Official Java Bit Patterns for Nan and Infinities

Apr 25, 2010

In case s.o. needs to encode NaN and Infinities, building an API for a different language:

Java has official bit values for them, which are not part of the IEEE 754 standard. There are many other bit patterns that are also NaNs.

This can be useful because NaN and Infinities can be send to a Stored Procedure, though not stored in the database.

POSITIVE_INFINITY: 0x7f800000

NEGATIVE_INFINITY: 0xff800000

NaN: 0x7fc00000

From: http://www.docjar.com/html/api/java/lang/Float.java.html

50 public final class Float extends Number implements Comparable<Float> {

51 /**

52 * A constant holding the positive infinity of type

53 * {@code float}. It is equal to the value returned by

54 * {@code Float.intBitsToFloat(0x7f800000)}.

55 */

56 public static final float POSITIVE_INFINITY = 1.0f / 0.0f;

57

58 /**

59 * A constant holding the negative infinity of type

60 * {@code float}. It is equal to the value returned by

61 * {@code Float.intBitsToFloat(0xff800000)}.

62 */

63 public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;

64

65 /**

66 * A constant holding a Not-a-Number (NaN) value of type

67 * {@code float}. It is equivalent to the value returned by

68 * {@code Float.intBitsToFloat(0x7fc00000)}.

69 */

70 public static final float NaN = 0.0f / 0.0f;

Java has official bit values for them, which are not part of the IEEE 754 standard. There are many other bit patterns that are also NaNs.

This can be useful because NaN and Infinities can be send to a Stored Procedure, though not stored in the database.

POSITIVE_INFINITY: 0x7f800000

NEGATIVE_INFINITY: 0xff800000

NaN: 0x7fc00000

From: http://www.docjar.com/html/api/java/lang/Float.java.html

**Home » Open-JDK-6.b17-src » java » lang » source**

48 * @since JDK1.0 49 */50 public final class Float extends Number implements Comparable<Float> {

51 /**

52 * A constant holding the positive infinity of type

53 * {@code float}. It is equal to the value returned by

54 * {@code Float.intBitsToFloat(0x7f800000)}.

55 */

56 public static final float POSITIVE_INFINITY = 1.0f / 0.0f;

57

58 /**

59 * A constant holding the negative infinity of type

60 * {@code float}. It is equal to the value returned by

61 * {@code Float.intBitsToFloat(0xff800000)}.

62 */

63 public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;

64

65 /**

66 * A constant holding a Not-a-Number (NaN) value of type

67 * {@code float}. It is equivalent to the value returned by

68 * {@code Float.intBitsToFloat(0x7fc00000)}.

69 */

70 public static final float NaN = 0.0f / 0.0f;