hi every one ....

thanks for comming to this thread ...

Dose any one know how to separate mantissa and exponent of a double and store them in two integers? :?:

I'm not sure if this is exactly what you're talking about, but here it is...

public class Mantissa
{
	public static void main(String[] args)
	{
		double d = 2.88;
		int a = (int) d; // here's the first part
		System.out.println(a);
		double f = d - (double) a;
		f = Math.round(f * 100);
		int c = (int) f;
		System.out.println(c);
	}
}

I'm not sure if this is exactly what you're talking about, but here it is...

public class Mantissa
{
	public static void main(String[] args)
	{
		double d = 2.88;
		int a = (int) d; // here's the first part
		System.out.println(a);
		double f = d - (double) a;
		f = Math.round(f * 100);
		int c = (int) f;
		System.out.println(c);
	}
}

yes, but is there any other way? or is there any chance of data lose in this way?

yes, but is there any other way? or is there any chance of data lose in this way?

I thought that was a very good solution myself, but if you want another way, you could throw it into a string and parse it.

hi every one ....

thanks for comming to this thread ...

Dose any one know how to separate mantissa and exponent of a double and store them in two integers? :?:

I'd go with something like

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

Note that the mantissa is actually 52 bits in a double, and shouldn't ever be put in an integer without making sure it fits first. The exponent is small enough.

Hope that helps.

This article has been dead for over six months. Start a new discussion instead.