Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Understanding Math.getExponent(Double)

Double dble = new Double("2.2737367544323201e-13");
int exponent = Math.getExponent(dble);

I have the above code and exponent has value of '-43'. I'm not sure how the exponent is '-43', when the passed double value contains '-13'. Could someone shed some light into this API?

like image 861
Paul-E Avatar asked Jan 07 '21 08:01

Paul-E


1 Answers

Math.getExponent() returns the exponent of the binary representation of the number. In your example -13 is the exponent of the decimal representation, and -43 the exponent of the binary representation.

For example,

System.out.println (Math.getExponent (1024));

prints

10

since

1024 = 2 ^ 10

so the exponent is 10.

System.out.println (Math.getExponent (1.0/8192));

will print

-13

since

1.0/8192 = 2 ^ (-13)
like image 71
Eran Avatar answered Sep 28 '22 06:09

Eran