Re: Binary representation of a double?
- From: José Manuel Agüero <chema012 en hotmail.com>
- Date: Sat, 1 Apr 2006 13:27:49 +0200
Hello vecozo,
The binary representation of a double is, in fact (with the bytes ordered):
SEEEEEEE EEEEMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM
The first bit of the mantissa is omitted and is always 1 for normalized numbers.
The precision P of the representation of a double D is: D * 2 ^ -53 <= P < D * 2 ^ -52.
If you take the exponent E, the precision is exactly 2 ^ (E - 53)
For more information, visit, for example:
IEEE Standard 754 Floating Point Numbers
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
What Every Computer Scientist Should Know About Floating-Point Arithmetic
http://docs.sun.com/source/806-3568/ncg_goldberg.html
Regards.
<vecozo@xxxxxxxxxxxxx> escribió en el mensaje news:89E20A1D-1E20-402E-AAFC-539BC90C53AE@xxxxxxxxxxxxxxxx
| Hello,
|
| We are writing an application in C# that finds roots of a function up to
| machine precision. Therefore I have to compare the number of significant bits
| in two double variables (the upper- and lowerbound of the interval containing
| the root). Currently I am struggling with the binary representation of a
| double variable.
|
| I have written some test code and it seems that the binary representation of
| a double is given by:
|
| MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM EEESMMMM EEEEEEEE
|
| Where M denotes the mantissa, E the exponent and S the sign.
|
| The location of the least significant bit (*) is seems to be given by:
|
| MMMMMMM* MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM EEESMMMM EEEEEEEE
|
| And the most significant bit:
|
| MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM EEES*MMM EEEEEEEE
|
| This would mean that the mantissa part is written as:
|
| qrstuvwxy ijklmnop abcdefgh
|
| Where y is the least significant bit and a the most significant bit. This is
| kind of unfortunate, because we cannot simply use a bitwise shift operator to
| determine if all but the least significant bit are equal. Could you confirm
| if we have this bitwise structure correct?
|
| Regards,
| Martijn Kaag
|
| We use test code similar to the following to obtain the bitwise
| representation:
| > public string GetBitString (double d) {
| >
| > byte[] bytes = ToByte(d);
| > string rval = “”;
| > for (int b=0; b<8;b++) {
| > rval += GetBitString (bytes[b]) + “ ”;
| > }
| > return rval;
| > }
| > public unsafe Byte[] ToByte ( double d)
| > {
| >
| > *Byte[] byte;
| > &byte = (*Byte[])&d;
| > return byt;
| >
| > }
| >
| > public string GetBitString (byte b)
| > {
| > string rval = "";
| >
| >
| > for (int i=0; i <8;i++)
| > {
| > if (b>=126){
| > // alleen >=126 als meest significante bit in b = 1
| > rval += "1";
| > }
| > else {
| > rval += "0";
| > }
|
|
| ______________________________
| www.VECOZO.nl
.
- Follow-Ups:
- Re: Binary representation of a double?
- From: Martijn Kaag
- Re: Binary representation of a double?
- Prev by Date: Own Drawn Forms
- Next by Date: Re: Merging ActiveX Control
- Previous by thread: Own Drawn Forms
- Next by thread: Re: Binary representation of a double?
- Index(es):
Relevant Pages
|