3 ms·
In case of floating points, since they are an approximation, zero is not zero. Zero is a quantity approaching to zero. In fact dividing by zero with floats is e
by alerighi 3y ago
In case of floating points, since they are an approximation, zero is not zero. Zero is a quantity approaching to zero. In fact dividing by zero with floats is entirely possible! (it leads to infinite, positive or negative depending on the sign).
For example, the quantity (try it in Python):
0.1 ** 100 / 1000**100 evaluates to 0.0
while the quantity
0.1 ** 100 / (-1000**100) evaluates to -0.0
It's clear that neither the two quantities are 0 (no division can produce a result that is exactly zero!) but they approach the zero. But one quantity is slightly less than zero, the other slightly more than zero.
Of course for integers -0 doesn't make sense (that is the reason why we invented 2 complement, to not have 2 "zeros")
- ghayes 3y ago> no division can produce a result that is exactly zero Except 0 / n
- phoe-krk 3y agoOr -0.0 / n, for what it's worth, at which point these zeroes will not be equal to one another.
- recursive 3y agoOr 1e-100 / 1e300
- Dylan16807 3y agoPlease refer back to "It's clear that neither the two quantities are 0 (no division can produce a result that is exactly zero!) but they approach the zero." because you just gave an example of how that rule is correct, not an exception.
- alerighi 3y agoOk, I should have specified unless the numerator is not exactly zero!
- parasti 3y agoThat sounds wrong to me. In IEEE floating point, 0.0 is not an approximation of zero, it is zero exactly. The binary value is literally all zero bits. Negative zero appears simply from the IEEE floating point format reserving a bit for the sign.
- 2h 3y ago> Zero is a quantity approaching to zero no, its not. zero is zero, its nothing. "a quantity approaching to zero" is "a quantity approaching to zero". its easy to remember because zero is not a quantity, its a lack of quantity, by definition. these are two distinct concepts, which some people mistake as the same item.
- alerighi 3y agoNot with floating point numbers.