XP is just a number PerlMonks

### Re^4: Detecting whether UV fits into an NV

by pryrt (Prior)
 on Feb 27, 2020 at 14:53 UTC Need Help??

in reply to Re^3: Detecting whether UV fits into an NV
in thread Detecting whether UV fits into an NV

Once you phrased it this way, I realized you finally gave me an in-the-wild use-case for my Data::IEEE754::Tools. Thanks! :-)

```#!/usr/bin/env perl

use strict;
use warnings;
use Data::IEEE754::Tools qw/ulp/;

sub uv_fits_double_using_ulp {
0 == (\$_[0] % (\$_[0]/ulp(\$_[0])))
}

my @in = map { no warnings 'portable'; chomp; oct('0b'.\$_) } <DATA>;

for(@in) {
my \$d = \$_/ulp(\$_);
printf "%-24s: %4d %32.15f %16d %1s\n", \$_, ulp(\$_), \$_/ulp(\$_), \$
+_ % \$d, uv_fits_double_using_ulp(\$_) ? 'T' : 'F';
}

__END__
1111111111111111111111111111111111111111111111111111100000000000
1111111111111111111111111111111111111111111111111111110000000000
1111111111111111111111111111111111111111111111111111100000000001
1111111111111111111111111111111111111111111110011011100000000000
1111111111111111111111111111111111111111111111111111100000000000
0111111111111111111111111111111111111111111111111111110000000000
0011111111111111111111111111111111111111111111111111111000000000
0001111111111111111111111111111111111111111111111111111100000000
0000111111111111111111111111111111111111111111111111111110000000
0000011111111111111111111111111111111111111111111111111111000000
0000001111111111111111111111111111111111111111111111111111100000
0000000111111111111111111111111111111111111111111111111111110000
0000000011111111111111111111111111111111111111111111111111111000
0000000001111111111111111111111111111111111111111111111111111100
0000000000111111111111111111111111111111111111111111111111111110
0000000000011111111111111111111111111111111111111111111111111111
0000000000111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111
which gives
```18446744073709549568    : 2048 9007199254740991.000000000000000
+         0 T
18446744073709550592    : 4096 4503599627370496.000000000000000 450359
+9627369472 F
18446744073709549569    : 2048 9007199254740991.000000000000000
+         1 F
18446744073709139968    : 2048 9007199254740791.000000000000000
+         0 T
18446744073709549568    : 2048 9007199254740991.000000000000000
+         0 T
9223372036854774784     : 1024 9007199254740991.000000000000000
+         0 T
4611686018427387392     :  512 9007199254740991.000000000000000
+         0 T
2305843009213693696     :  256 9007199254740991.000000000000000
+         0 T
1152921504606846848     :  128 9007199254740991.000000000000000
+         0 T
576460752303423424      :   64 9007199254740991.000000000000000
+         0 T
288230376151711712      :   32 9007199254740991.000000000000000
+         0 T
144115188075855856      :   16 9007199254740991.000000000000000
+         0 T
72057594037927928       :    8 9007199254740991.000000000000000
+         0 T
36028797018963964       :    4 9007199254740991.000000000000000
+         0 T
18014398509481982       :    2 9007199254740991.000000000000000
+         0 T
9007199254740991        :    1 9007199254740991.000000000000000
+         0 T
18014398509481983       :    4 4503599627370496.000000000000000 450359
+9627370495 F
18446744073709551615    : 4096 4503599627370496.000000000000000 450359
+9627370495 F

I doubt it's faster than some of hte others

Create A New User
Node Status?
node history
Node Type: note [id://11113497]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2020-06-04 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Do you really want to know if there is extraterrestrial life?

Results (35 votes). Check out past polls.

Notices?