lua-users home
lua-l archive

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


> ------------------------------
> Date: Wed, 1 Dec 2010 10:41:13 +0000
> From: Tony Finch <dot@dotat.at>
> Subject: RE: lua-l Digest, Vol 5, Issue 1
> To: Lua mailing list <lua-l@lists.lua.org>
> Message-ID:
> 	<alpine.LSU.2.00.1012011031480.14239@hermes-2.csi.cam.ac.uk>
> Content-Type: TEXT/PLAIN; charset=US-ASCII
> 
> On Wed, 1 Dec 2010, jgiors@threeeyessoftware.com wrote:
> >
> > 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).
> 
> The reason they are distinguished is to do with branch cuts, which are
> especially important in complex arithmetic. See for example atan2() which
> as well aas being useful in real geometry gives you the argument (polar
> angle) of a complex number. For atan2(y,-1) the result is +pi if y == +0
> and -pi if y == -0.
> 
> Tony.
> -- 
> f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/

I did not mean to imply that I do not understand there is a purpose for
+0 and -0. I have not run into contexts where I've needed to distinguish
them, but I would probably recognize if/when it is useful to do so.

In the case of atan2(), I've only used it for graphics/games
applications, where distinguishing +pi from -pi is not useful. Both mean
180 degree rotation, at which point the choice of positive or negative
rotation is arbitrary.

Returning +/- pi from atan2(y,-1) when y is +/- 0 seems like what I
mentioned in the preceding post -- treating +/- 0 as equivalent to +/-
1/infinity instead of as mathematical zero.

Anyway, I'm not certain we should continue discussing +/-0 on this
thread, which has strayed from the original suggestion that a small
epsilon, e.g. 1e-17, be applied to Lua numeric comparisons, especially
since the original poster has conceded the point (and there doesn't seem
to be any new advocate of the idea).

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