Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36573

Re: double bits

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: double bits
Date 2017-05-02 07:46 -0400
Organization Aioe.org NNTP Server
Message-ID <oe9rif$m2v$1@gioia.aioe.org> (permalink)
References <bits-20170502040246@ram.dialup.fu-berlin.de>

Show all headers | View raw


On 5/1/2017 11:08 PM, Stefan Ram wrote:
>   Today, I was trying to actually see the double bits.
>
> Main.java
> public final class Main
> {
>
>   private static void print( final double x )
>   { java.lang.System.out.printf
>     ( "%9.0f %064d%n", x,
>       new java.math.BigInteger
>       ( java.lang.Long.toBinaryString
>         ( java.lang.Double.doubleToLongBits
>           ( x )))); }
>
>   public static void main( final java.lang.String[] args )
>   { print(  1.0 );
>     print(  2.0 );

> transcript
>
>         1 0011111111110000000000000000000000000000000000000000000000000000
>         2 0100000000000000000000000000000000000000000000000000000000000000

>   Well, I am left somewhat confused now. I would not be able
>   to predict one of those bit patterns from the number. For
>   example, why »1« has so many 1 bits, but then »2« has one
>   1 bit only.

You can look up the IEEE floating point format and see what bits means what.

But basically floating points are:

(2 pow (exponentbits - exponentbase)) * sum { mantissabitsinclhiddenbit 
* 1/2 pow i }

And without checking the IEEE format then I am willing to guess that
the exponent bits are:

001111111111
010000000000

which is N and N+1.

And that:

1 = (2 pow N ) * Z
2 = (2 pow (N + 1)) * Z

seems very plausible to me.

Arne


Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread


Thread

Re: double bits Arne Vajhøj <arne@vajhoej.dk> - 2017-05-02 07:46 -0400

csiph-web