How do I check if a zero is positive or negative?

前端 未结 7 1318
孤街浪徒
孤街浪徒 2020-12-01 06:50

Is it possible to check if a float is a positive zero (0.0) or a negative zero (-0.0)?

I\'ve converted the float to a String a

7条回答
  •  -上瘾入骨i
    2020-12-01 07:49

    Definitly not the best aproach. Checkout the function

    Float.floatToRawIntBits(f);
    

    Doku:

    /**
     * Returns a representation of the specified floating-point value
     * according to the IEEE 754 floating-point "single format" bit
     * layout, preserving Not-a-Number (NaN) values.
     *
     * 

    Bit 31 (the bit that is selected by the mask * {@code 0x80000000}) represents the sign of the floating-point * number. ... public static native int floatToRawIntBits(float value);

提交回复
热议问题