lua-users home
lua-l archive

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


> ------------------------------
> Date: Tue, 30 Nov 2010 17:04:39 -0800
> From: Andrew Lentvorski <bsder@allcaps.org>
> Subject: Re: Floating point inaccuracies
> To: Lua mailing list <lua-l@lists.lua.org>
> Cc: jgiors@threeeyessoftware.com
> Message-ID: <4CF59F27.2070706@allcaps.org>
> Content-Type: text/plain; charset=UTF-8; format=flowed
> 
> On 11/30/10 9:10 AM, jgiors@threeeyessoftware.com wrote:
> > I don't understand your point here. My point was that when checking for
> > exactly zero, I would not expect my code to detect anything except zero
> > as zero
> 
> So, what about +0 and -0?
> 
> -a
> 

OK, you got me!  :)

I'm not sure how much I should get into this -- I've never worked on
code where I needed to differentiate the two, but it doesn't feel right
to ignore the query, either...

For me, there is just one mathematical zero, and its negation is equal
to itself. But IEEE 754 has both +0 and -0, and in all contexts I've
been exposed to, both are "exactly zero" to me (and as Luiz points out
in another reply, IEEE 754 requires they compare equal).

In a hypothetical context where I needed to distinguish -0 from +0, I
would think of them as representing -1/infinity and +1/infinity, with
neither representing mathematical zero (despite being written with a '0'
character).

John Giors
Independent Programmer
Three Eyes Software
jgiors@ThreeEyesSoftware.com
http://ThreeEyesSoftware.com