lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



-----Original Message----- 
> From: "Sean Conner" <sean@conman.org> 
> To: "Lua mailing list" <lua-l@lists.lua.org> 
> Date: 07-03-2014 21:09 
> Subject: Re: Hardware trap while casting large doubles to int on PowerPC P2020 
> 
> It was thus said that the Great Thomas Jericke once stated:
> > On 03/07/2014 09:50 AM, Philipp Janda wrote:
> > >
> > >3.2.1.3 Floating and integral
> > >
> > >   When a value of floating type is converted to integral type, the 
> > >fractional part is discarded.  If the value of the integral part 
> > >cannot be represented by the integral type, the behavior is undefined. 
> > >/23/
> > >
> > >Footnote /23/ is:
> > >23. The remaindering operation done when a value of integral type is 
> > >converted to unsigned type need not be done when a value of floating 
> > >type is converted to unsigned type.  Thus the range of portable values 
> > >is [0, U type _MAX +1).
> > >
> > >Looks clear-cut to me ...
> > >
> > >
> > >Philipp
> > Oh well, then I looked at the wrong place. So the behavior is undefined, 
> > this means the P2020 is doing nothing that isn't allowed here, and maybe 
> > the code in the vanilla Lua source should be changed accordingly.
> > 
> > We were surprised that only we encountered the problem. I haven't found 
> > anything on the list about it.
> 
>   I think I hit this problem a few days ago and mentioned it on the list
> [1].  I did figure out that on a 64-bit system, not all 64-bit values will
> survive intact through a double.  I wrote about it a bit more here:
> 
>      http://boston.conman.org/2014/03/05.1
> 
>   -spc (Is the P2020 a 64-bit CPU?)
> 
> [1]     Only one person responded, and that was a mistake.
> 
> 
>
No that's not the same problem. Your problem is to store a 64bit integer in a 64bit float (AKA double), which does only works up to 2^53 without loosing percition. My problem is the convertion of a doubke into a 32 bit signed integer. This will fail for any double storing a value larger than 2^31. The type in the code is int which is 32 bit on either 32 or 64 bit systems.
--
Thomas