Anton Hornquist wrote in post #1067775:
> I guess this is quite simple. I just cant get my head around the
> description in the wikipedia page. Yet.
>
> http://en.m.wikipedia.org/wiki/Extended_precision

"The standard specifies the minimum requirements for an extended format 
but does not specify an encoding.[5] The encoding is the implementor's 
choice."

So it's undefined. Do you have some sample values, and know what they 
translate to?

As a test, let's see what GCC gives.

#include <stdio.h>
int main(void)
{
  long double foo = 12.5;
  unsigned char *p = (unsigned char *)&foo;
  int i;
  for (i=0; i<sizeof(foo); i++) {
    printf("%02x ", p[i]);
  }
  printf("\n");
  return 0;
}

This gives me a value padded to 16 bytes. Taking the first 10 bytes:

>> str = "\x00\x00\x00\x00\x00\x00\x00\xc8\x02\x40"
>> mant, exp = str.unpack("QS")
=> [14411518807585587200, 16386]
>> "%064b" % mant
=> "1100100000000000000000000000000000000000000000000000000000000000"
>> "%016b" % exp
=> "0100000000000010"

(i.e. zero sign, exponent = 16384+2)

The value we want is:

>> mant / (2.0**63) * 2.0**(exp-16383)
=> 12.5

or equivalently:

>> mant * 2.0 ** (exp-16446)
=> 12.5

Note that unpack("Q") depends on the endianness of the system running 
the code, so this isn't portable to big-endian processors.

-- 
Posted via http://www.ruby-forum.com/.