views:

25

answers:

1

Hi there.

Can anyone offer any advice on how to get the mantissa and exponent from a double in VB.net? I know I can do a string parse and some conversion to ints but I wondered if anyone had a mathematical equivalent formula that would allow me to do this?

Many thanks

+2  A: 

Do you want to get the "native" mantissa and exponent within the IEEE-754 value? That's actually fairly easy: use BitConverter.DoubleToInt64Bits to get the value as an integer (which is easier to perform bit operations on) and then see my article on .NET binary floating point types for which bits are where.

I have some C# code which extracts the various parts in order to convert it to a precise decimal representation - you could convert the relevant bits of that into VB reasonably easily.

Jon Skeet
I just want to get the exponent and manitssa as two seperate integer values.
WizardsSleeve
user479122: But in what format? Do you mean as *decimal* exponent and mantissa? Or the native base-2 exponent and mantissa?
Jon Skeet
sorry, the decimal exponent and mantissa.
WizardsSleeve