I'm not sure if this helps ...
Heh ... it helps ... but only in that it reaffirms what I already knew ;-)
I'll elaborate a little on how this all came about.
As I mentioned in the opening post, with perl-5.34.0, pack's 'D' templates are allowed on all builds irrespective of whether $Config{nvtype} is 'double' or 'long double' or '__float128'.
In earlier perl versions the 'D' templates were supported only if $Config{nvtype} was 'long double'.
With perl-5.34.0 and nvtype of 'long double' we get:
C:\>perl -wle "print unpack 'H*', pack 'D', 2.4;"
9a999999999999990040000000000000
whereas with perl-5.34.0 and nvtype of double, the same command yields a slightly different result:
C:\>perl -wle "print unpack 'H*', pack 'D', 2.4;"
00989999999999990040000000000000
That's pretty much as I expected because the string being unpacked in the first one-liner is different to the string being unpacked in the second one-liner.
But then I wanted to see what the result would be if the string created on the long double build (in the first one-liner) was fed to the 'double' build (in the second one-liner).
Would the result be 9a999999999999990040000000000000 or 00989999999999990040000000000000 ?
(I was quite sure it would be the former, but I knew that if I didn't check then I'd get it wrong.)
So I thought I'd do something cute:
I decided that, on my 'long double' build, I would run the following script:
use warnings;
$template = 'D<';
$nv = 2.4;
$p = pack $template, $nv;
$s = "'$p'";
# Now pass $p to the 'double' build of perl.
$double_perl = "C:/perl-5.34.0/bin/MSWin32-x64-multi-thread/perl.exe";
system $double_perl, '-wle', "print unpack('H*', $s);";
But, as already demonstrated, that doesn't DWIM.
In the end, I took the clunky approach of running 2 scripts.
Firstly, on the 'long double' build of perl-5.34.0 I ran the following script that would print the string returned by pack() to a file:
use warnings;
$p = pack("D", 2.4);
open WR, '>', 'packstr.txt' or die "Opening: $!";
binmode(WR);
print WR $p;
close WR or die "Closing: $!";
Then, on the 'double' build of perl-5.34.0, I ran a script that passed the string that was saved in packstr.txt to unpack():
use warnings;
open RD, '<', 'packstr.txt' or die "Opening: $!";
binmode(RD);
$p = <RD>;
close RD or die "Closing: $!";
print unpack("H*", $p);
That script output 9a999999999999990040000000000000.
(Hmph ... as if it was ever going to do anything else ...)
It just would have been so much cleaner and simpler if I could have got the first approach to work.
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.