Comments on "Proposal for Extension of Java(TM) Floating Point Semantics, Revision 1"

Tim Lindholm Timothy.Lindholmaeng.sun.com
Wed Aug 19 10:04:30 PDT 1998


Hi Joe,

Responding to a little thing first: we understood this point and
initialize these variables with static initializers, not integer
literals.

-- Tim

> As a minor implementation note, the expressions setting these
> variables shouldn't be integer literals.  If the fields were assigned
> using integer literals, the values of the fields could be
> constant-propagated on the system that *compiled* a program instead of
> the system that ran the program (the fields would be constant
> expressions according to [JLS] section 15.27).
> 
> For example, let's say that in a particular VM these fields
> (faithfully) indicated that double extended would be used.  A double
> variable cannot overflow if 8 or fewer finite float values are
> multiplied together.  A doubled extended variable cannot overflow if
> fewer than 128 float variables are multiplied together.  Knowing that
> double precision (or greater) will be used, a programmer might want to
> block products of float array elements into groups that cannot
> overflow so that overflow can be prevented by scaling.  For example,
> consider the following code skeleton to compute the geometric mean:
> 
> static double geoMean(double A[])
> {
>   double product=1.0;	// product of elements of A
>   int count=0;		// number of times exponent is adjusted up or down
> 
> // for expository purposes, assuming length of A is a multiple of
> // Double.WIDEFP_MAX_EXPONENT/127; strip-mining code elided
> 
>   int i=0;
>   while(i < a.length)
>     {
>       // multiply in groups guaranteed not to overflow
>       for(j=0; j < Double.WIDEFP_MAX_EXPONENT/127; j++,i++)
>         product *= a[i];
> 
>       // check current magnitude of product
>       if(product near overflow)
>         {
>           count++;
>           product *= 2^(-known_adjustment_factor);
>         }
>       else if(product near underflow)
>         {
>           count--;
>           product *= 2^known_adjustment_factor;
>         }
>     }
> 
>   // calculate geometric mean taking exponent adjustment into account
>   return ...;
> }
> 
> If this code were compiled on a machine supporting double extended but
> run on a machine supporting only double, the code would not have the
> intended affect of preventing all overflows since
> Double.WIDEFP_MAX_EXPONENT would be taken from the platform compiling
> the program.




More information about the Numeric-interest mailing list