Java numerics issue
Douglas Priest
Douglas.PriestaEng.Sun.COM
Sat Feb 1 11:19:50 PST 1997
Coonen laments the fact that Java as it is defined seems not to be a
good environment for serious scientific computing. While I imagine
some people might find it reassuring to be able to buy an airline
ticket over the Web and then click on a link that downloads and runs
a structural simulation of the aircraft they'll be flying on, there
is another application that is important in the context of Java and
the Web that would provide reassurance to more of us, namely encryp-
tion.
Many encryption techniques rely on multi-word integer arithmetic,
and on many modern computers, the easiest and most efficient way to
do multi-word integer arithmetic is to use double precision floating
point. The key ingredient that makes such techniques work (and makes
related techniques for multiple precision floating point work, too)
is the ability to round a known number of bits off of the end of a
floating point number; for example, if x is a double precision number
no larger than 2^51 in absolute value, then computing
(x + 6755399441055744.0) - 6755399441055744.0
gives x rounded to the nearest integer in the direction of the pre-
vailing rounding mode provided each operation is rounded to double
precision.
The magic number 6755399441055744 is related to the precision used,
here 53 bits. Experts like Coonen know that the same thing can be
done in any precision and that there are ways to compute the appro-
priate magic number at run time to match the expression evaluation
format used, but many programmers who think they know what the IEEE
standard has to say about precision might not know of them. They
might not realize that in some languages, on some machines, "double"
sometimes means double precision and sometimes means double extended
and which is which when can hinge on what most of us would regard as
accidents of notation. The choice that the designers of Java made
sacrifices efficiency but may well save a lot of programmers from
the embarrassment (or worse) of not knowing that
y = (x + 6755399441055744.0) - 6755399441055744.0
and
y = x + 6755399441055744.0
y = y - 6755399441055744.0
don't mean the same thing.
Douglas M. Priest
SunSoft Floating Point Group
Sun Microsystems, Inc.
(but only speaking for myself)
More information about the Numeric-interest
mailing list