Java numerics issue

Arthur van Hoff avhamarimba.com
Thu Jan 30 15:28:25 PST 1997


Hi Jerome,

I am not a math expert but I was present when some of the decisions
about Java's math support were made. We spend a fair amount of time 
discussing these issues before we decided on the current specification.
Guy Steele acted as our resident Math expert at the time.

Anyway, it was decided that for the sake of portability all platforms
would have to implement the exact same semantics for all language
features including math operations. We considered portability to
be more important than performance in some cases. Unfortunately this
means that on some platforms this will make it impossible to generate 
optimal native code for math operations. 

With this strict requirement for portability it should be easy
to write math algorithms that produce the same results on all 
platforms. This would be very hard to do in C or C++ which were
designed for performance not portability. Anyway, as a resuls it is 
unlikely that Java will be the best choice for implementing very
performance critical math routines such as sqrt(). It is likely that 
these will remain hand-coded native routines for a while.

Another issue to consider is the support for interpreted and compiled
code in the same environment. It would be wrong if JIT compiled code would
produce different or more accurate results than interpreted code
which rounds intermediate results differently. This could cause very
unpredictable behaviour within one virtual machine. Forcing the interpreter
to mimick the hardware's capabilities would be very expensive and very slow.

A related problem that was never resolved, is the standarization of the
Math library which is part of the Java standard. I think we decided that
Sun would eventually provide a reference implementation for these in Java.
I don't think there is a satisfactory answer for that one. 

Was it the right decision to force the JIT compiled Java code to conform
to a strict standard? I think so, but then again, I am not a math expert...
	
Have fun,

	Arthur van Hoff

Marímba Inc., 445 Sherman Avenue, Palo Alto CA 94306
415-328 JAVA (main), 415-328 5283 (direct), 415-328 5295 (fax)
http://www.marimba.com/, mailto:avhamarimba.com



More information about the Numeric-interest mailing list