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


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

Re: double bits

Started byArne Vajhøj <arne@vajhoej.dk>
First post2017-05-02 07:46 -0400
Last post2017-05-02 07:46 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#36573 — Re: double bits

FromArne Vajhøj <arne@vajhoej.dk>
Date2017-05-02 07:46 -0400
SubjectRe: double bits
Message-ID<oe9rif$m2v$1@gioia.aioe.org>
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


[toc] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web