Java Reference
In-Depth Information
The static method
IEEEremainder
calculates remainder as defined by the
Point Arithmetic
" on page
202
, obeys the rule
(x/y)*y + x%y == x
This preserves one kind of symmetry: Symmetry around zero. That is,
if
x%y
is
z
, then changing the sign of either
x
or
y
will change only the
sign of
z
, never its absolute value. For example,
7%2.5
is
2.0
, and
-7%2.5
is
-2.0
. The
IEEE
standard defines remainder for
x
and
y
differently, pre-
serving symmetry of spacing along the number linethe result of
IEEEre-
mainder(-7,2.5)
is
0.5
. The
IEEE
remainder mechanism keeps resulting
values
y
units apart, as contrasted with the remainder operator's sym-
metry around zero. The method is provided because both kinds of re-
mainder are useful.
The static method
random
generates a pseudorandom number
r
in the
range 0.0
r
< 1.0. More control over pseudorandom number genera-
The algorithms used in
StrictMath
are those defined in the
FDLIBM
"C"
math library; if you need a complete understanding of these issues, con-
sult
The Java
™
Language Specification
,
Third Edition.
See "
java.math Mathematics
"
on page
722
for brief coverage of some
other math-related classes.
Exercise 22.15
: Write a calculator that has all
Math
or
StrictMath
func-
tions, as well as (at least) the basic operators
+
,
-
,
*
,
/
, and
%
. (The
simplest form is probably a reverse Polish stack calculator because op-
erator precedence is not an issue.)
Computers are uselessthey can only give you answers.
Pablo Picasso