Just a question that I'm kind of confused about
So I was messing around with float('inf') and kind of wondering what it is used for.
Also I noticed that if I add -inf + inf i get nan is that the same as Zero or not.
I'm confused about what the uses of these two values are.
Also when I do nan - inf I don't get -inf I get nan I'm sure it's all pretty simple but I stumbled upon them and didn't know what they do.
Floating point. In floating-point calculations, NaN is not the same as infinity, although both are typically handled as special cases in floating-point representations of real numbers as well as in floating-point operations.
Inf means infinity, and is the result of dividing a positive number by zero -- e.g., 1/0 → Inf. or computing a number larger than 1.796E308 (the largest number that your computer can represent in 64 bits) -- e.g. 1E307 * 100 → Inf.
In comparison operations, positive infinity is larger than all values except itself and NaN, and negative infinity is smaller than all values except itself and NaN. NaN is unordered: it is not equal to, greater than, or less than anything, including itself.
inf constant returns a floating-point positive infinity. For negative infinity, use -math. inf .
nan means "not a number", a float value that you get if you perform a calculation whose result can't be expressed as a number. Any calculations you perform with NaN will also result in NaN.
inf means infinity.
For example:
>>> 2*float("inf") inf >>> -2*float("inf") -inf >>> float("inf")-float("inf") nan
inf is infinity - a value that is greater than any other value. -inf is therefore smaller than any other value.
nan stands for Not A Number, and this is not equal to 0.
Although positive and negative infinity can be said to be symmetric about 0, the same can be said for any value n, meaning that the result of adding the two yields nan. This idea is discussed in this math.se question.
Because nan is (literally) not a number, you can't do arithmetic with it, so the result of the second operation is also not a number (nan)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With