commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Diggory <mdigg...@gmail.com>
Subject Re: [math][patch] Mantissa + Characteristic methods for MathUtils
Date Tue, 26 Sep 2006 03:53:22 GMT
Best I've found on the net uses some bit arithmetic.

long bits = Double.doubleToLongBits(5894.349580349);

boolean negative = (bits & 0x8000000000000000L) != 0;
long exponent = bits & 0x7ff0000000000000L >> 52;
long mantissa = bits & 0x000fffffffffffffL;

Cheers,
Mark

On Sep 25, 2006, at 11:39 PM, Kevin Jackson wrote:

> Hi,
>
> I've just been working on some fairly simple code (in any other
> language), and realised that I needed some of the most basic methods
> available and suprise Java doesn't have them in the base libraries.
>
> These are very tiny, but I can't believe that no-one else has ever
> needed to get the mantissa of a float/double before me - if these
> exist in some other form please forgive this intrusion.
>
> Adding these would greatly simplify my current code, or if anyone
> knows how to get the mantissa without resorting to String manipulation
> - even using x * 10^mantissaLength % 10^mantissaLength /
> 10^mantissaLength is fairly nasty in client code (and you get rounding
> errors that way).
>
> Thanks,
> Kev
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message