1000 Java Tips ebook
Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!.
JavaFAQ Home » Mathematics
Floating-point numbers are like real numbers in mathematics, for
example, 3.14159, -0.000001. Java has two kinds of floating-point numbers:
double, both stored in IEEE-754 format. The
default type when you write a floating-point literal is
Java floating-point types
||in decimal digits
||+/- 3.4 * 1038
||+/- 1.8 * 10308
Because there are only a limited number of bits in each floating-point type,
some numbers are inexact, just as the decimal system can not represent some
numbers exactly, for example 1/3. The most troublesome of these is that 1/10 can
not be represented exactly in binary.
There are two types of notation for floating-point numbers. Any of these
numbers can be followed by "F" (or "f") to make it a
of the default
- Standard (American) notation which is a series of digits for the
integer part followed by a decimal point followed by a series of digits for
the fraction part. Eg, 3.14159 is a
double. A sign (+ or -) may
precede the number.
- Scientific notation which is a standard floating-point literal
followed by the letter "E" (or "e") followed by an optionally signed
exponent of 10 which is used as a multiplier (ie, how to shift the decimal
point). Generally scientific notation is used only for very large or small
Infinity and NaN
No exceptions are generated by floating-point operations. Instead of an
interruption in execution, the result of an operation may be positive infinity,
negative infinity, or NaN (not a number). Division by zero or overflow produce
infinity. Subtracting two infinities produces a NaN. Use methods in the wrapper
classes (Float or Double) to test for these values.
Printer Friendly Page
Send to a Friend
Search here again if you need more info!