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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|