Results 1 to 6 of 6

Thread: Official Java Bit Patterns for Nan and Infinities

  1. #1
    Senior Member
    Join Date
    Feb 2010
    Posts
    106

    Official Java Bit Patterns for Nan and Infinities

    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/...loat.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;
    Last edited by mneaton; 11-09-2012 at 02:38 PM.

  2. #2
    Super Moderator
    Join Date
    Feb 2010
    Posts
    133

    Good news!

    Hi Henning,


    I have done some code snooping in Java's ByteBuffer class and it turns out that it takes care of the conversion from Java floats to IEEE 754 floats. If you try and send a Java float to us on the wire it might get mangled when ByteBuffer attempts to decode it as an IEEE 754 float. We still need better test coverage of floating point expressions involving Nan and +-Inf, but there is no reason to think they wouldn't behave as expected.


    -Ariel

  3. #3
    Senior Member
    Join Date
    Feb 2010
    Posts
    106

    Ieee 754

    Are there any other differences between Java and IEEE 754 except for the NaN types and their flags?


    Not in the representation of 'real' float numbers I take it?


    Thanks,
    Henning

  4. #4
    Senior Member
    Join Date
    Feb 2010
    Posts
    106

    Shift to "Wire Protocol Forum"

    This thread could be shifted to the new Wire Protocol Forum I think.

  5. #5
    Super Moderator
    Join Date
    Feb 2010
    Posts
    133

    Here is the JVM spec for

    Quote Originally Posted by henning View Post
    Are there any other differences between Java and IEEE 754 except for the NaN types and their flags?


    Not in the representation of 'real' float numbers I take it?


    Thanks,
    Henning
    Here is the JVM spec for floats and doubles
    http://java.sun.com/docs/books/jvms/...doc.html#33377
    The elements of the float value set are exactly the values that can be represented using the single floating-point format defined in the IEEE 754 standard, except that there is only one NaN value (IEEE 754 specifies 224 - 2 distinct NaN values). The elements of the double value set are exactly the values that can be represented using the double floating-point format defined in the IEEE 754 standard, except that there is only one NaN value (IEEE 754 specifies 253 - 2 distinct NaN values). Note, however, that the elements of the float-extended-exponent and double-extended-exponent value sets defined here do not correspond to the values that can be represented using IEEE 754 single extended and double extended formats, respectively.
    VoltDB expects true IEE 754 floats and doubles on the wire and not the Java version. This is because Java already correctly handles the conversion from IEEE 754 to Java floats/doubles in ByteBuffer.

  6. #6
    New Member
    Join Date
    Oct 2013
    Posts
    1
    This could be shifted to the new Wire Protocol Forum I think are there any other differences between Java and IEEE 754 except for the NaN types and their flags?
    pass4sure Pass4sure.com
    mad max jacket mad max jacket
    mclaren jacket mclaren jacket
    plus size leather coats plus size leather coats
    suede coats for women suede coats for women

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •