Meaning of Double.doubleToLongBits(x)

前端 未结 3 530
傲寒
傲寒 2020-12-18 22:02

I am writing a class Vec2D, representing a 2 dimensional vector. I store x and y in doubles.

When asked to genera

3条回答
  •  孤城傲影
    2020-12-18 23:07

    A quick glance at the online javadoc yields this:

    Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout.

    ...

    In all cases, the result is a long integer that, when given to the longBitsToDouble(long) method, will produce a floating-point value the same as the argument to doubleToLongBits (except all NaN values are collapsed to a single "canonical" NaN value).

    So it's probably a way of standardizing the double representations of x and y, as NaN can have multiple double representations

提交回复
热议问题