As soon as the value is loaded into an FP register, it gets silently converted to a QNan
I was thinking that when we do:
$packed = pack 'd', '7ff0000000000001';
$d = unpack 'h16', $packed;
there would be no loading of the double into an FP register.
But I guess that thinking must be wrong as $d is definitely set to '7ff8000000000001', on my Windows box at least.
On my Linux box (also little-endian), however, there's no such problem and I can assign '7ff0000000000001' just fine.
Is this difference a Windows v Linux thing ? ... or is it to be explained in terms of different hardware ?
Do you know of
any way that one can assign the value '7ff0000000000001' on Windows ? (I haven't found a way, yet.)
Here's a nice Perl demo (utilising the union you provided) of the Windows/Linux discrepancy:
use warnings;
use strict;
use Inline C => Config =>
BUILD_NOISY => 1;
use Inline C => <<'EOC';
#ifdef _WIN32
typedef __int64 BIGGUN;
#else
/* "long" is 64-bit on my linux box */
typedef long BIGGUN;
#endif
typedef union {
double d;
BIGGUN i;
} BITS64;
void bytes(double d) {
int i;
void * p = &d;
for(i = 7; i >=0; i--)
printf("%02x", ((unsigned char*)p)[i]);
printf("\n");
}
double get_snan () {
BITS64 x;
x.i = 0x7ff0000000000001;
bytes(x.d);
return x.d;
}
EOC
print doubleToHex(get_snan());
sub doubleToHex { scalar reverse unpack 'h16', pack 'd', $_[0] }
On Windows it outputs:
7ff0000000000001
7ff8000000000001
On Ubuntu it outputs:
7ff0000000000001
7ff0000000000001
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.