Internal structure of long double and double 
Author Message
 Internal structure of long double and double

Hi,
In 16 bit C a long double type was 80 bits 10 bytes long, in 32 bit C a long
double become a regular double. This resulted in loss of a type. However I
need to use double long 80 bits long. To make this I could use a structure
like:

struct{
DWORD a;
DWORD b;
WORD c;

Quote:
}LONG_DOUBLE;

This is fine. But this solution involves me to implement data translation.
The problem is:
I don't know the exact specification those three fields, what their values
should be and what they represent.

ILiya



Sat, 03 May 2003 03:00:00 GMT  
 Internal structure of long double and double
Hi,

take a look at
http://msdn.microsoft.com/library/default.asp?URL=/library/devprods/v...
alc/vclang/_clang_type_long_double.htm
it states that

"The long double contains 80 bits: 1 for sign, 15 for exponent, and 64 for
mantissa. Its range is +/-1.2E4932 with at least 19 digits of precision.
Although long double and double are separate types, the representation of
long double and double is identical."

It seems that ist just a regular IEEE-Floating point number with a longer
exponent and mantisse (15 instead of 11 exp. and 64 intead of 52 mant.)

HTH
Markus



Quote:

> Hi,
> In 16 bit C a long double type was 80 bits 10 bytes long, in 32 bit C a
long
> double become a regular double. This resulted in loss of a type.



Sat, 03 May 2003 03:00:00 GMT  
 Internal structure of long double and double

If you go to the Intel web site and look at the technical documentation I am
sure that you will find more about the Floating Point unit than you ever
thought possible.

You may have 80 bit FP numbers but how do you intend to operate on them?
If you want to do any FP operations like add, subtract, multiply, divide etc
you have a bit of a problem.

You could do it as ASM code I suppose.

Nick

--
Nick Kotarski

Quote:

> Hi,
> In 16 bit C a long double type was 80 bits 10 bytes long, in 32 bit C a
long
> double become a regular double. This resulted in loss of a type. However I
> need to use double long 80 bits long. To make this I could use a structure
> like:

> struct{
> DWORD a;
> DWORD b;
> WORD c;
> }LONG_DOUBLE;

> This is fine. But this solution involves me to implement data translation.
> The problem is:
> I don't know the exact specification those three fields, what their values
> should be and what they represent.

> ILiya



Sat, 03 May 2003 03:00:00 GMT  
 Internal structure of long double and double

Quote:
> "The long double contains 80 bits: 1 for sign, 15 for exponent, and 64 for
> mantissa. Its range is +/-1.2E4932 with at least 19 digits of precision.
> Although long double and double are separate types, the representation of
> long double and double is identical."

> It seems that ist just a regular IEEE-Floating point number with a longer
> exponent and mantisse (15 instead of 11 exp. and 64 intead of 52 mant.)
> "The long double contains 80 bits: 1 for sign, 15 for exponent, and 64 for
> mantissa. Its range is +/-1.2E4932 with at least 19 digits of precision.
> Although long double and double are separate types, the representation of
> long double and double is identical."

> It seems that ist just a regular IEEE-Floating point number with a longer
> exponent and mantisse (15 instead of 11 exp. and 64 intead of 52 mant.)

Ok, so I need to squeeze a 15 bit exponent value of a long double, lets say
16401d (0x4011), into first 11 bit value of a double. HOW???
And how to set the rest 52 bytes of a double mantissa? For instance, from
long a double's mantissa we could have somthing like -217808896 value.

ILiya



Sat, 03 May 2003 03:00:00 GMT  
 Internal structure of long double and double

Quote:
> You may have 80 bit FP numbers but how do you intend to operate on them?
> If you want to do any FP operations like add, subtract, multiply, divide
etc
> you have a bit of a problem.

Actually that represents a real problem. I do have old values of this old
type in database, which I retrieve from database records as raw data (a bate
array buffer). And I need to at least be able calculating them, not to say
having changed them to write them back.

I could well shift to Delphi framework which offers Extended (80 bit floting
point) type. But I don't really want to do it in a middle, because of this
"small" crux.

ILiya



Sat, 03 May 2003 03:00:00 GMT  
 Internal structure of long double and double
From the MSDN section on Floating Point Support in
VC++:

"The Microsoft run-time library sets the default internal
precision of the math coprocessor (or emulator) to
64 bits. This default applies only to the internal precision
at which all intermediate calculations are performed;
it does not apply to the size of arguments, return values,
or variables. You can override this default and set the
chip (or emulator) back to 80-bit precision by linking
your program with LIB/FP10.OBJ. On the linker
command line, FP10.OBJ must appear before
LIBC.LIB, LIBCMT.LIB, or MSVCRT.LIB."

You might also see KBase article Q129209, which
has some inline assembler that may give you some
ideas.

MS altered this behavior in part for NT support on the
Alpha processor.

Hope this helps.

<snip>

Quote:
>Actually that represents a real problem. I do have old values of this old
>type in database, which I retrieve from database records as raw data (a
bate
>array buffer). And I need to at least be able calculating them, not to say
>having changed them to write them back.

>I could well shift to Delphi framework which offers Extended (80 bit
floting
>point) type. But I don't really want to do it in a middle, because of this
>"small" crux.



Sat, 03 May 2003 03:00:00 GMT  
 Internal structure of long double and double


Quote:
> From the MSDN section on Floating Point Support in
> VC++:

> "The Microsoft run-time library sets the default internal
> precision of the math coprocessor (or emulator) to
> 64 bits. This default applies only to the internal precision
> at which all intermediate calculations are performed;
> it does not apply to the size of arguments, return values,
> or variables. You can override this default and set the
> chip (or emulator) back to 80-bit precision by linking
> your program with LIB/FP10.OBJ. On the linker
> command line, FP10.OBJ must appear before
> LIBC.LIB, LIBCMT.LIB, or MSVCRT.LIB."

I was testing this on a console application. After including FP10.obj
sizeof(long double) returnes still 8 bytes.

Quote:
> You might also see KBase article Q129209, which
> has some inline assembler that may give you some
> ideas.

 unsigned char res[10] = {0,0,0,0,0,0x80,0x04,0xF3,0x11,0x40};
 double Newdbl;
 _asm {
      fld TBYTE PTR res;
      fstp Newdbl;
   }
returnes the correct value. THANKS. That was all i needed. However it would
be good to also know how to convert an 8 byte to 10 byte too.

Tanks,
ILiya



Sun, 04 May 2003 03:00:00 GMT  
 Internal structure of long double and double
Thanks Ron,
Since the assembler based solution turned out to work both ways, that's the
end of the story.
ILiya


Sun, 04 May 2003 03:00:00 GMT  
 Internal structure of long double and double
Glad everything worked out.
Quote:

>Thanks Ron,
>Since the assembler based solution turned out to work both ways, that's the
>end of the story.



Sun, 04 May 2003 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. can long double be less precise than double?

2. epsilon for float, double long double

3. Difference between double and long double?

4. Converting long double to double

5. diff between double and long double

6. Difference between double & long double

7. Long long and long double

8. result of double*double is no double

9. long long integer and double precision number

10. addition long values to long double value ?

11. long double to string & string to long double

12. Problem with Double.IsNan() and Double.Nan

 

 
Powered by phpBB® Forum Software