On Fri, Dec 19 2014, Hans W Borchers <[email protected]> wrote: > The expression -0.0 means the floating point number that in memory has the > same > bit representation as 0.0, but the sign bit set to 1. One can see this > applying > the 'bits' function to 0.0 and -0.0. > > I seem to remember that the IEEE floating point convention says that for > `sqrt(-0.0)` the sign bit has to be reset, so that > > julia> sqrt(-0.0) > -0.0 > > would be wrong while MATLAB, R,... returning 0.0 are correct.
I don't think so. Section 6.3 of the IEEE Std 754TM-2008 says that "Except that squareRoot(−0) shall be −0, every numeric squareRoot result shall have a positive sign. Furthermore, you can't rely on R to display the sign bit, eg > 1/(-Inf) [1] 0 Best, Tamas > The expression -0.0 means the floating point number that in memory has the > same > bit representation as 0.0, but the sign bit set to 1. One can see this > applying > the 'bits' function to 0.0 and -0.0. > > I seem to remember that the IEEE floating point convention says that for > `sqrt(-0.0)` the sign bit has to be reset, so that > > julia> sqrt(-0.0) > -0.0 > > would be wrong while MATLAB, R,... returning 0.0 are correct. > > For `1/-Inf` the sign bit is not reset because this expression should be > the > limit of 1/-x for very large numbers x, i.e. approaching 0 from left. > > > On Friday, December 19, 2014 12:13:57 PM UTC+1, Tamas Papp wrote: >> >> Hmmm, did you read the whole blog post, including the update at the end? >> Julia does handle signed zeroes correctly when working with floats. >> >> As to what signed zeros "mean" -- they have some applications, including >> indicating the direction of underflow. Probably you don't need to worry >> about them much since 0.0 == -0.0 (unless you specifically want to use >> them). >> >> I usually think about -0.0 as equivalent to 0.0 except for +, -, *, and >> /, especially when Inf is involved. Thinking about it as some limit is >> not very intuitive for IEEE floats, eg >> >> julia> log(-0.0) >> -Inf >> >> julia> sqrt(-0.0) >> -0.0 >> >> all of which are correct IEEE. >> >> Best, >> >> Tamas >> >> >> On Fri, Dec 19 2014, cdm <[email protected] <javascript:>> wrote: >> >> > i stumbled across a post and got to wondering what Julians thought of it >> ... >> > >> > http://www.walkingrandomly.com/?p=5152 >> > >> > >> > the author presents the case that Python is not IEEE compliant, but >> > MATLAB is and Julia is close: >> > >> > "From the wikipedia page on Division by Zero >> > <http://en.wikipedia.org/wiki/Division_by_zero>: *“The IEEE 754 >> > standard specifies that every floating point arithmetic operation, >> > including division by zero, has a well-defined result”.* >> > >> > >> > the author reports that in Julia >> > >> > julia> 1/(-0) >> > Inf >> > >> > >> > but MATLAB "correctly" returns -Inf ... >> > >> > >> > i am not sure that signed zero (-0) >> > means anything to me ... >> > >> > should it? >> > >> > many thanks, >> > >> > cdm >>
