Java includes the
primitive types float
and double
which hold floating point numbers.
When written with characters, floating point numbers include a decimal point
followed by a decimal fraction.
For example, 3.14159
and -0.718802
.
But (of course),
inside the computer floating point numbers are represented with bit patterns,
as is all data.
All of the familiar mathematical functions such as
sine, log, and square root
are available to your program in the Java Math
class.
These functions usually use arguments of type double
,
and usually return values of type double
.
Note: the character that is used to separate the whole part of the number from the fractional part depends on what country you are in. In the U.S. (and other countries with a historical tie to England) a dot is used. In many other countries (most of Europe and South America) a comma is used. These notes use a dot.
Which uses more bits: a Java float
or a Java double
?