Browse Prior Art Database

Optimizing Java IEEE 754 floating-point arithmetic functions.

IP.com Disclosure Number: IPCOM000015161D
Original Publication Date: 2001-Nov-03
Included in the Prior Art Database: 2003-Jun-20
Document File: 2 page(s) / 54K

Publishing Venue

IBM

Abstract

A program is disclosed for efficiently calculating IEEE 754[1] floating-point maximum and minimum functions and the isFinite and isInfinite functions. The Java* programming language library defines the methods package java.lang; public class Math public static double max(double a, double b);

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 100% of the total text.

Page 1 of 2

Optimizing Java IEEE 754 floating-point arithmetic functions.

A program is disclosed for efficiently calculating IEEE 754[1] floating-point maximum and minimum functions and the isFinite and isInfinite functions.

The Java* programming language library defines the methods package java.lang;
public class Math {
public static double max(double a, double b);
public static double max(double a, double b);
public static float max(float a, float b);
public static float max(float a, float b);

Page 2 of 2

The max method can then be implemented as follows, and the min method similarly: public static double max(double a, double b) {
if (a > b)) return a; // a and b are not NaN
if (a < b)) return b; // a and b are not NaN
if (a == 0.0) returna+b;//bis +-0.0 or NaN
if (a != a) return a; // a is NaN
return b; // a equals b or b is NaN
}

Another optimization is for the isFinite() function. It is useful to tell whether a value is a finite value (i.e. not Infinity or NaN). Subtracting a number from itself gives either +0.0 or NaN.

Number a + a a - a NaN NaN NaN +/-Infinity +/-Infinity NaN finite number finite number or +/-Infinity +0.0 +0.0 +0.0 +0.0 -0.0 -0.0 +0.0

So simple test for isFinite(a) is: public static boolean isFinite(double a) {
returna-a== 0.0;

2