I think that checking whether the UV arg == (UV)((NV)arg) is a splendid idea
Unfortunately this check fails for some UV values with less recent Microsoft Compilers - eg Visual Studio 2010 and earlier.
No problems with Visual Studio 2017 and Visual Studio 2019.
I suspect that Visual Studio 2015 is the oldest Microsoft Compiler that doesn't suffer from this problem, but I haven't confirmed that.
This particular issue looks like another manifestation of the problem that sent me down this path in the first place.
Here's the demo I ran:
use strict;
use warnings;
use Inline C => Config =>
BUILD_NOISY => 1;
use Inline C => <<'EOC';
int uv_fits_double1( UV arg ) {
if(arg == (UV)((NV)arg)) return 1;
return 0;
}
int uv_fits_double2(UV arg) {
while(!(arg & 1)) arg >>= 1;
if(arg < 9007199254740993) return 1;
return 0;
}
EOC
my $ls = 63;
my @in = ( 18446744073709549568, 18446744073709139968);
for(@in) { print "$_: ", uv_fits_double1($_),uv_fits_double2($_), "\n"
+; }
__END__
With Windows Server 2003 SP1 Platform SDK, this outputs:
18446744073709549568: 01
18446744073709139968: 01
Base 2 representations of the 2 Uvs is (resp):
1111111111111111111111111111111111111111111111111111100000000000
1111111111111111111111111111111111111111111110011011100000000000
showing that both are exactly representable by a double.
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, 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, 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.
|
|