Quantcast
Channel: Reza's Weblog
Viewing all articles
Browse latest Browse all 50

Java's Mathematical Infinity

$
0
0

We have the mathematical representation of infinity in double or float:


double i = Double.POSITIVE_INFINITY;

and it behaves like mathematical infinity so that i == i+1; is correct!

In Java adding a small floating-point value to a large one will not change the large value.

This distribution of floating-point values is a consequence of their representation with a fixed number of significant bits. Adding 1 to a floating-point value that is sufficiently large will not change the value, because it doesn't "bridge the gap" to its successor.

Math.ulp(argument) method returns the smallest value which, when added to the argument, would be recognized as larger than the argument!
Remember that the binary floating-point arithmetic is only an approximation to real arithmetic.


Viewing all articles
Browse latest Browse all 50

Trending Articles