>> 1 / -0.0
=> -Infinity
Although you have to put the 0.0, otherwise it treats it as an integer and makes it 0.How does your programming language handle “minus zero” (-0.0)?
61–70 of 219 posts
Re: How does your programming language handle “minus zero” (-0.0)?
#62Ruby seems to handle this correctly: >> 1 / -0.0 => -Infinity Although you have to put the 0.0, otherwise it treats it as an integer and makes it 0.
Re: How does your programming language handle “minus zero” (-0.0)?
#63There are still (a few) computers in the world (Sperry Univac legacy support) using one's complement arithmetic, hence having a positive and negative zero in the architecture. https://en.wikipedia.org/wiki/Ones%27_complement
Well all computers supporting IEEE 754 floating point numbers have a positive and a negative 0. Thats quite a few. I prefer to store all my most important data in the sign bit of floats set to zero.
How is the result of:
a = 0;
different from:
a = -0;
:-)
Re: How does your programming language handle “minus zero” (-0.0)?
#64I feel like floating point is a completely separate branch of programming that a lot of coders never use. When they do it's often a mistake, like for currency. Yet floating point is very useful for scientific calculations and simulations, which is what computers were all about for the first couple of decades. I have a suspicion that on a fundamental level, floating point isn't actually good for games or machine learn…
Re: How does your programming language handle “minus zero” (-0.0)?
#65I feel like floating point is a completely separate branch of programming that a lot of coders never use. When they do it's often a mistake, like for currency. Yet floating point is very useful for scientific calculations and simulations, which is what computers were all about for the first couple of decades. I have a suspicion that on a fundamental level, floating point isn't actually good for games or machine learn…
Re: How does your programming language handle “minus zero” (-0.0)?
#66I feel like floating point is a completely separate branch of programming that a lot of coders never use. When they do it's often a mistake, like for currency. Yet floating point is very useful for scientific calculations and simulations, which is what computers were all about for the first couple of decades. I have a suspicion that on a fundamental level, floating point isn't actually good for games or machine learn…
In some game engines, Fixed Point Arithmetic is used instead of Floating Point, because it's faster, and the approximation is generally good enough for a game.
Re: How does your programming language handle “minus zero” (-0.0)?
#67Earlier quoted context omitted.
Isn't that true for all correct implementations of negative zero? It's still a neutral for addition
Not quite neutral. You return -0.0 only when needed. >>> 0.0+0.0 0.0 >>> 0.0+(-0.0) 0.0 >>> (-0.0)+0.0 0.0 >>> (-0.0)+(-0.0) -0.0
Re: How does your programming language handle “minus zero” (-0.0)?
#68Re: How does your programming language handle “minus zero” (-0.0)?
#69Does -0.0 == +0.0 ?
Its bitwise representation is different, but when compared as floats they are equal.
Re: How does your programming language handle “minus zero” (-0.0)?
#70Earlier quoted context omitted.
In some game engines, Fixed Point Arithmetic is used instead of Floating Point, because it's faster, and the approximation is generally good enough for a game.
I dont think this is true. Integer math is used in some game engines because they need to be deterministic, between networked computers (and different CPUs rounds floating point numbers differently). I have written an engine like that, and i know that Starcraft 2 is all integer for the same reason. No one does it because its faster or easier. Its a pain.
And computing integers IS faster than computing floats, at least on a CPU.