Click to See Complete Forum and Search --> : datatype to hold 10E308


francoz
May 9th, 2003, 12:04 AM
Can anyone of you please tell me a data type that can hold value like 10E308.

I gave

long double db = 10E308;

But it'll give "constant too big" error since, long double is mapped to double in NT and 95.

Any alternative?

Bengi
May 9th, 2003, 06:51 AM
DWORD myNum=0x10E308;

NigelQ
May 10th, 2003, 07:14 PM
I will assume that francoz wanted the exponent and mantissa represented to be converted to a double precision number rather than a simple hexadecimal conversion.

The format you have is correct, but the number is simply too big.

Double precision numbers must be in the range:

2.2250738585072014 E – 308 to 1.7976931348623158 E + 308

Your number was just outside the upper bounds of this.

Other valid examples:

10.3E+44
10e44
12.34e-56

See DBL_MAX, DBL_MIN and DBL_MAX_10_EXP, DBL_MIN_10_EXP for limits of doubles.

Hope this helps,

- Nigel

francoz
May 11th, 2003, 09:10 AM
Actually my client has changed the requirement that,

by

10E308 they meant pow(10,308) and not 10*pow(10,308).
So the problem is fixed.

But if it was the othercase anyof you think it was possible?
I looked into DBL_MAX_10_EXP related topics. but nowhere I could see it describes a method to represent value exceeding the max. range which comes less than
10* pow(10,308).

NigelQ
May 11th, 2003, 12:39 PM
Sure it's possible, but you need to implement it yourself (maybe a little wrapper class)

Essentially you perform calculations on the mansissa (to the left of the e) and exponent (to the right of the e - or ten to the power of this) portions of the numbers yourself.

For example, you could implement your own numbering class where the exponent values are stored in a long member variable and the mantissa values are stored in their own float or double member variable.

You can then perform simple math on each.

-- I'm going from memory here, so don't shoot me...:p

if you want to add 1.5e5 to 2.3e6, you take the smallest exponent number and use that as your common denominator.

You must change all numbers so that they have this common exponent value before you can perform simple math, so you need to multiply mantissa values by (10 ^ (the difference between their exponent and the common denominator)) to make all exponent values be the same.

The only other number we have is 2.3e6, so we need to perform:

2.3 * (10 ^ (6-5)) to make it have an exponent value of 5

Therefore the above becomes:

1.5e5 + 23e5

[ note both exponents are now 5 ]

Once you have acheived this, you can perform simple math on the mantissa values:

( 1.5 + 23 ) e5

or 24.5e5

or (more correctly, I suppose) 2.45e6

----

Subtraction is essentially the same as above.

During multiplication, you multiply the mantissa values and add the exponent values.

Division is something like divide mantissas and subtract the exponents.

Using the above technique, you can have exceptionally big numbers (and headaches).

Hope this helps,

- Nigel