From b0f0b674bcf9986ebc656ed12d388e0a4e74db8f Mon Sep 17 00:00:00 2001 From: PeterCJ Date: Mon, 25 Sep 2017 14:38:56 -0700 Subject: [PATCH 1/6] v0.018002: add a bunch of debug to 02-converttostr.t; change from README.pod to README.md to stay out of the way of the automatic .pod->library, which is what was triggering the 'make README.pod' during the smoke testing --- CHANGES | 12 +++++ MANIFEST | 2 +- Makefile.PL | 4 +- README.md | 106 ++++++++++++++++++++++++++++++++++++ README.pod | 109 -------------------------------------- RELEASE.md | 4 +- lib/Data/IEEE754/Tools.pm | 47 +++++++++++++++- t/02-converttostr.t | 11 ++++ t/04-nextupdown.t | 6 +-- t/05-nextafter.t | 6 +-- 10 files changed, 187 insertions(+), 120 deletions(-) create mode 100644 README.md delete mode 100644 README.pod diff --git a/CHANGES b/CHANGES index f954d97..1c862df 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,17 @@ Revision history for Perl module Data::IEEE754::Tools. +v0.018002 2017-Sep-25 + - Change from README.pod to README.md, because *.pod are built and put in + the module documentation directory + - Debugging roundoff on certain systems (not sure yet what the common + aspect of the systems are, because bsd or mswin for the same perl version + will both pass and fail -- my guess is 32bit vs 64bit machines, maybe + in the integer processing, but I need data that will show me what's + different, so I'm doing another "official" release that turns on debug + printing during the test suite for known-buggy values. (I would do alpha, + but the smoke testers didn't run when I tried v0.017_xxx alpha versions, + so sorry. This release should be no more broken than v0.018 or v0.018001) + v0.018001 2017-Sep-24 - for some reason, `make test` was invoking `make README.pod`: trying to fix diff --git a/MANIFEST b/MANIFEST index 27df629..9dcbf19 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3,7 +3,7 @@ LICENSE Makefile.PL MANIFEST This list of files lib/Data/IEEE754/Tools.pm -README.pod +README.md RELEASE.md t/00-load.t t/01-internalstring.t diff --git a/Makefile.PL b/Makefile.PL index 96927bb..bc845b0 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -111,8 +111,10 @@ realclean :: $(NOECHO) ( $(TEST_D) cover_db && $(RM_RF) cover_db ) || $(ECHO) realclean:: skip "rm -rf cover_db" # auto-generate the README from the lib/Data/IEEE754/Tools.pm -README.pod :: lib/Data/IEEE754/Tools.pm +README.md :: lib/Data/IEEE754/Tools.pm podselect -section "NAME|SYNOPSIS|DESCRIPTION|COMPATIBILITY|INSTALLATION|AUTHOR|COPYRIGHT|LICENSE/!IEEE 754 Encoding" lib/Data/IEEE754/Tools.pm > README.pod + pod2markdown README.pod README.md + $(RM_F) README.pod POSTAMBLE } diff --git a/README.md b/README.md new file mode 100644 index 0000000..01cdb53 --- /dev/null +++ b/README.md @@ -0,0 +1,106 @@ +# NAME + +Data::IEEE754::Tools - Various tools for understanding and manipulating the underlying IEEE-754 representation of floating point values + +# SYNOPSIS + + use Data::IEEE754::Tools qw/:convertToString :ulp/; + + # return -12.875 as strings of decimal or hexadecimal floating point numbers ("convertTo*Character" in IEEE-754 parlance) + convertToDecimalString(-12.875); # -0d1.6093750000000000p+0003 + convertToHexString(-12.875); # -0x1.9c00000000000p+0003 + + # shows the smallest value you can add or subtract to 16.16 (ulp = "Unit in the Last Place") + print ulp( 16.16 ); # 3.5527136788005e-015 + + # toggles the ulp: returns a float that has the ULP of 16.16 toggled + # (if it was a 1, it will be 0, and vice versa); + # running it twice should give the original value + print $t16 = toggle_ulp( 16.16 ); # 16.159999999999997 + print $v16 = toggle_ulp( $t16 ); # 16.160000000000000 + +# DESCRIPTION + +These tools give access to the underlying IEEE 754 floating-point 64bit representation +used by many instances of Perl (see [perlguts](https://metacpan.org/pod/perlguts)). They include functions for converting +from the 64bit internal representation to a string that shows those bits (either as +hexadecimal or binary) and back, functions for converting that encoded value +into a more human-readable format to give insight into the meaning of the encoded +values, and functions to manipulate the smallest possible change for a given +floating-point value (which is the [ULP](https://en.wikipedia.org/wiki/Unit_in_the_last_place) or +"Unit in the Last Place"). + +## Justification for the existence of **Data::IEEE754::Tools** + +[Data::IEEE754](https://metacpan.org/pod/Data::IEEE754), or the equivalent ["pack" in perlfunc](https://metacpan.org/pod/perlfunc#pack) recipe [d>](https://metacpan.org/pod/d>), do a +good job of converting a perl floating value (NV) into the big-endian bytes +that encode that value, but they don't help you interpret the value. + +[Data::Float](https://metacpan.org/pod/Data::Float) has a similar suite of tools to **Data::IEEE754::Tools**, but +uses numerical methods rather than accessing the underlying bits. It [has been +shown](http://perlmonks.org/?node_id=1167146) that its interpretation function can take +an order of magnitude longer than a routine that manipulates the underlying bits +to gather the information. + +This **Data::IEEE754::Tools** module combines the two sets of functions, giving +access to the raw IEEE 754 encoding, or a stringification of the encoding which +interprets the encoding as a sign and a coefficient and a power of 2, or access to +the ULP and ULP-manipulating features, all using direct bit manipulation when +appropriate. + +## Compatibility + +**Data::IEEE754::Tools** works with 64bit floating-point representations. + +If you have a Perl setup which uses a larger representation (for example, +`use [Config](https://metacpan.org/pod/Config); print $Config{nvsize}; # 16 => 128bit`), values reported by +this module will be reduced in precision to fit the 64bit representation. + +If you have a Perl setup which uses a smaller representation (for example, +`use [Config](https://metacpan.org/pod/Config); print $Config{nvsize}; # 4 => 32bit`), the installation +will likely fail, because the unit tests were not set up for lower precision +inputs. However, forcing the installation _might_ still allow coercion +from the smaller Perl NV into a true IEEE 754 double (64bit) floating-point, +but there is no guarantee it will work. + +# INSTALLATION + +To install this module, use your favorite CPAN client. + +For a manual install, type the following: + + perl Makefile.PL + make + make test + make install + +(On Windows machines, you may need to use "dmake" or "gmake" instead of "make", depending on your setup.) + +# AUTHOR + +Peter C. Jones `` + +Please report any bugs or feature requests emailing `` +or thru the web interface at [http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-IEEE754-Tools](http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-IEEE754-Tools), +or thru the repository's interface at [https://github.com/pryrt/Data-IEEE754-Tools/issues](https://github.com/pryrt/Data-IEEE754-Tools/issues). + +
+ + + + + + +
+ +# COPYRIGHT + +Copyright (C) 2016-2017 Peter C. Jones + +# LICENSE + +This program is free software; you can redistribute it and/or modify it +under the terms of either: the GNU General Public License as published +by the Free Software Foundation; or the Artistic License. + +See [http://dev.perl.org/licenses/](http://dev.perl.org/licenses/) for more information. diff --git a/README.pod b/README.pod deleted file mode 100644 index 105dfea..0000000 --- a/README.pod +++ /dev/null @@ -1,109 +0,0 @@ -=head1 NAME - -Data::IEEE754::Tools - Various tools for understanding and manipulating the underlying IEEE-754 representation of floating point values - -=head1 SYNOPSIS - - use Data::IEEE754::Tools qw/:convertToString :ulp/; - - # return -12.875 as strings of decimal or hexadecimal floating point numbers ("convertTo*Character" in IEEE-754 parlance) - convertToDecimalString(-12.875); # -0d1.6093750000000000p+0003 - convertToHexString(-12.875); # -0x1.9c00000000000p+0003 - - # shows the smallest value you can add or subtract to 16.16 (ulp = "Unit in the Last Place") - print ulp( 16.16 ); # 3.5527136788005e-015 - - # toggles the ulp: returns a float that has the ULP of 16.16 toggled - # (if it was a 1, it will be 0, and vice versa); - # running it twice should give the original value - print $t16 = toggle_ulp( 16.16 ); # 16.159999999999997 - print $v16 = toggle_ulp( $t16 ); # 16.160000000000000 - -=head1 DESCRIPTION - -These tools give access to the underlying IEEE 754 floating-point 64bit representation -used by many instances of Perl (see L). They include functions for converting -from the 64bit internal representation to a string that shows those bits (either as -hexadecimal or binary) and back, functions for converting that encoded value -into a more human-readable format to give insight into the meaning of the encoded -values, and functions to manipulate the smallest possible change for a given -floating-point value (which is the L or -"Unit in the Last Place"). - -=head2 Justification for the existence of B - -L, or the equivalent L recipe L>, do a -good job of converting a perl floating value (NV) into the big-endian bytes -that encode that value, but they don't help you interpret the value. - -L has a similar suite of tools to B, but -uses numerical methods rather than accessing the underlying bits. It L that its interpretation function can take -an order of magnitude longer than a routine that manipulates the underlying bits -to gather the information. - -This B module combines the two sets of functions, giving -access to the raw IEEE 754 encoding, or a stringification of the encoding which -interprets the encoding as a sign and a coefficient and a power of 2, or access to -the ULP and ULP-manipulating features, all using direct bit manipulation when -appropriate. - -=head2 Compatibility - -B works with 64bit floating-point representations. - -If you have a Perl setup which uses a larger representation (for example, -C; print $Config{nvsize}; # 16 =E 128bit>), values reported by -this module will be reduced in precision to fit the 64bit representation. - -If you have a Perl setup which uses a smaller representation (for example, -C; print $Config{nvsize}; # 4 =E 32bit>), the installation -will likely fail, because the unit tests were not set up for lower precision -inputs. However, forcing the installation I still allow coercion -from the smaller Perl NV into a true IEEE 754 double (64bit) floating-point, -but there is no guarantee it will work. - -=head1 INSTALLATION - -To install this module, use your favorite CPAN client. - -For a manual install, type the following: - - perl Makefile.PL - make - make test - make install - -(On Windows machines, you may need to use "dmake" or "gmake" instead of "make", depending on your setup.) - -=head1 AUTHOR - -Peter C. Jones Cpetercj AT cpan DOT orgE> - -Please report any bugs or feature requests emailing Cbug-Data-IEEE754-Tools AT rt.cpan.orgE> -or thru the web interface at L, -or thru the repository's interface at L. - -=begin html - - - - - - - - -=end html - -=head1 COPYRIGHT - -Copyright (C) 2016-2017 Peter C. Jones - -=head1 LICENSE - -This program is free software; you can redistribute it and/or modify it -under the terms of either: the GNU General Public License as published -by the Free Software Foundation; or the Artistic License. - -See L for more information. - diff --git a/RELEASE.md b/RELEASE.md index 45672b5..7e83d13 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -31,8 +31,8 @@ I use a local svn client to checkout the GitHub repo. All these things can be d * `pod2text lib/Data/IEEE754/Tools.pm README`, then edit so that only NAME, DESCRIPTION, COMPATIBILITY, INSTALLATION, AUTHOR, COPYRIGHT, LICENSE remain - * or, with README.pod instead: `podselect -section "NAME|SYNOPSIS|DESCRIPTION|COMPATIBILITY|INSTALLATION|AUTHOR|COPYRIGHT|LICENSE/!IEEE 754 Encoding" lib\Data\IEEE754\Tools.pm > README.pod` - * or `dmake README.pod` + * or, with README.pod instead: `podselect -section "NAME|SYNOPSIS|DESCRIPTION|COMPATIBILITY|INSTALLATION|AUTHOR|COPYRIGHT|LICENSE/!IEEE 754 Encoding" lib\Data\IEEE754\Tools.pm > README.pod`, then `pod2markdown README.pod README.md` + * or `dmake README.md` * verify CHANGES (history) * **Build Distribution** diff --git a/lib/Data/IEEE754/Tools.pm b/lib/Data/IEEE754/Tools.pm index 19bc3c3..34e109c 100644 --- a/lib/Data/IEEE754/Tools.pm +++ b/lib/Data/IEEE754/Tools.pm @@ -6,7 +6,7 @@ use Carp; use Exporter 'import'; # just use the import() function, without the rest of the overhead of ISA use Config; -our $VERSION = '0.018001'; +our $VERSION = '0.018002'; # use rrr.mmm_aaa, where rrr is major revision, mmm is ODD minor revision, and aaa is alpha sub-revision (for ALPHA code) # use rrr.mmmsss, where rrr is major revision, mmm is EVEN minor revision, and sss is a sub-revision (usually sss=000) (for releases) @@ -401,9 +401,32 @@ hex-digits or 16 decimal-digits). =cut +sub DBG_SPRINTF { + return unless $Data::IEEE754::Tools::CPANTESTERS_DEBUG; + my $fmt = shift; + warn sprintf("# __%04d__\t", (caller)[2]), sprintf( $fmt, @_ ), "\n"; +} +use Devel::Peek (); +sub DBG_PEEK { + return unless $Data::IEEE754::Tools::CPANTESTERS_DEBUG; + my ($name, $var) = @_; + open( my $ek , '>&STDERR') or die "dup STDERR: $!"; + close(STDERR); + my $txt; + open(STDERR, '>', \$txt) or die "STDERR to var: $!"; + Devel::Peek::Dump($var); + close(STDERR); + open(STDERR, ">&", $ek) or die "STDERR back to orig: $!"; + $txt =~ s/^/# \t\t# /gims; + $txt =~ s/\s*$//gims; + DBG_SPRINTF("Devel::Peek::Dump(%s):\n%s", $name, $txt); +} sub binary64_convertToHexString { # thanks to BrowserUK @ http://perlmonks.org/?node_id=1167146 for slighly better decision factors # I tweaked it to use the two 32bit words instead of one 64bit word (which wouldn't work on some systems) +print STDERR "#\n" if $Data::IEEE754::Tools::CPANTESTERS_DEBUG; +DBG_SPRINTF('binary64_convertToHexString()'); +DBG_SPRINTF("\t%-16s = %d", $_ => $Config{$_}) foreach( qw/nvsize ivsize doublesize intsize longsize ptrsize/ ); my $v = shift; my $p = defined $_[0] ? shift : 13; my ($msb,$lsb) = $_helper64_arr2x32b->($v); @@ -411,6 +434,8 @@ sub binary64_convertToHexString { my $sign = $sbit ? '-' : '+'; my $exp = (($msb & 0x7FF00000) >> 20) - 1023; my $mant = sprintf '%05x%08x', $msb & 0x000FFFFF, $lsb & 0xFFFFFFFF; +DBG_SPRINTF('[msb][lsb] = 0x%08x %08x => digits=%d', $msb, $lsb, $p); +DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, '?', $mant, $exp); if($exp == 1024) { my $z = "0"x (($p<5?4:$p)-4); return $sign . "0x1.#INF${z}p+0000" if $mant eq '0000000000000'; @@ -419,28 +444,41 @@ sub binary64_convertToHexString { return $sign . ( (($msb & 0x00080000) != 0x00080000) ? "0x1.#SNAN${z}p+0000" : "0x1.#QNAN${z}p+0000"); # v0.012 coverage note: '!=' condition only triggered on systems with SNAN; ignore Devel::Cover failures on this line on systems which quiet all SNAN to QNAN } my $implied = 1; +DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, $implied, $mant, $exp); if( $exp == -1023 ) { # zero or denormal $implied = 0; $exp = $mant eq '0000000000000' ? 0 : -1022; # 0 for zero, -1022 for denormal } +DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, $implied, $mant, $exp); if($p<13) { my $m = $msb & 0xFFFFF; my $l = $lsb; my $o = 0; +DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); if($p>=5) { # use all of MSB, and move into LSB my $one = 1 << 4*( 8 - ($p-5) ); my $haf = $one >> 1; my $eff = $one - 1; my $msk = 0xFFFFFFFF ^ $eff; +DBG_SPRINTF('... = (l:0x%08x & eff:0x%08x = and:0x%08x) vs (haf:0x%08x): %s', $l, $eff, $l & $eff, $haf, ((($l & $eff) >= $haf) ? '>=' : '<')); +DBG_PEEK('l ', $l); +DBG_PEEK('eff', $eff); +DBG_PEEK('haf', $haf); if( ($l & $eff) >= $haf) { $l = ($l & $msk) + $one; +DBG_PEEK('l ', $l); +DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); my $l32 = $l & 0xFFFFFFFF; +DBG_PEEK('l32', $l32); +DBG_PEEK('one', $one); if($l32 < $one) { $l = 0; $m++; } +DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); } else { $l = ($l & $msk); +DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); } if($m >= 0x1_0_0000) { $o = 1; @@ -455,24 +493,31 @@ sub binary64_convertToHexString { my $haf = $one >> 1; my $eff = $one - 1; my $msk = 0xFFFFF ^ $eff; +DBG_SPRINTF('... = (m:0x%05x & eff:0x%05x = and:0x%05x) vs (haf:0x%05x): %s', $m, $eff, $m & $eff, $haf, ((($m & $eff) >= $haf) ? '>=' : '<')); if( ($m & $eff) >= $haf) { $m = ($m & $msk) + $one; +DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); my $m20 = $m & 0xFFFFF; if($m20 < $one) { $m = 0; $o++; } +DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); } else { $m = ($m & $msk); +DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); } if($o) { $implied++; } } +DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); my $f = substr( sprintf('%05x%08x', $m, $l), 0, $p); +DBG_SPRINTF('%s0x%1u%s%*sp%+05d', $sign, $implied, $p?'.':'', $p, $f, $exp); return sprintf '%s0x%1u%s%*sp%+05d', $sign, $implied, $p?'.':'', $p, $f, $exp; } else { # thus, p>=13: +DBG_SPRINTF('%s0x%1u.%13.13sp%+05d', $sign, $implied, $mant . '0'x($p-13), $exp); return sprintf '%s0x%1u.%13.13sp%+05d', $sign, $implied, $mant . '0'x($p-13), $exp; } } diff --git a/t/02-converttostr.t b/t/02-converttostr.t index 9395d83..4fcd3e4 100644 --- a/t/02-converttostr.t +++ b/t/02-converttostr.t @@ -24,6 +24,17 @@ sub fptest { $h->{src}, $val, defined $h->{convSpec} ? $h->{convSpec} : '') ); + if( $h->{src} eq '3FFFFFFFFFFFFFFF' or $h->{src} eq '3FF0000000000001') { + $Data::IEEE754::Tools::CPANTESTERS_DEBUG = 1; + my $s = convertToHexString($val, $h->{convSpec}); + diag sprintf(qq(__%04d__\t/exited DEBUG:convertToHexString(ieee754(%-16.16s) = %-+24.16e, %s) = "%s"), + __LINE__, $h->{src}, $val, + defined $h->{convSpec} ? $h->{convSpec} : '', + $s + ); + diag ''; + undef $Data::IEEE754::Tools::CPANTESTERS_DEBUG; + } } else { like( $got = convertToHexString($val), qr/$exp/, diff --git a/t/04-nextupdown.t b/t/04-nextupdown.t index b8ac961..f17a1aa 100644 --- a/t/04-nextupdown.t +++ b/t/04-nextupdown.t @@ -24,8 +24,8 @@ sub fntest { my $n = shift || "$fn(0x$h => $v)"; my $tada = shift; my $r = undef; - note ''; - note "===== ${n} ====="; + #note ''; + #note "===== ${n} ====="; if($tada) { TODO: { local $TODO = $tada; @@ -86,7 +86,7 @@ sub fntest { } diag ''; } - note '-'x80; + # note '-'x80; } my @tests = (); diff --git a/t/05-nextafter.t b/t/05-nextafter.t index 51d2b8a..9d0df75 100644 --- a/t/05-nextafter.t +++ b/t/05-nextafter.t @@ -25,8 +25,8 @@ sub f2test { my $n = shift || "$fn(0x$h => $v)"; my $tada = shift; my $r = undef; - note ''; - note "===== ${n} ====="; + #note ''; + #note "===== ${n} ====="; if($tada) { TODO: { local $TODO = $tada; @@ -114,7 +114,7 @@ sub f2test { } diag ''; } - note '-'x80; + #note '-'x80; } my @tests = (); From 17133eac20709fd9c084f53a71be3fb46d828db9 Mon Sep 17 00:00:00 2001 From: PeterCJ Date: Tue, 26 Sep 2017 09:07:34 -0700 Subject: [PATCH 2/6] v0.018002: reorder; my theory is that $v <<= n will overflow iv to 0 rather than upgrading to nv; unfortunately, my 32bit perl still has ivsize=8 (64bit), so I cannot test or confirm; also, I dont know where all it might be happening. I hope I have enough peeks to determine; will be doing a non-signed release --- lib/Data/IEEE754/Tools.pm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/Data/IEEE754/Tools.pm b/lib/Data/IEEE754/Tools.pm index 34e109c..ebc5c6e 100644 --- a/lib/Data/IEEE754/Tools.pm +++ b/lib/Data/IEEE754/Tools.pm @@ -456,21 +456,22 @@ DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, $implied, $mant, $exp); my $o = 0; DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); if($p>=5) { # use all of MSB, and move into LSB +DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'l', $l), $l); my $one = 1 << 4*( 8 - ($p-5) ); +DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'one', $one), $one); # for p==5, on a 32bit ivsize=4, I think there is overflow in $one beyond IV, which may be part of the culprit; but why on the higher p, where $one fits within ivsize? Besides, shouldn't it just promote to NV if it overflows IV? That's why I want the Devel::Peek my $haf = $one >> 1; +DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'haf', $haf), $haf); my $eff = $one - 1; +DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'eff', $eff), $eff); my $msk = 0xFFFFFFFF ^ $eff; DBG_SPRINTF('... = (l:0x%08x & eff:0x%08x = and:0x%08x) vs (haf:0x%08x): %s', $l, $eff, $l & $eff, $haf, ((($l & $eff) >= $haf) ? '>=' : '<')); -DBG_PEEK('l ', $l); -DBG_PEEK('eff', $eff); -DBG_PEEK('haf', $haf); if( ($l & $eff) >= $haf) { $l = ($l & $msk) + $one; -DBG_PEEK('l ', $l); +DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'l', $l), $l); # maybe it was the (l&msk)+(one) ???? DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); my $l32 = $l & 0xFFFFFFFF; -DBG_PEEK('l32', $l32); -DBG_PEEK('one', $one); +DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'l32', $l32), $l32); +DBG_SPRINTF('... : l32 < one = 0x%08x < 0x%08x = %x', $l32, $one, $l32 < $one); if($l32 < $one) { $l = 0; $m++; From 3e15bc574688792dba37a818e1224a106f9fad91 Mon Sep 17 00:00:00 2001 From: PeterCJ Date: Tue, 26 Sep 2017 14:23:37 -0700 Subject: [PATCH 3/6] v0.018dbg: found that my 32b vm has ivsize=4, so using that; output to true32bit.txt; added notes, which indicate I need to rework things, so that I am never trying to make l bigger than 0xffff_ffff --- lib/Data/IEEE754/Tools.pm | 19 +- true32bit.txt | 753 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 763 insertions(+), 9 deletions(-) create mode 100644 true32bit.txt diff --git a/lib/Data/IEEE754/Tools.pm b/lib/Data/IEEE754/Tools.pm index ebc5c6e..51dd4d4 100644 --- a/lib/Data/IEEE754/Tools.pm +++ b/lib/Data/IEEE754/Tools.pm @@ -6,7 +6,7 @@ use Carp; use Exporter 'import'; # just use the import() function, without the rest of the overhead of ISA use Config; -our $VERSION = '0.018002'; +our $VERSION = '0.018003'; # use rrr.mmm_aaa, where rrr is major revision, mmm is ODD minor revision, and aaa is alpha sub-revision (for ALPHA code) # use rrr.mmmsss, where rrr is major revision, mmm is EVEN minor revision, and sss is a sub-revision (usually sss=000) (for releases) @@ -419,7 +419,7 @@ sub DBG_PEEK { open(STDERR, ">&", $ek) or die "STDERR back to orig: $!"; $txt =~ s/^/# \t\t# /gims; $txt =~ s/\s*$//gims; - DBG_SPRINTF("Devel::Peek::Dump(%s):\n%s", $name, $txt); + DBG_SPRINTF("__%04d__\tDevel::Peek::Dump(%s):\n%s", (caller)[2], $name, $txt); } sub binary64_convertToHexString { # thanks to BrowserUK @ http://perlmonks.org/?node_id=1167146 for slighly better decision factors @@ -457,20 +457,21 @@ DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, $implied, $mant, $exp); DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); if($p>=5) { # use all of MSB, and move into LSB DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'l', $l), $l); - my $one = 1 << 4*( 8 - ($p-5) ); -DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'one', $one), $one); # for p==5, on a 32bit ivsize=4, I think there is overflow in $one beyond IV, which may be part of the culprit; but why on the higher p, where $one fits within ivsize? Besides, shouldn't it just promote to NV if it overflows IV? That's why I want the Devel::Peek - my $haf = $one >> 1; -DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'haf', $haf), $haf); + my $one = 1; $one *= 2 for 1 .. 4*( 8 - ($p-5) ); # was 1 << 4*(), but doesn't work on {ivsize}=4 (32bit) +DBG_PEEK(sprintf("%-6s = 0x%08x or %.16e\t", 'one', $one, $one), $one); # for p==5, on a 32bit ivsize=4, I think there is overflow in $one beyond IV, which may be part of the culprit; but why on the higher p, where $one fits within ivsize? Besides, shouldn't it just promote to NV if it overflows IV? That's why I want the Devel::Peek + my $haf = $one / 2.0; +DBG_PEEK(sprintf("%-6s = 0x%08x or %.16e\t", 'haf', $haf, $haf), $haf); my $eff = $one - 1; -DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'eff', $eff), $eff); +DBG_PEEK(sprintf("%-6s = 0x%08x or %.16e\t", 'eff', $eff, $eff), $eff); my $msk = 0xFFFFFFFF ^ $eff; DBG_SPRINTF('... = (l:0x%08x & eff:0x%08x = and:0x%08x) vs (haf:0x%08x): %s', $l, $eff, $l & $eff, $haf, ((($l & $eff) >= $haf) ? '>=' : '<')); if( ($l & $eff) >= $haf) { +DBG_SPRINTF('... = (l:0x%08x & msk:0x%08x):0x%08x + one:0x%08x = 0x%08x', $l, $msk, $l & $msk, $one, ($l & $msk) + $one); $l = ($l & $msk) + $one; -DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'l', $l), $l); # maybe it was the (l&msk)+(one) ???? +DBG_PEEK(sprintf("%-6s = 0x%08x or %.16e\t", 'l', $l, $l), $l); # maybe it was the (l&msk)+(one) ???? DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); my $l32 = $l & 0xFFFFFFFF; -DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'l32', $l32), $l32); +DBG_PEEK(sprintf("%-6s = 0x%08x or %.16e\t", 'l32', $l32, $l32), $l32); DBG_SPRINTF('... : l32 < one = 0x%08x < 0x%08x = %x', $l32, $one, $l32 < $one); if($l32 < $one) { $l = 0; diff --git a/true32bit.txt b/true32bit.txt new file mode 100644 index 0000000..335ad9e --- /dev/null +++ b/true32bit.txt @@ -0,0 +1,753 @@ +1..362 +ok 1 - convertToHexString (ieee754(0000000000000000) = +0.0000000000000000e+00 ) +ok 2 - convertToDecimalString(ieee754(0000000000000000) = +0.0000000000000000e+00 ) +ok 3 - convertToHexString (ieee754(0000000000000000) = +0.0000000000000000e+00 , ) +ok 4 - convertToDecimalString(ieee754(0000000000000000) = +0.0000000000000000e+00 , ) +ok 5 - convertToHexString (ieee754(0000000000000000) = +0.0000000000000000e+00 , 10) +ok 6 - convertToDecimalString(ieee754(0000000000000000) = +0.0000000000000000e+00 , 10) +ok 7 - convertToHexString (ieee754(0000000000000000) = +0.0000000000000000e+00 , 13) +ok 8 - convertToDecimalString(ieee754(0000000000000000) = +0.0000000000000000e+00 , 13) +ok 9 - convertToHexString (ieee754(8000000000000000) = -0.0000000000000000e+00 ) +ok 10 - convertToDecimalString(ieee754(8000000000000000) = -0.0000000000000000e+00 ) +ok 11 - convertToHexString (ieee754(8000000000000000) = -0.0000000000000000e+00 , ) +ok 12 - convertToDecimalString(ieee754(8000000000000000) = -0.0000000000000000e+00 , ) +ok 13 - convertToHexString (ieee754(8000000000000000) = -0.0000000000000000e+00 , 10) +ok 14 - convertToDecimalString(ieee754(8000000000000000) = -0.0000000000000000e+00 , 10) +ok 15 - convertToHexString (ieee754(8000000000000000) = -0.0000000000000000e+00 , 13) +ok 16 - convertToDecimalString(ieee754(8000000000000000) = -0.0000000000000000e+00 , 13) +ok 17 - convertToHexString (ieee754(0000000000000001) = +4.9406564584124654e-324) +ok 18 - convertToDecimalString(ieee754(0000000000000001) = +4.9406564584124654e-324) +ok 19 - convertToHexString (ieee754(0000000000000001) = +4.9406564584124654e-324, ) +ok 20 - convertToDecimalString(ieee754(0000000000000001) = +4.9406564584124654e-324, ) +ok 21 - convertToHexString (ieee754(0000000000000001) = +4.9406564584124654e-324, 3) +ok 22 - convertToDecimalString(ieee754(0000000000000001) = +4.9406564584124654e-324, 3) +ok 23 - convertToHexString (ieee754(0000000000000001) = +4.9406564584124654e-324, 10) +ok 24 - convertToDecimalString(ieee754(0000000000000001) = +4.9406564584124654e-324, 10) +ok 25 - convertToHexString (ieee754(0000000000000001) = +4.9406564584124654e-324, 13) +ok 26 - convertToDecimalString(ieee754(0000000000000001) = +4.9406564584124654e-324, 13) +ok 27 - convertToHexString (ieee754(8000000000000001) = -4.9406564584124654e-324) +ok 28 - convertToDecimalString(ieee754(8000000000000001) = -4.9406564584124654e-324) +ok 29 - convertToHexString (ieee754(8000000000000001) = -4.9406564584124654e-324, ) +ok 30 - convertToDecimalString(ieee754(8000000000000001) = -4.9406564584124654e-324, ) +ok 31 - convertToHexString (ieee754(8000000000000001) = -4.9406564584124654e-324, 3) +ok 32 - convertToDecimalString(ieee754(8000000000000001) = -4.9406564584124654e-324, 3) +ok 33 - convertToHexString (ieee754(8000000000000001) = -4.9406564584124654e-324, 10) +ok 34 - convertToDecimalString(ieee754(8000000000000001) = -4.9406564584124654e-324, 10) +ok 35 - convertToHexString (ieee754(8000000000000001) = -4.9406564584124654e-324, 13) +ok 36 - convertToDecimalString(ieee754(8000000000000001) = -4.9406564584124654e-324, 13) +ok 37 - convertToHexString (ieee754(000FFFFFFFFFFFFF) = +2.2250738585072009e-308) +ok 38 - convertToDecimalString(ieee754(000FFFFFFFFFFFFF) = +2.2250738585072009e-308) +ok 39 - convertToHexString (ieee754(000FFFFFFFFFFFFF) = +2.2250738585072009e-308, ) +ok 40 - convertToDecimalString(ieee754(000FFFFFFFFFFFFF) = +2.2250738585072009e-308, ) +ok 41 - convertToHexString (ieee754(000FFFFFFFFFFFFF) = +2.2250738585072009e-308, 3) +ok 42 - convertToDecimalString(ieee754(000FFFFFFFFFFFFF) = +2.2250738585072009e-308, 3) +not ok 43 - convertToHexString (ieee754(000FFFFFFFFFFFFF) = +2.2250738585072009e-308, 10) +# Failed test 'convertToHexString (ieee754(000FFFFFFFFFFFFF) = +2.2250738585072009e-308, 10)' +# at t/02-converttostr.t line 21. +# '+0x0.ffffffffffp-1022' +# doesn't match '(?-xism:\+0x1\.0000000000p\-1022)' +ok 44 - convertToDecimalString(ieee754(000FFFFFFFFFFFFF) = +2.2250738585072009e-308, 10) +ok 45 - convertToHexString (ieee754(000FFFFFFFFFFFFF) = +2.2250738585072009e-308, 13) +ok 46 - convertToDecimalString(ieee754(000FFFFFFFFFFFFF) = +2.2250738585072009e-308, 13) +ok 47 - convertToHexString (ieee754(800FFFFFFFFFFFFF) = -2.2250738585072009e-308) +ok 48 - convertToDecimalString(ieee754(800FFFFFFFFFFFFF) = -2.2250738585072009e-308) +ok 49 - convertToHexString (ieee754(800FFFFFFFFFFFFF) = -2.2250738585072009e-308, ) +ok 50 - convertToDecimalString(ieee754(800FFFFFFFFFFFFF) = -2.2250738585072009e-308, ) +ok 51 - convertToHexString (ieee754(800FFFFFFFFFFFFF) = -2.2250738585072009e-308, 3) +ok 52 - convertToDecimalString(ieee754(800FFFFFFFFFFFFF) = -2.2250738585072009e-308, 3) +not ok 53 - convertToHexString (ieee754(800FFFFFFFFFFFFF) = -2.2250738585072009e-308, 10) +# Failed test 'convertToHexString (ieee754(800FFFFFFFFFFFFF) = -2.2250738585072009e-308, 10)' +# at t/02-converttostr.t line 21. +# '-0x0.ffffffffffp-1022' +# doesn't match '(?-xism:\-0x1\.0000000000p\-1022)' +ok 54 - convertToDecimalString(ieee754(800FFFFFFFFFFFFF) = -2.2250738585072009e-308, 10) +ok 55 - convertToHexString (ieee754(800FFFFFFFFFFFFF) = -2.2250738585072009e-308, 13) +ok 56 - convertToDecimalString(ieee754(800FFFFFFFFFFFFF) = -2.2250738585072009e-308, 13) +ok 57 - convertToHexString (ieee754(0010000000000000) = +2.2250738585072014e-308) +ok 58 - convertToDecimalString(ieee754(0010000000000000) = +2.2250738585072014e-308) +ok 59 - convertToHexString (ieee754(0010000000000000) = +2.2250738585072014e-308, ) +ok 60 - convertToDecimalString(ieee754(0010000000000000) = +2.2250738585072014e-308, ) +ok 61 - convertToHexString (ieee754(0010000000000000) = +2.2250738585072014e-308, 10) +ok 62 - convertToDecimalString(ieee754(0010000000000000) = +2.2250738585072014e-308, 10) +ok 63 - convertToHexString (ieee754(0010000000000000) = +2.2250738585072014e-308, 13) +ok 64 - convertToDecimalString(ieee754(0010000000000000) = +2.2250738585072014e-308, 13) +ok 65 - convertToHexString (ieee754(8010000000000000) = -2.2250738585072014e-308) +ok 66 - convertToDecimalString(ieee754(8010000000000000) = -2.2250738585072014e-308) +ok 67 - convertToHexString (ieee754(8010000000000000) = -2.2250738585072014e-308, ) +ok 68 - convertToDecimalString(ieee754(8010000000000000) = -2.2250738585072014e-308, ) +ok 69 - convertToHexString (ieee754(8010000000000000) = -2.2250738585072014e-308, 10) +ok 70 - convertToDecimalString(ieee754(8010000000000000) = -2.2250738585072014e-308, 10) +ok 71 - convertToHexString (ieee754(8010000000000000) = -2.2250738585072014e-308, 13) +ok 72 - convertToDecimalString(ieee754(8010000000000000) = -2.2250738585072014e-308, 13) +ok 73 - convertToHexString (ieee754(0010000000000001) = +2.2250738585072019e-308) +ok 74 - convertToDecimalString(ieee754(0010000000000001) = +2.2250738585072019e-308) +ok 75 - convertToHexString (ieee754(0010000000000001) = +2.2250738585072019e-308, ) +ok 76 - convertToDecimalString(ieee754(0010000000000001) = +2.2250738585072019e-308, ) +ok 77 - convertToHexString (ieee754(0010000000000001) = +2.2250738585072019e-308, 10) +ok 78 - convertToDecimalString(ieee754(0010000000000001) = +2.2250738585072019e-308, 10) +ok 79 - convertToHexString (ieee754(0010000000000001) = +2.2250738585072019e-308, 13) +ok 80 - convertToDecimalString(ieee754(0010000000000001) = +2.2250738585072019e-308, 13) +ok 81 - convertToHexString (ieee754(8010000000000001) = -2.2250738585072019e-308) +ok 82 - convertToDecimalString(ieee754(8010000000000001) = -2.2250738585072019e-308) +ok 83 - convertToHexString (ieee754(8010000000000001) = -2.2250738585072019e-308, ) +ok 84 - convertToDecimalString(ieee754(8010000000000001) = -2.2250738585072019e-308, ) +ok 85 - convertToHexString (ieee754(8010000000000001) = -2.2250738585072019e-308, 10) +ok 86 - convertToDecimalString(ieee754(8010000000000001) = -2.2250738585072019e-308, 10) +ok 87 - convertToHexString (ieee754(8010000000000001) = -2.2250738585072019e-308, 13) +ok 88 - convertToDecimalString(ieee754(8010000000000001) = -2.2250738585072019e-308, 13) +ok 89 - convertToHexString (ieee754(001FFFFFFFFFFFFF) = +4.4501477170144023e-308) +ok 90 - convertToDecimalString(ieee754(001FFFFFFFFFFFFF) = +4.4501477170144023e-308) +ok 91 - convertToHexString (ieee754(001FFFFFFFFFFFFF) = +4.4501477170144023e-308, ) +ok 92 - convertToDecimalString(ieee754(001FFFFFFFFFFFFF) = +4.4501477170144023e-308, ) +not ok 93 - convertToHexString (ieee754(001FFFFFFFFFFFFF) = +4.4501477170144023e-308, 10) +# Failed test 'convertToHexString (ieee754(001FFFFFFFFFFFFF) = +4.4501477170144023e-308, 10)' +# at t/02-converttostr.t line 21. +# '+0x1.ffffffffffp-1022' +# doesn't match '(?-xism:\+0x2\.0000000000p\-1022)' +ok 94 - convertToDecimalString(ieee754(001FFFFFFFFFFFFF) = +4.4501477170144023e-308, 10) +ok 95 - convertToHexString (ieee754(001FFFFFFFFFFFFF) = +4.4501477170144023e-308, 13) +ok 96 - convertToDecimalString(ieee754(001FFFFFFFFFFFFF) = +4.4501477170144023e-308, 13) +ok 97 - convertToHexString (ieee754(801FFFFFFFFFFFFF) = -4.4501477170144023e-308) +ok 98 - convertToDecimalString(ieee754(801FFFFFFFFFFFFF) = -4.4501477170144023e-308) +ok 99 - convertToHexString (ieee754(801FFFFFFFFFFFFF) = -4.4501477170144023e-308, ) +ok 100 - convertToDecimalString(ieee754(801FFFFFFFFFFFFF) = -4.4501477170144023e-308, ) +not ok 101 - convertToHexString (ieee754(801FFFFFFFFFFFFF) = -4.4501477170144023e-308, 10) +# Failed test 'convertToHexString (ieee754(801FFFFFFFFFFFFF) = -4.4501477170144023e-308, 10)' +# at t/02-converttostr.t line 21. +# '-0x1.ffffffffffp-1022' +# doesn't match '(?-xism:\-0x2\.0000000000p\-1022)' +ok 102 - convertToDecimalString(ieee754(801FFFFFFFFFFFFF) = -4.4501477170144023e-308, 10) +ok 103 - convertToHexString (ieee754(801FFFFFFFFFFFFF) = -4.4501477170144023e-308, 13) +ok 104 - convertToDecimalString(ieee754(801FFFFFFFFFFFFF) = -4.4501477170144023e-308, 13) +ok 105 - convertToHexString (ieee754(3FF0000000000000) = +1.0000000000000000e+00 ) +ok 106 - convertToDecimalString(ieee754(3FF0000000000000) = +1.0000000000000000e+00 ) +ok 107 - convertToHexString (ieee754(3FF0000000000000) = +1.0000000000000000e+00 , ) +ok 108 - convertToDecimalString(ieee754(3FF0000000000000) = +1.0000000000000000e+00 , ) +ok 109 - convertToHexString (ieee754(3FF0000000000000) = +1.0000000000000000e+00 , 10) +ok 110 - convertToDecimalString(ieee754(3FF0000000000000) = +1.0000000000000000e+00 , 10) +ok 111 - convertToHexString (ieee754(3FF0000000000000) = +1.0000000000000000e+00 , 13) +ok 112 - convertToDecimalString(ieee754(3FF0000000000000) = +1.0000000000000000e+00 , 13) +ok 113 - convertToHexString (ieee754(BFF0000000000000) = -1.0000000000000000e+00 ) +ok 114 - convertToDecimalString(ieee754(BFF0000000000000) = -1.0000000000000000e+00 ) +ok 115 - convertToHexString (ieee754(BFF0000000000000) = -1.0000000000000000e+00 , ) +ok 116 - convertToDecimalString(ieee754(BFF0000000000000) = -1.0000000000000000e+00 , ) +ok 117 - convertToHexString (ieee754(BFF0000000000000) = -1.0000000000000000e+00 , 10) +ok 118 - convertToDecimalString(ieee754(BFF0000000000000) = -1.0000000000000000e+00 , 10) +ok 119 - convertToHexString (ieee754(BFF0000000000000) = -1.0000000000000000e+00 , 13) +ok 120 - convertToDecimalString(ieee754(BFF0000000000000) = -1.0000000000000000e+00 , 13) +ok 121 - convertToHexString (ieee754(3FF0000000000001) = +1.0000000000000002e+00 ) +ok 122 - convertToDecimalString(ieee754(3FF0000000000001) = +1.0000000000000002e+00 ) +ok 123 - convertToHexString (ieee754(3FF0000000000001) = +1.0000000000000002e+00 , ) +# + +# __0428__ binary64_convertToHexString() +# __0429__ nvsize = 8 +# __0429__ ivsize = 4 +# __0429__ doublesize = 8 +# __0429__ intsize = 4 +# __0429__ longsize = 4 +# __0429__ ptrsize = 4 +# __0437__ [msb][lsb] = 0x3ff00000 00000001 => digits=13 +# __0438__ ... = + ? . 0000000000001 pwr 0 +# __0447__ ... = + 1 . 0000000000001 pwr 0 +# __0452__ ... = + 1 . 0000000000001 pwr 0 +# __0522__ +0x1.0000000000001p+0000 +# __0031__ /exited DEBUG:convertToHexString(ieee754(3FF0000000000001) = +1.0000000000000002e+00 , ) = "+0x1.0000000000001p+0000" +# +ok 124 - convertToDecimalString(ieee754(3FF0000000000001) = +1.0000000000000002e+00 , ) +ok 125 - convertToHexString (ieee754(3FF0000000000001) = +1.0000000000000002e+00 , 10) +# + +# __0428__ binary64_convertToHexString() +# __0429__ nvsize = 8 +# __0429__ ivsize = 4 +# __0429__ doublesize = 8 +# __0429__ intsize = 4 +# __0429__ longsize = 4 +# __0429__ ptrsize = 4 +# __0437__ [msb][lsb] = 0x3ff00000 00000001 => digits=10 +# __0438__ ... = + ? . 0000000000001 pwr 0 +# __0447__ ... = + 1 . 0000000000001 pwr 0 +# __0452__ ... = + 1 . 0000000000001 pwr 0 +# __0457__ ... = + 1 . left(00000_00000001, digits:10) pwr 0 +# __0422__ __0459__ Devel::Peek::Dump(l = 0x00000001 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,pIOK) +# # IV = 1 +# # NV = 0 +# # PV = 0 +# __0422__ __0461__ Devel::Peek::Dump(one = 0x00001000 or 4.0960000000000000e+03 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK) +# # IV = 4096 +# # NV = 4096 +# # PV = 0 +# __0422__ __0463__ Devel::Peek::Dump(haf = 0x00000800 or 2.0480000000000000e+03 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK) +# # IV = 2048 +# # NV = 2048 +# # PV = 0 +# __0422__ __0465__ Devel::Peek::Dump(eff = 0x00000fff or 4.0950000000000000e+03 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK) +# # IV = 4095 +# # NV = 4095 +# # PV = 0 +# __0467__ ... = (l:0x00000001 & eff:0x00000fff = and:0x00000001) vs (haf:0x00000800): < +# __0483__ ... = + 1 . left(00000_00000000, digits:10) pwr 0 +# __0516__ ... = + 1 . left(00000_00000000, digits:10) pwr 0 +# __0519__ +0x1.0000000000p+0000 +# __0031__ /exited DEBUG:convertToHexString(ieee754(3FF0000000000001) = +1.0000000000000002e+00 , 10) = "+0x1.0000000000p+0000" +# +ok 126 - convertToDecimalString(ieee754(3FF0000000000001) = +1.0000000000000002e+00 , 10) +ok 127 - convertToHexString (ieee754(3FF0000000000001) = +1.0000000000000002e+00 , 13) +# + +# __0428__ binary64_convertToHexString() +# __0429__ nvsize = 8 +# __0429__ ivsize = 4 +# __0429__ doublesize = 8 +# __0429__ intsize = 4 +# __0429__ longsize = 4 +# __0429__ ptrsize = 4 +# __0437__ [msb][lsb] = 0x3ff00000 00000001 => digits=13 +# __0438__ ... = + ? . 0000000000001 pwr 0 +# __0447__ ... = + 1 . 0000000000001 pwr 0 +# __0452__ ... = + 1 . 0000000000001 pwr 0 +# __0522__ +0x1.0000000000001p+0000 +# __0031__ /exited DEBUG:convertToHexString(ieee754(3FF0000000000001) = +1.0000000000000002e+00 , 13) = "+0x1.0000000000001p+0000" +# +ok 128 - convertToDecimalString(ieee754(3FF0000000000001) = +1.0000000000000002e+00 , 13) +ok 129 - convertToHexString (ieee754(BFF0000000000001) = -1.0000000000000002e+00 ) +ok 130 - convertToDecimalString(ieee754(BFF0000000000001) = -1.0000000000000002e+00 ) +ok 131 - convertToHexString (ieee754(BFF0000000000001) = -1.0000000000000002e+00 , ) +ok 132 - convertToDecimalString(ieee754(BFF0000000000001) = -1.0000000000000002e+00 , ) +ok 133 - convertToHexString (ieee754(BFF0000000000001) = -1.0000000000000002e+00 , 10) +ok 134 - convertToDecimalString(ieee754(BFF0000000000001) = -1.0000000000000002e+00 , 10) +ok 135 - convertToHexString (ieee754(BFF0000000000001) = -1.0000000000000002e+00 , 13) +ok 136 - convertToDecimalString(ieee754(BFF0000000000001) = -1.0000000000000002e+00 , 13) +ok 137 - convertToHexString (ieee754(3FF0000000000008) = +1.0000000000000018e+00 ) +ok 138 - convertToDecimalString(ieee754(3FF0000000000008) = +1.0000000000000018e+00 ) +ok 139 - convertToHexString (ieee754(3FF0000000000008) = +1.0000000000000018e+00 , ) +ok 140 - convertToDecimalString(ieee754(3FF0000000000008) = +1.0000000000000018e+00 , ) +ok 141 - convertToHexString (ieee754(3FF0000000000008) = +1.0000000000000018e+00 , 10) +ok 142 - convertToDecimalString(ieee754(3FF0000000000008) = +1.0000000000000018e+00 , 10) +ok 143 - convertToHexString (ieee754(3FF0000000000008) = +1.0000000000000018e+00 , 13) +ok 144 - convertToDecimalString(ieee754(3FF0000000000008) = +1.0000000000000018e+00 , 13) +ok 145 - convertToHexString (ieee754(BFF0000000000008) = -1.0000000000000018e+00 ) +ok 146 - convertToDecimalString(ieee754(BFF0000000000008) = -1.0000000000000018e+00 ) +ok 147 - convertToHexString (ieee754(BFF0000000000008) = -1.0000000000000018e+00 , ) +ok 148 - convertToDecimalString(ieee754(BFF0000000000008) = -1.0000000000000018e+00 , ) +ok 149 - convertToHexString (ieee754(BFF0000000000008) = -1.0000000000000018e+00 , 10) +ok 150 - convertToDecimalString(ieee754(BFF0000000000008) = -1.0000000000000018e+00 , 10) +ok 151 - convertToHexString (ieee754(BFF0000000000008) = -1.0000000000000018e+00 , 13) +ok 152 - convertToDecimalString(ieee754(BFF0000000000008) = -1.0000000000000018e+00 , 13) +ok 153 - convertToHexString (ieee754(3FF0000000000080) = +1.0000000000000284e+00 ) +ok 154 - convertToDecimalString(ieee754(3FF0000000000080) = +1.0000000000000284e+00 ) +ok 155 - convertToHexString (ieee754(3FF0000000000080) = +1.0000000000000284e+00 , ) +ok 156 - convertToDecimalString(ieee754(3FF0000000000080) = +1.0000000000000284e+00 , ) +ok 157 - convertToHexString (ieee754(3FF0000000000080) = +1.0000000000000284e+00 , 10) +ok 158 - convertToDecimalString(ieee754(3FF0000000000080) = +1.0000000000000284e+00 , 10) +ok 159 - convertToHexString (ieee754(3FF0000000000080) = +1.0000000000000284e+00 , 13) +ok 160 - convertToDecimalString(ieee754(3FF0000000000080) = +1.0000000000000284e+00 , 13) +ok 161 - convertToHexString (ieee754(BFF0000000000080) = -1.0000000000000284e+00 ) +ok 162 - convertToDecimalString(ieee754(BFF0000000000080) = -1.0000000000000284e+00 ) +ok 163 - convertToHexString (ieee754(BFF0000000000080) = -1.0000000000000284e+00 , ) +ok 164 - convertToDecimalString(ieee754(BFF0000000000080) = -1.0000000000000284e+00 , ) +ok 165 - convertToHexString (ieee754(BFF0000000000080) = -1.0000000000000284e+00 , 10) +ok 166 - convertToDecimalString(ieee754(BFF0000000000080) = -1.0000000000000284e+00 , 10) +ok 167 - convertToHexString (ieee754(BFF0000000000080) = -1.0000000000000284e+00 , 13) +ok 168 - convertToDecimalString(ieee754(BFF0000000000080) = -1.0000000000000284e+00 , 13) +ok 169 - convertToHexString (ieee754(3FF0000000000800) = +1.0000000000004547e+00 ) +ok 170 - convertToDecimalString(ieee754(3FF0000000000800) = +1.0000000000004547e+00 ) +ok 171 - convertToHexString (ieee754(3FF0000000000800) = +1.0000000000004547e+00 , ) +ok 172 - convertToDecimalString(ieee754(3FF0000000000800) = +1.0000000000004547e+00 , ) +ok 173 - convertToHexString (ieee754(3FF0000000000800) = +1.0000000000004547e+00 , 10) +ok 174 - convertToDecimalString(ieee754(3FF0000000000800) = +1.0000000000004547e+00 , 10) +ok 175 - convertToHexString (ieee754(3FF0000000000800) = +1.0000000000004547e+00 , 13) +ok 176 - convertToDecimalString(ieee754(3FF0000000000800) = +1.0000000000004547e+00 , 13) +ok 177 - convertToHexString (ieee754(BFF0000000000800) = -1.0000000000004547e+00 ) +ok 178 - convertToDecimalString(ieee754(BFF0000000000800) = -1.0000000000004547e+00 ) +ok 179 - convertToHexString (ieee754(BFF0000000000800) = -1.0000000000004547e+00 , ) +ok 180 - convertToDecimalString(ieee754(BFF0000000000800) = -1.0000000000004547e+00 , ) +ok 181 - convertToHexString (ieee754(BFF0000000000800) = -1.0000000000004547e+00 , 10) +ok 182 - convertToDecimalString(ieee754(BFF0000000000800) = -1.0000000000004547e+00 , 10) +ok 183 - convertToHexString (ieee754(BFF0000000000800) = -1.0000000000004547e+00 , 13) +ok 184 - convertToDecimalString(ieee754(BFF0000000000800) = -1.0000000000004547e+00 , 13) +ok 185 - convertToHexString (ieee754(3FF0000000008000) = +1.0000000000072760e+00 ) +ok 186 - convertToDecimalString(ieee754(3FF0000000008000) = +1.0000000000072760e+00 ) +ok 187 - convertToHexString (ieee754(3FF0000000008000) = +1.0000000000072760e+00 , ) +ok 188 - convertToDecimalString(ieee754(3FF0000000008000) = +1.0000000000072760e+00 , ) +ok 189 - convertToHexString (ieee754(3FF0000000008000) = +1.0000000000072760e+00 , 10) +ok 190 - convertToDecimalString(ieee754(3FF0000000008000) = +1.0000000000072760e+00 , 10) +ok 191 - convertToHexString (ieee754(3FF0000000008000) = +1.0000000000072760e+00 , 13) +ok 192 - convertToDecimalString(ieee754(3FF0000000008000) = +1.0000000000072760e+00 , 13) +ok 193 - convertToHexString (ieee754(BFF0000000008000) = -1.0000000000072760e+00 ) +ok 194 - convertToDecimalString(ieee754(BFF0000000008000) = -1.0000000000072760e+00 ) +ok 195 - convertToHexString (ieee754(BFF0000000008000) = -1.0000000000072760e+00 , ) +ok 196 - convertToDecimalString(ieee754(BFF0000000008000) = -1.0000000000072760e+00 , ) +ok 197 - convertToHexString (ieee754(BFF0000000008000) = -1.0000000000072760e+00 , 10) +ok 198 - convertToDecimalString(ieee754(BFF0000000008000) = -1.0000000000072760e+00 , 10) +ok 199 - convertToHexString (ieee754(BFF0000000008000) = -1.0000000000072760e+00 , 13) +ok 200 - convertToDecimalString(ieee754(BFF0000000008000) = -1.0000000000072760e+00 , 13) +ok 201 - convertToHexString (ieee754(3FF0000000080000) = +1.0000000001164153e+00 ) +ok 202 - convertToDecimalString(ieee754(3FF0000000080000) = +1.0000000001164153e+00 ) +ok 203 - convertToHexString (ieee754(3FF0000000080000) = +1.0000000001164153e+00 , ) +ok 204 - convertToDecimalString(ieee754(3FF0000000080000) = +1.0000000001164153e+00 , ) +ok 205 - convertToHexString (ieee754(3FF0000000080000) = +1.0000000001164153e+00 , 10) +ok 206 - convertToDecimalString(ieee754(3FF0000000080000) = +1.0000000001164153e+00 , 10) +ok 207 - convertToHexString (ieee754(3FF0000000080000) = +1.0000000001164153e+00 , 13) +ok 208 - convertToDecimalString(ieee754(3FF0000000080000) = +1.0000000001164153e+00 , 13) +ok 209 - convertToHexString (ieee754(BFF0000000080000) = -1.0000000001164153e+00 ) +ok 210 - convertToDecimalString(ieee754(BFF0000000080000) = -1.0000000001164153e+00 ) +ok 211 - convertToHexString (ieee754(BFF0000000080000) = -1.0000000001164153e+00 , ) +ok 212 - convertToDecimalString(ieee754(BFF0000000080000) = -1.0000000001164153e+00 , ) +ok 213 - convertToHexString (ieee754(BFF0000000080000) = -1.0000000001164153e+00 , 10) +ok 214 - convertToDecimalString(ieee754(BFF0000000080000) = -1.0000000001164153e+00 , 10) +ok 215 - convertToHexString (ieee754(BFF0000000080000) = -1.0000000001164153e+00 , 13) +ok 216 - convertToDecimalString(ieee754(BFF0000000080000) = -1.0000000001164153e+00 , 13) +ok 217 - convertToHexString (ieee754(3FF0000000800000) = +1.0000000018626451e+00 ) +ok 218 - convertToDecimalString(ieee754(3FF0000000800000) = +1.0000000018626451e+00 ) +ok 219 - convertToHexString (ieee754(3FF0000000800000) = +1.0000000018626451e+00 , ) +ok 220 - convertToDecimalString(ieee754(3FF0000000800000) = +1.0000000018626451e+00 , ) +ok 221 - convertToHexString (ieee754(3FF0000000800000) = +1.0000000018626451e+00 , 10) +ok 222 - convertToDecimalString(ieee754(3FF0000000800000) = +1.0000000018626451e+00 , 10) +ok 223 - convertToHexString (ieee754(3FF0000000800000) = +1.0000000018626451e+00 , 13) +ok 224 - convertToDecimalString(ieee754(3FF0000000800000) = +1.0000000018626451e+00 , 13) +ok 225 - convertToHexString (ieee754(BFF0000000800000) = -1.0000000018626451e+00 ) +ok 226 - convertToDecimalString(ieee754(BFF0000000800000) = -1.0000000018626451e+00 ) +ok 227 - convertToHexString (ieee754(BFF0000000800000) = -1.0000000018626451e+00 , ) +ok 228 - convertToDecimalString(ieee754(BFF0000000800000) = -1.0000000018626451e+00 , ) +ok 229 - convertToHexString (ieee754(BFF0000000800000) = -1.0000000018626451e+00 , 10) +ok 230 - convertToDecimalString(ieee754(BFF0000000800000) = -1.0000000018626451e+00 , 10) +ok 231 - convertToHexString (ieee754(BFF0000000800000) = -1.0000000018626451e+00 , 13) +ok 232 - convertToDecimalString(ieee754(BFF0000000800000) = -1.0000000018626451e+00 , 13) +ok 233 - convertToHexString (ieee754(3FF0000008000000) = +1.0000000298023224e+00 ) +ok 234 - convertToDecimalString(ieee754(3FF0000008000000) = +1.0000000298023224e+00 ) +ok 235 - convertToHexString (ieee754(3FF0000008000000) = +1.0000000298023224e+00 , ) +ok 236 - convertToDecimalString(ieee754(3FF0000008000000) = +1.0000000298023224e+00 , ) +ok 237 - convertToHexString (ieee754(3FF0000008000000) = +1.0000000298023224e+00 , 10) +ok 238 - convertToDecimalString(ieee754(3FF0000008000000) = +1.0000000298023224e+00 , 10) +ok 239 - convertToHexString (ieee754(3FF0000008000000) = +1.0000000298023224e+00 , 13) +ok 240 - convertToDecimalString(ieee754(3FF0000008000000) = +1.0000000298023224e+00 , 13) +ok 241 - convertToHexString (ieee754(BFF0000008000000) = -1.0000000298023224e+00 ) +ok 242 - convertToDecimalString(ieee754(BFF0000008000000) = -1.0000000298023224e+00 ) +ok 243 - convertToHexString (ieee754(BFF0000008000000) = -1.0000000298023224e+00 , ) +ok 244 - convertToDecimalString(ieee754(BFF0000008000000) = -1.0000000298023224e+00 , ) +ok 245 - convertToHexString (ieee754(BFF0000008000000) = -1.0000000298023224e+00 , 10) +ok 246 - convertToDecimalString(ieee754(BFF0000008000000) = -1.0000000298023224e+00 , 10) +ok 247 - convertToHexString (ieee754(BFF0000008000000) = -1.0000000298023224e+00 , 13) +ok 248 - convertToDecimalString(ieee754(BFF0000008000000) = -1.0000000298023224e+00 , 13) +ok 249 - convertToHexString (ieee754(3FF0000080000000) = +1.0000004768371582e+00 ) +ok 250 - convertToDecimalString(ieee754(3FF0000080000000) = +1.0000004768371582e+00 ) +ok 251 - convertToHexString (ieee754(3FF0000080000000) = +1.0000004768371582e+00 , ) +ok 252 - convertToDecimalString(ieee754(3FF0000080000000) = +1.0000004768371582e+00 , ) +ok 253 - convertToHexString (ieee754(3FF0000080000000) = +1.0000004768371582e+00 , 10) +ok 254 - convertToDecimalString(ieee754(3FF0000080000000) = +1.0000004768371582e+00 , 10) +ok 255 - convertToHexString (ieee754(3FF0000080000000) = +1.0000004768371582e+00 , 13) +ok 256 - convertToDecimalString(ieee754(3FF0000080000000) = +1.0000004768371582e+00 , 13) +ok 257 - convertToHexString (ieee754(BFF0000080000000) = -1.0000004768371582e+00 ) +ok 258 - convertToDecimalString(ieee754(BFF0000080000000) = -1.0000004768371582e+00 ) +ok 259 - convertToHexString (ieee754(BFF0000080000000) = -1.0000004768371582e+00 , ) +ok 260 - convertToDecimalString(ieee754(BFF0000080000000) = -1.0000004768371582e+00 , ) +ok 261 - convertToHexString (ieee754(BFF0000080000000) = -1.0000004768371582e+00 , 10) +ok 262 - convertToDecimalString(ieee754(BFF0000080000000) = -1.0000004768371582e+00 , 10) +ok 263 - convertToHexString (ieee754(BFF0000080000000) = -1.0000004768371582e+00 , 13) +ok 264 - convertToDecimalString(ieee754(BFF0000080000000) = -1.0000004768371582e+00 , 13) +ok 265 - convertToHexString (ieee754(3FF0000800000000) = +1.0000076293945312e+00 ) +ok 266 - convertToDecimalString(ieee754(3FF0000800000000) = +1.0000076293945312e+00 ) +ok 267 - convertToHexString (ieee754(3FF0000800000000) = +1.0000076293945312e+00 , ) +ok 268 - convertToDecimalString(ieee754(3FF0000800000000) = +1.0000076293945312e+00 , ) +ok 269 - convertToHexString (ieee754(3FF0000800000000) = +1.0000076293945312e+00 , 10) +ok 270 - convertToDecimalString(ieee754(3FF0000800000000) = +1.0000076293945312e+00 , 10) +ok 271 - convertToHexString (ieee754(3FF0000800000000) = +1.0000076293945312e+00 , 13) +ok 272 - convertToDecimalString(ieee754(3FF0000800000000) = +1.0000076293945312e+00 , 13) +ok 273 - convertToHexString (ieee754(BFF0000800000000) = -1.0000076293945312e+00 ) +ok 274 - convertToDecimalString(ieee754(BFF0000800000000) = -1.0000076293945312e+00 ) +ok 275 - convertToHexString (ieee754(BFF0000800000000) = -1.0000076293945312e+00 , ) +ok 276 - convertToDecimalString(ieee754(BFF0000800000000) = -1.0000076293945312e+00 , ) +ok 277 - convertToHexString (ieee754(BFF0000800000000) = -1.0000076293945312e+00 , 10) +ok 278 - convertToDecimalString(ieee754(BFF0000800000000) = -1.0000076293945312e+00 , 10) +ok 279 - convertToHexString (ieee754(BFF0000800000000) = -1.0000076293945312e+00 , 13) +ok 280 - convertToDecimalString(ieee754(BFF0000800000000) = -1.0000076293945312e+00 , 13) +ok 281 - convertToHexString (ieee754(3FF0008000000000) = +1.0001220703125000e+00 ) +ok 282 - convertToDecimalString(ieee754(3FF0008000000000) = +1.0001220703125000e+00 ) +ok 283 - convertToHexString (ieee754(3FF0008000000000) = +1.0001220703125000e+00 , ) +ok 284 - convertToDecimalString(ieee754(3FF0008000000000) = +1.0001220703125000e+00 , ) +ok 285 - convertToHexString (ieee754(3FF0008000000000) = +1.0001220703125000e+00 , 10) +ok 286 - convertToDecimalString(ieee754(3FF0008000000000) = +1.0001220703125000e+00 , 10) +ok 287 - convertToHexString (ieee754(3FF0008000000000) = +1.0001220703125000e+00 , 13) +ok 288 - convertToDecimalString(ieee754(3FF0008000000000) = +1.0001220703125000e+00 , 13) +ok 289 - convertToHexString (ieee754(BFF0008000000000) = -1.0001220703125000e+00 ) +ok 290 - convertToDecimalString(ieee754(BFF0008000000000) = -1.0001220703125000e+00 ) +ok 291 - convertToHexString (ieee754(BFF0008000000000) = -1.0001220703125000e+00 , ) +ok 292 - convertToDecimalString(ieee754(BFF0008000000000) = -1.0001220703125000e+00 , ) +ok 293 - convertToHexString (ieee754(BFF0008000000000) = -1.0001220703125000e+00 , 10) +ok 294 - convertToDecimalString(ieee754(BFF0008000000000) = -1.0001220703125000e+00 , 10) +ok 295 - convertToHexString (ieee754(BFF0008000000000) = -1.0001220703125000e+00 , 13) +ok 296 - convertToDecimalString(ieee754(BFF0008000000000) = -1.0001220703125000e+00 , 13) +ok 297 - convertToHexString (ieee754(3FF0080000000000) = +1.0019531250000000e+00 ) +ok 298 - convertToDecimalString(ieee754(3FF0080000000000) = +1.0019531250000000e+00 ) +ok 299 - convertToHexString (ieee754(3FF0080000000000) = +1.0019531250000000e+00 , ) +ok 300 - convertToDecimalString(ieee754(3FF0080000000000) = +1.0019531250000000e+00 , ) +ok 301 - convertToHexString (ieee754(3FF0080000000000) = +1.0019531250000000e+00 , 10) +ok 302 - convertToDecimalString(ieee754(3FF0080000000000) = +1.0019531250000000e+00 , 10) +ok 303 - convertToHexString (ieee754(3FF0080000000000) = +1.0019531250000000e+00 , 13) +ok 304 - convertToDecimalString(ieee754(3FF0080000000000) = +1.0019531250000000e+00 , 13) +ok 305 - convertToHexString (ieee754(BFF0080000000000) = -1.0019531250000000e+00 ) +ok 306 - convertToDecimalString(ieee754(BFF0080000000000) = -1.0019531250000000e+00 ) +ok 307 - convertToHexString (ieee754(BFF0080000000000) = -1.0019531250000000e+00 , ) +ok 308 - convertToDecimalString(ieee754(BFF0080000000000) = -1.0019531250000000e+00 , ) +ok 309 - convertToHexString (ieee754(BFF0080000000000) = -1.0019531250000000e+00 , 10) +ok 310 - convertToDecimalString(ieee754(BFF0080000000000) = -1.0019531250000000e+00 , 10) +ok 311 - convertToHexString (ieee754(BFF0080000000000) = -1.0019531250000000e+00 , 13) +ok 312 - convertToDecimalString(ieee754(BFF0080000000000) = -1.0019531250000000e+00 , 13) +ok 313 - convertToHexString (ieee754(3FF0800000000000) = +1.0312500000000000e+00 ) +ok 314 - convertToDecimalString(ieee754(3FF0800000000000) = +1.0312500000000000e+00 ) +ok 315 - convertToHexString (ieee754(3FF0800000000000) = +1.0312500000000000e+00 , ) +ok 316 - convertToDecimalString(ieee754(3FF0800000000000) = +1.0312500000000000e+00 , ) +ok 317 - convertToHexString (ieee754(3FF0800000000000) = +1.0312500000000000e+00 , 10) +ok 318 - convertToDecimalString(ieee754(3FF0800000000000) = +1.0312500000000000e+00 , 10) +ok 319 - convertToHexString (ieee754(3FF0800000000000) = +1.0312500000000000e+00 , 13) +ok 320 - convertToDecimalString(ieee754(3FF0800000000000) = +1.0312500000000000e+00 , 13) +ok 321 - convertToHexString (ieee754(BFF0800000000000) = -1.0312500000000000e+00 ) +ok 322 - convertToDecimalString(ieee754(BFF0800000000000) = -1.0312500000000000e+00 ) +ok 323 - convertToHexString (ieee754(BFF0800000000000) = -1.0312500000000000e+00 , ) +ok 324 - convertToDecimalString(ieee754(BFF0800000000000) = -1.0312500000000000e+00 , ) +ok 325 - convertToHexString (ieee754(BFF0800000000000) = -1.0312500000000000e+00 , 10) +ok 326 - convertToDecimalString(ieee754(BFF0800000000000) = -1.0312500000000000e+00 , 10) +ok 327 - convertToHexString (ieee754(BFF0800000000000) = -1.0312500000000000e+00 , 13) +ok 328 - convertToDecimalString(ieee754(BFF0800000000000) = -1.0312500000000000e+00 , 13) +ok 329 - convertToHexString (ieee754(3FF8000000000000) = +1.5000000000000000e+00 ) +ok 330 - convertToDecimalString(ieee754(3FF8000000000000) = +1.5000000000000000e+00 ) +ok 331 - convertToHexString (ieee754(3FF8000000000000) = +1.5000000000000000e+00 , ) +ok 332 - convertToDecimalString(ieee754(3FF8000000000000) = +1.5000000000000000e+00 , ) +ok 333 - convertToHexString (ieee754(3FF8000000000000) = +1.5000000000000000e+00 , 10) +ok 334 - convertToDecimalString(ieee754(3FF8000000000000) = +1.5000000000000000e+00 , 10) +ok 335 - convertToHexString (ieee754(3FF8000000000000) = +1.5000000000000000e+00 , 13) +ok 336 - convertToDecimalString(ieee754(3FF8000000000000) = +1.5000000000000000e+00 , 13) +ok 337 - convertToHexString (ieee754(BFF8000000000000) = -1.5000000000000000e+00 ) +ok 338 - convertToDecimalString(ieee754(BFF8000000000000) = -1.5000000000000000e+00 ) +ok 339 - convertToHexString (ieee754(BFF8000000000000) = -1.5000000000000000e+00 , ) +ok 340 - convertToDecimalString(ieee754(BFF8000000000000) = -1.5000000000000000e+00 , ) +ok 341 - convertToHexString (ieee754(BFF8000000000000) = -1.5000000000000000e+00 , 10) +ok 342 - convertToDecimalString(ieee754(BFF8000000000000) = -1.5000000000000000e+00 , 10) +ok 343 - convertToHexString (ieee754(BFF8000000000000) = -1.5000000000000000e+00 , 13) +ok 344 - convertToDecimalString(ieee754(BFF8000000000000) = -1.5000000000000000e+00 , 13) +ok 345 - convertToHexString (ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 ) +ok 346 - convertToDecimalString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 ) +ok 347 - convertToHexString (ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , ) +# + +# __0428__ binary64_convertToHexString() +# __0429__ nvsize = 8 +# __0429__ ivsize = 4 +# __0429__ doublesize = 8 +# __0429__ intsize = 4 +# __0429__ longsize = 4 +# __0429__ ptrsize = 4 +# __0437__ [msb][lsb] = 0x3fffffff ffffffff => digits=13 +# __0438__ ... = + ? . fffffffffffff pwr 0 +# __0447__ ... = + 1 . fffffffffffff pwr 0 +# __0452__ ... = + 1 . fffffffffffff pwr 0 +# __0522__ +0x1.fffffffffffffp+0000 +# __0031__ /exited DEBUG:convertToHexString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , ) = "+0x1.fffffffffffffp+0000" +# +ok 348 - convertToDecimalString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , ) +ok 349 - convertToHexString (ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 0) +# + +# __0428__ binary64_convertToHexString() +# __0429__ nvsize = 8 +# __0429__ ivsize = 4 +# __0429__ doublesize = 8 +# __0429__ intsize = 4 +# __0429__ longsize = 4 +# __0429__ ptrsize = 4 +# __0437__ [msb][lsb] = 0x3fffffff ffffffff => digits=0 +# __0438__ ... = + ? . fffffffffffff pwr 0 +# __0447__ ... = + 1 . fffffffffffff pwr 0 +# __0452__ ... = + 1 . fffffffffffff pwr 0 +# __0457__ ... = + 1 . left(fffff_ffffffff, digits:0) pwr 0 +# __0498__ ... = (m:0xfffff & eff:0xfffff = and:0xfffff) vs (haf:0x80000): >= +# __0501__ ... = + 1 . left(100000_00000000, digits:0) pwr 0 +# __0507__ ... = + 1 . left(00000_00000000, digits:0) pwr 0 +# __0516__ ... = + 2 . left(00000_00000000, digits:0) pwr 0 +# __0519__ +0x2p+0000 +# __0031__ /exited DEBUG:convertToHexString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 0) = "+0x2p+0000" +# +ok 350 - convertToDecimalString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 0) +ok 351 - convertToHexString (ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 1) +# + +# __0428__ binary64_convertToHexString() +# __0429__ nvsize = 8 +# __0429__ ivsize = 4 +# __0429__ doublesize = 8 +# __0429__ intsize = 4 +# __0429__ longsize = 4 +# __0429__ ptrsize = 4 +# __0437__ [msb][lsb] = 0x3fffffff ffffffff => digits=1 +# __0438__ ... = + ? . fffffffffffff pwr 0 +# __0447__ ... = + 1 . fffffffffffff pwr 0 +# __0452__ ... = + 1 . fffffffffffff pwr 0 +# __0457__ ... = + 1 . left(fffff_ffffffff, digits:1) pwr 0 +# __0498__ ... = (m:0xfffff & eff:0x0ffff = and:0x0ffff) vs (haf:0x08000): >= +# __0501__ ... = + 1 . left(100000_00000000, digits:1) pwr 0 +# __0507__ ... = + 1 . left(00000_00000000, digits:1) pwr 0 +# __0516__ ... = + 2 . left(00000_00000000, digits:1) pwr 0 +# __0519__ +0x2.0p+0000 +# __0031__ /exited DEBUG:convertToHexString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 1) = "+0x2.0p+0000" +# +ok 352 - convertToDecimalString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 1) +ok 353 - convertToHexString (ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 2) +# + +# __0428__ binary64_convertToHexString() +# __0429__ nvsize = 8 +# __0429__ ivsize = 4 +# __0429__ doublesize = 8 +# __0429__ intsize = 4 +# __0429__ longsize = 4 +# __0429__ ptrsize = 4 +# __0437__ [msb][lsb] = 0x3fffffff ffffffff => digits=2 +# __0438__ ... = + ? . fffffffffffff pwr 0 +# __0447__ ... = + 1 . fffffffffffff pwr 0 +# __0452__ ... = + 1 . fffffffffffff pwr 0 +# __0457__ ... = + 1 . left(fffff_ffffffff, digits:2) pwr 0 +# __0498__ ... = (m:0xfffff & eff:0x00fff = and:0x00fff) vs (haf:0x00800): >= +# __0501__ ... = + 1 . left(100000_00000000, digits:2) pwr 0 +# __0507__ ... = + 1 . left(00000_00000000, digits:2) pwr 0 +# __0516__ ... = + 2 . left(00000_00000000, digits:2) pwr 0 +# __0519__ +0x2.00p+0000 +# __0031__ /exited DEBUG:convertToHexString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 2) = "+0x2.00p+0000" +# +ok 354 - convertToDecimalString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 2) +ok 355 - convertToHexString (ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 3) +# + +# __0428__ binary64_convertToHexString() +# __0429__ nvsize = 8 +# __0429__ ivsize = 4 +# __0429__ doublesize = 8 +# __0429__ intsize = 4 +# __0429__ longsize = 4 +# __0429__ ptrsize = 4 +# __0437__ [msb][lsb] = 0x3fffffff ffffffff => digits=3 +# __0438__ ... = + ? . fffffffffffff pwr 0 +# __0447__ ... = + 1 . fffffffffffff pwr 0 +# __0452__ ... = + 1 . fffffffffffff pwr 0 +# __0457__ ... = + 1 . left(fffff_ffffffff, digits:3) pwr 0 +# __0498__ ... = (m:0xfffff & eff:0x000ff = and:0x000ff) vs (haf:0x00080): >= +# __0501__ ... = + 1 . left(100000_00000000, digits:3) pwr 0 +# __0507__ ... = + 1 . left(00000_00000000, digits:3) pwr 0 +# __0516__ ... = + 2 . left(00000_00000000, digits:3) pwr 0 +# __0519__ +0x2.000p+0000 +# __0031__ /exited DEBUG:convertToHexString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 3) = "+0x2.000p+0000" +# +ok 356 - convertToDecimalString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 3) +ok 357 - convertToHexString (ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 4) +# + +# __0428__ binary64_convertToHexString() +# __0429__ nvsize = 8 +# __0429__ ivsize = 4 +# __0429__ doublesize = 8 +# __0429__ intsize = 4 +# __0429__ longsize = 4 +# __0429__ ptrsize = 4 +# __0437__ [msb][lsb] = 0x3fffffff ffffffff => digits=4 +# __0438__ ... = + ? . fffffffffffff pwr 0 +# __0447__ ... = + 1 . fffffffffffff pwr 0 +# __0452__ ... = + 1 . fffffffffffff pwr 0 +# __0457__ ... = + 1 . left(fffff_ffffffff, digits:4) pwr 0 +# __0498__ ... = (m:0xfffff & eff:0x0000f = and:0x0000f) vs (haf:0x00008): >= +# __0501__ ... = + 1 . left(100000_00000000, digits:4) pwr 0 +# __0507__ ... = + 1 . left(00000_00000000, digits:4) pwr 0 +# __0516__ ... = + 2 . left(00000_00000000, digits:4) pwr 0 +# __0519__ +0x2.0000p+0000 +# __0031__ /exited DEBUG:convertToHexString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 4) = "+0x2.0000p+0000" +# +ok 358 - convertToDecimalString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 4) +ok 359 - convertToHexString (ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 5) +# + +# __0428__ binary64_convertToHexString() +# __0429__ nvsize = 8 +# __0429__ ivsize = 4 +# __0429__ doublesize = 8 +# __0429__ intsize = 4 +# __0429__ longsize = 4 +# __0429__ ptrsize = 4 +# __0437__ [msb][lsb] = 0x3fffffff ffffffff => digits=5 +# __0438__ ... = + ? . fffffffffffff pwr 0 +# __0447__ ... = + 1 . fffffffffffff pwr 0 +# __0452__ ... = + 1 . fffffffffffff pwr 0 +# __0457__ ... = + 1 . left(fffff_ffffffff, digits:5) pwr 0 +# __0422__ __0459__ Devel::Peek::Dump(l = 0xffffffff ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,pIOK,IsUV) +# # UV = 4294967295 +# # NV = 4095 +# # PV = 0 +# __0422__ __0461__ Devel::Peek::Dump(one = 0xffffffff or 4.2949672960000000e+09 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,NOK,pIOK,pNOK,IsUV) +# # UV = 4294967295 +# # NV = 4294967296 +# # PV = 0 +# __0422__ __0463__ Devel::Peek::Dump(haf = 0x80000000 or 2.1474836480000000e+09 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK,IsUV) +# # UV = 2147483648 +# # NV = 2147483648 +# # PV = 0 +# __0422__ __0465__ Devel::Peek::Dump(eff = 0xffffffff or 4.2949672950000000e+09 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK,IsUV) +# # UV = 4294967295 +# # NV = 4294967295 +# # PV = 0 +# __0467__ ... = (l:0xffffffff & eff:0xffffffff = and:0xffffffff) vs (haf:0x80000000): >= +# __0469__ ... = (l:0xffffffff & msk:0x00000000):0x00000000 + one:0xffffffff = 0xffffffff +# __0422__ __0471__ Devel::Peek::Dump(l = 0xffffffff or 4.2949672960000000e+09 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,NOK,pIOK,pNOK,IsUV) +# # UV = 4294967295 +# # NV = 4294967296 +# # PV = 0 +# __0472__ ... = + 1 . left(fffff_ffffffff, digits:5) pwr 0 +# __0422__ __0474__ Devel::Peek::Dump(l32 = 0xffffffff or 4.2949672950000000e+09 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK,IsUV) +# # UV = 4294967295 +# # NV = 4294967295 +# # PV = 0 +# __0475__ ... : l32 < one = 0xffffffff < 0xffffffff = 1 +# __0480__ ... = + 1 . left(100000_00000000, digits:5) pwr 0 +# __0516__ ... = + 2 . left(00000_00000000, digits:5) pwr 0 +# __0519__ +0x2.00000p+0000 +# __0031__ /exited DEBUG:convertToHexString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 5) = "+0x2.00000p+0000" +# +ok 360 - convertToDecimalString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 5) +not ok 361 - convertToHexString (ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 6) +# Failed test 'convertToHexString (ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 6)' +# at t/02-converttostr.t line 21. +# '+0x1.ffffffp+0000' +# doesn't match '(?-xism:\+0x2\.000000p\+0000)' +# + +# __0428__ binary64_convertToHexString() +# __0429__ nvsize = 8 +# __0429__ ivsize = 4 +# __0429__ doublesize = 8 +# __0429__ intsize = 4 +# __0429__ longsize = 4 +# __0429__ ptrsize = 4 +# __0437__ [msb][lsb] = 0x3fffffff ffffffff => digits=6 +# __0438__ ... = + ? . fffffffffffff pwr 0 +# __0447__ ... = + 1 . fffffffffffff pwr 0 +# __0452__ ... = + 1 . fffffffffffff pwr 0 +# __0457__ ... = + 1 . left(fffff_ffffffff, digits:6) pwr 0 +# __0422__ __0459__ Devel::Peek::Dump(l = 0xffffffff ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,pIOK,IsUV) +# # UV = 4294967295 +# # NV = 4294967295 +# # PV = 0 +# __0422__ __0461__ Devel::Peek::Dump(one = 0x10000000 or 2.6843545600000000e+08 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK) +# # IV = 268435456 +# # NV = 268435456 +# # PV = 0 +# __0422__ __0463__ Devel::Peek::Dump(haf = 0x08000000 or 1.3421772800000000e+08 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK) +# # IV = 134217728 +# # NV = 134217728 +# # PV = 0 +# __0422__ __0465__ Devel::Peek::Dump(eff = 0x0fffffff or 2.6843545500000000e+08 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK) +# # IV = 268435455 +# # NV = 268435455 +# # PV = 0 +# __0467__ ... = (l:0xffffffff & eff:0x0fffffff = and:0x0fffffff) vs (haf:0x08000000): >= +# __0469__ ... = (l:0xffffffff & msk:0xf0000000):0xf0000000 + one:0x10000000 = 0xffffffff +# __0422__ __0471__ Devel::Peek::Dump(l = 0xffffffff or 4.2949672960000000e+09 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,NOK,pIOK,pNOK,IsUV) +# # UV = 4294967295 +# # NV = 4294967296 +# # PV = 0 +# __0472__ ... = + 1 . left(fffff_ffffffff, digits:6) pwr 0 +# __0422__ __0474__ Devel::Peek::Dump(l32 = 0xffffffff or 4.2949672950000000e+09 ): +# # Use of uninitialized value in subroutine entry at lib/Data/IEEE754/Tools.pm line 417. +# # SV = PVNV(0x91d7088) at 0x911cfd0 +# # REFCNT = 1 +# # FLAGS = (PADBUSY,PADMY,IOK,NOK,pIOK,pNOK,IsUV) +# # UV = 4294967295 +# # NV = 4294967295 +# # PV = 0 +# __0475__ ... : l32 < one = 0xffffffff < 0x10000000 = 0 +# __0480__ ... = + 1 . left(fffff_ffffffff, digits:6) pwr 0 +# __0516__ ... = + 1 . left(fffff_ffffffff, digits:6) pwr 0 +# __0519__ +0x1.ffffffp+0000 +# __0031__ /exited DEBUG:convertToHexString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 6) = "+0x1.ffffffp+0000" +# +ok 362 - convertToDecimalString(ieee754(3FFFFFFFFFFFFFFF) = +1.9999999999999998e+00 , 6) +# Looks like you failed 5 tests of 362. + + + +........................ +So, I really need to come up with a way to _not_ be working at the left edge of a 32bit integer: +try something like: + + l = ffff_ffff + sh = shift l right to leave p-4 digits + p=5: sh=f p=6: sh=ff + if substr( l , p-5 , 1 ) > 7 then ">=" else "<" + if ">=", + if sh eq 'ffffffff' + known overflow + set l = 0x00000000, and set overflow bit + else + sh += 1 + if len(sh) > p-4, + set overflow bit + else + no overflow... + From 114612534142c1bd9df0c2ce7852ff573649adb0 Mon Sep 17 00:00:00 2001 From: PeterCJ Date: Fri, 29 Sep 2017 13:51:21 -0700 Subject: [PATCH 4/6] I think I might have the new version, but it's not fully tested yet --- lib/Data/IEEE754/Tools.pm | 90 +++++++++------------------------------ 1 file changed, 20 insertions(+), 70 deletions(-) diff --git a/lib/Data/IEEE754/Tools.pm b/lib/Data/IEEE754/Tools.pm index 51dd4d4..cd52564 100644 --- a/lib/Data/IEEE754/Tools.pm +++ b/lib/Data/IEEE754/Tools.pm @@ -433,7 +433,9 @@ DBG_SPRINTF("\t%-16s = %d", $_ => $Config{$_}) foreach( qw/nvsize ivsize doubles my $sbit = ($msb & 0x80000000) >> 31; my $sign = $sbit ? '-' : '+'; my $exp = (($msb & 0x7FF00000) >> 20) - 1023; - my $mant = sprintf '%05x%08x', $msb & 0x000FFFFF, $lsb & 0xFFFFFFFF; + my $mhex = sprintf '%05x', $msb & 0x000FFFFF; + my $lhex = sprintf '%08x', $lsb & 0xFFFFFFFF; + my $mant = $mhex . $lhex; DBG_SPRINTF('[msb][lsb] = 0x%08x %08x => digits=%d', $msb, $lsb, $p); DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, '?', $mant, $exp); if($exp == 1024) { @@ -450,77 +452,25 @@ DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, $implied, $mant, $exp); $exp = $mant eq '0000000000000' ? 0 : -1022; # 0 for zero, -1022 for denormal } DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, $implied, $mant, $exp); - if($p<13) { - my $m = $msb & 0xFFFFF; - my $l = $lsb; - my $o = 0; -DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); - if($p>=5) { # use all of MSB, and move into LSB -DBG_PEEK(sprintf("%-6s = 0x%08x\t", 'l', $l), $l); - my $one = 1; $one *= 2 for 1 .. 4*( 8 - ($p-5) ); # was 1 << 4*(), but doesn't work on {ivsize}=4 (32bit) -DBG_PEEK(sprintf("%-6s = 0x%08x or %.16e\t", 'one', $one, $one), $one); # for p==5, on a 32bit ivsize=4, I think there is overflow in $one beyond IV, which may be part of the culprit; but why on the higher p, where $one fits within ivsize? Besides, shouldn't it just promote to NV if it overflows IV? That's why I want the Devel::Peek - my $haf = $one / 2.0; -DBG_PEEK(sprintf("%-6s = 0x%08x or %.16e\t", 'haf', $haf, $haf), $haf); - my $eff = $one - 1; -DBG_PEEK(sprintf("%-6s = 0x%08x or %.16e\t", 'eff', $eff, $eff), $eff); - my $msk = 0xFFFFFFFF ^ $eff; -DBG_SPRINTF('... = (l:0x%08x & eff:0x%08x = and:0x%08x) vs (haf:0x%08x): %s', $l, $eff, $l & $eff, $haf, ((($l & $eff) >= $haf) ? '>=' : '<')); - if( ($l & $eff) >= $haf) { -DBG_SPRINTF('... = (l:0x%08x & msk:0x%08x):0x%08x + one:0x%08x = 0x%08x', $l, $msk, $l & $msk, $one, ($l & $msk) + $one); - $l = ($l & $msk) + $one; -DBG_PEEK(sprintf("%-6s = 0x%08x or %.16e\t", 'l', $l, $l), $l); # maybe it was the (l&msk)+(one) ???? -DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); - my $l32 = $l & 0xFFFFFFFF; -DBG_PEEK(sprintf("%-6s = 0x%08x or %.16e\t", 'l32', $l32, $l32), $l32); -DBG_SPRINTF('... : l32 < one = 0x%08x < 0x%08x = %x', $l32, $one, $l32 < $one); - if($l32 < $one) { - $l = 0; - $m++; - } -DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); - } else { - $l = ($l & $msk); -DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); - } - if($m >= 0x1_0_0000) { - $o = 1; - $m -= 0x1_0_0000; - } - if($o) { - $implied++; - } - } else { # thus p<5 - $l = 0; # don't need the lowest 8 nibbles... - my $one = 1 << 4*( 5 - $p ); - my $haf = $one >> 1; - my $eff = $one - 1; - my $msk = 0xFFFFF ^ $eff; -DBG_SPRINTF('... = (m:0x%05x & eff:0x%05x = and:0x%05x) vs (haf:0x%05x): %s', $m, $eff, $m & $eff, $haf, ((($m & $eff) >= $haf) ? '>=' : '<')); - if( ($m & $eff) >= $haf) { - $m = ($m & $msk) + $one; -DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); - my $m20 = $m & 0xFFFFF; - if($m20 < $one) { - $m = 0; - $o++; - } -DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); - } else { - $m = ($m & $msk); -DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); - } - if($o) { - $implied++; - } - } -DBG_SPRINTF('... = %s %s . left(%05x_%08x, digits:%d) pwr %d', $sign, $implied, $m, $l, $p, $exp); - - my $f = substr( sprintf('%05x%08x', $m, $l), 0, $p); -DBG_SPRINTF('%s0x%1u%s%*sp%+05d', $sign, $implied, $p?'.':'', $p, $f, $exp); - return sprintf '%s0x%1u%s%*sp%+05d', $sign, $implied, $p?'.':'', $p, $f, $exp; - } else { # thus, p>=13: + if( $p>12 ) { DBG_SPRINTF('%s0x%1u.%13.13sp%+05d', $sign, $implied, $mant . '0'x($p-13), $exp); return sprintf '%s0x%1u.%13.13sp%+05d', $sign, $implied, $mant . '0'x($p-13), $exp; + } else { + my $roundhex = substr $mant, 0, $p; + my $nibble = substr $mant, $p, 1; + my $carry = hex($nibble)>7 ? 1 : 0; + foreach my $cp ( 1 .. $p ) { + $nibble = substr $roundhex, -$cp, 1; + my $v = hex($nibble)+$carry; + ($carry, $v) = (16==$v) ? (1,0) : (0, $v); + $nibble = sprintf '%01x', $v; + substr($roundhex, -$cp, 1) = $nibble; + } +DBG_SPRINTF('{%02d} %13.13s => [%13.13s] [%1.1s] <%01d>', $p, $mant, $roundhex, $nibble, $carry); + $implied += $carry; + my $ret = sprintf '%s0x%1u%s%*sp%+05d', $sign, $implied, $p?'.':'', $p, $roundhex, $exp; +DBG_SPRINTF('ret=%s', $ret); + return $ret; } } *convertToHexString = \&binary64_convertToHexString; From 4bf338c7ee7a265e57700bb6b64675a136db5cfa Mon Sep 17 00:00:00 2001 From: PeterCJ Date: Fri, 29 Sep 2017 16:28:56 -0700 Subject: [PATCH 5/6] v0.018003: reworked function to one nibble at a time (no overflow possible) --- CHANGES | 5 ++ TODO | 4 ++ lib/Data/IEEE754/Tools.pm | 8 +-- t/02-converttostr.t | 108 ++++++++++++++++++++++---------------- 4 files changed, 75 insertions(+), 50 deletions(-) diff --git a/CHANGES b/CHANGES index 1c862df..2174d13 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,10 @@ Revision history for Perl module Data::IEEE754::Tools. +v0.018003 2017-Sep-29 + - Completely reworked the function, so it deals with one nibble at a time, + thus avoiding any overflow (easier to code than doing sub-32b groupings) + - possible bug in t/01*.t, but unverified and unstudied + v0.018002 2017-Sep-25 - Change from README.pod to README.md, because *.pod are built and put in the module documentation directory diff --git a/TODO b/TODO index 8f40158..51fc93d 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,8 @@ TODO + - bugfix: + - fix the v0.018 t/02*.t roundoff bug: it was overflowing 32bit on {ivsize}=4 systems; + new method should not + - testing on my 32b linux box, found failures in t/01*.t suite; needs to be investigated - long-term: implement more functions from IEEE754-2007, especially + IEEE754 5.4.2 => 5.12 ☐ -convertFormat diff --git a/lib/Data/IEEE754/Tools.pm b/lib/Data/IEEE754/Tools.pm index cd52564..a371400 100644 --- a/lib/Data/IEEE754/Tools.pm +++ b/lib/Data/IEEE754/Tools.pm @@ -425,10 +425,10 @@ sub binary64_convertToHexString { # thanks to BrowserUK @ http://perlmonks.org/?node_id=1167146 for slighly better decision factors # I tweaked it to use the two 32bit words instead of one 64bit word (which wouldn't work on some systems) print STDERR "#\n" if $Data::IEEE754::Tools::CPANTESTERS_DEBUG; -DBG_SPRINTF('binary64_convertToHexString()'); -DBG_SPRINTF("\t%-16s = %d", $_ => $Config{$_}) foreach( qw/nvsize ivsize doublesize intsize longsize ptrsize/ ); my $v = shift; my $p = defined $_[0] ? shift : 13; +DBG_SPRINTF('binary64_convertToHexString(%+24.16e, digits:%d)', $v, $p); +DBG_SPRINTF("\t%-16s = %d", $_ => $Config{$_}) foreach( qw/nvsize ivsize doublesize intsize longsize ptrsize/ ); my ($msb,$lsb) = $_helper64_arr2x32b->($v); my $sbit = ($msb & 0x80000000) >> 31; my $sign = $sbit ? '-' : '+'; @@ -453,7 +453,7 @@ DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, $implied, $mant, $exp); } DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, $implied, $mant, $exp); if( $p>12 ) { -DBG_SPRINTF('%s0x%1u.%13.13sp%+05d', $sign, $implied, $mant . '0'x($p-13), $exp); +DBG_SPRINTF('ret(%+24.16e,%d)=%s0x%1u.%13.13sp%+05d', $v, $p, $sign, $implied, $mant . '0'x($p-13), $exp); return sprintf '%s0x%1u.%13.13sp%+05d', $sign, $implied, $mant . '0'x($p-13), $exp; } else { my $roundhex = substr $mant, 0, $p; @@ -469,7 +469,7 @@ DBG_SPRINTF('%s0x%1u.%13.13sp%+05d', $sign, $implied, $mant . '0'x($p-13), $exp) DBG_SPRINTF('{%02d} %13.13s => [%13.13s] [%1.1s] <%01d>', $p, $mant, $roundhex, $nibble, $carry); $implied += $carry; my $ret = sprintf '%s0x%1u%s%*sp%+05d', $sign, $implied, $p?'.':'', $p, $roundhex, $exp; -DBG_SPRINTF('ret=%s', $ret); +DBG_SPRINTF('ret(%+24.16e,%d)=%s', $v, $p, $ret); return $ret; } } diff --git a/t/02-converttostr.t b/t/02-converttostr.t index 4fcd3e4..bd19c28 100644 --- a/t/02-converttostr.t +++ b/t/02-converttostr.t @@ -24,7 +24,7 @@ sub fptest { $h->{src}, $val, defined $h->{convSpec} ? $h->{convSpec} : '') ); - if( $h->{src} eq '3FFFFFFFFFFFFFFF' or $h->{src} eq '3FF0000000000001') { + if( $h->{src} eq '3FFFFFFFFFFFFFFF') { $Data::IEEE754::Tools::CPANTESTERS_DEBUG = 1; my $s = convertToHexString($val, $h->{convSpec}); diag sprintf(qq(__%04d__\t/exited DEBUG:convertToHexString(ieee754(%-16.16s) = %-+24.16e, %s) = "%s"), @@ -256,34 +256,34 @@ push @tests, { src => 'BFF8000000000000', exp_hex => '-0x1.8000000000000p+0000', push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x1.fffffffffffffp+0000', exp_dec => '+0d1.9999999999999998p+0000' }; push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x1.fffffffffffffp+0000', exp_dec => '+0d1.9999999999999998p+0000' , convSpec => undef }; -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2p+0000' , exp_dec => '+0d2p+0000' , convSpec => 0 }; # extra: coverage for low p -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.0p+0000' , exp_dec => '+0d2.0p+0000' , convSpec => 1 }; # extra: coverage for low p -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.00p+0000' , exp_dec => '+0d2.00p+0000' , convSpec => 2 }; # extra: coverage for low p -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.000p+0000' , exp_dec => '+0d2.000p+0000' , convSpec => 3 }; # extra: coverage for low p -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.0000p+0000' , exp_dec => '+0d2.0000p+0000' , convSpec => 4 }; # extra: coverage for low p -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.00000p+0000' , exp_dec => '+0d2.00000p+0000' , convSpec => 5 }; # extra: coverage for low p -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.000000p+0000' , exp_dec => '+0d2.000000p+0000' , convSpec => 6 }; # extra: coverage for low p -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.0000000p+0000' , exp_dec => '+0d2.0000000p+0000' , convSpec => 7 }; # extra: coverage for low p -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.00000000p+0000' , exp_dec => '+0d2.00000000p+0000' , convSpec => 8 }; # extra: coverage for low p -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.000000000p+0000' , exp_dec => '+0d2.000000000p+0000' , convSpec => 9 }; # extra: coverage for low p +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2p+0000' , exp_dec => '+0d2p+0000' , convSpec => 0 }; # extra: coverage for low number of digits +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.0p+0000' , exp_dec => '+0d2.0p+0000' , convSpec => 1 }; # extra: coverage for low number of digits +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.00p+0000' , exp_dec => '+0d2.00p+0000' , convSpec => 2 }; # extra: coverage for low number of digits +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.000p+0000' , exp_dec => '+0d2.000p+0000' , convSpec => 3 }; # extra: coverage for low number of digits +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.0000p+0000' , exp_dec => '+0d2.0000p+0000' , convSpec => 4 }; # extra: coverage for low number of digits +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.00000p+0000' , exp_dec => '+0d2.00000p+0000' , convSpec => 5 }; # extra: coverage for low number of digits +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.000000p+0000' , exp_dec => '+0d2.000000p+0000' , convSpec => 6 }; # extra: coverage for low number of digits +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.0000000p+0000' , exp_dec => '+0d2.0000000p+0000' , convSpec => 7 }; # extra: coverage for low number of digits +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.00000000p+0000' , exp_dec => '+0d2.00000000p+0000' , convSpec => 8 }; # extra: coverage for low number of digits +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.000000000p+0000' , exp_dec => '+0d2.000000000p+0000' , convSpec => 9 }; # extra: coverage for low number of digits push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.0000000000p+0000' , exp_dec => '+0d2.0000000000p+0000' , convSpec => 10 }; -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.00000000000p+0000' , exp_dec => '+0d2.00000000000p+0000' , convSpec => 11 }; # extra: coverage for low p -push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.000000000000p+0000' , exp_dec => '+0d2.000000000000p+0000' , convSpec => 12 }; # extra: coverage for low p +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.00000000000p+0000' , exp_dec => '+0d2.00000000000p+0000' , convSpec => 11 }; # extra: coverage for low number of digits +push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x2.000000000000p+0000' , exp_dec => '+0d2.000000000000p+0000' , convSpec => 12 }; # extra: coverage for low number of digits push @tests, { src => '3FFFFFFFFFFFFFFF', exp_hex => '+0x1.fffffffffffffp+0000', exp_dec => '+0d2.0000000000000p+0000' , convSpec => 13 }; push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x1.fffffffffffffp+0000', exp_dec => '-0d1.9999999999999998p+0000' }; push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x1.fffffffffffffp+0000', exp_dec => '-0d1.9999999999999998p+0000' , convSpec => undef }; -push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.0p+0000' , exp_dec => '-0d2.0p+0000' , convSpec => 1 }; # extra: coverage for low p -push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.00p+0000' , exp_dec => '-0d2.00p+0000' , convSpec => 2 }; # extra: coverage for low p -push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.000p+0000' , exp_dec => '-0d2.000p+0000' , convSpec => 3 }; # extra: coverage for low p -push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.0000p+0000' , exp_dec => '-0d2.0000p+0000' , convSpec => 4 }; # extra: coverage for low p -push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.00000p+0000' , exp_dec => '-0d2.00000p+0000' , convSpec => 5 }; # extra: coverage for low p -push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.000000p+0000' , exp_dec => '-0d2.000000p+0000' , convSpec => 6 }; # extra: coverage for low p -push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.0000000p+0000' , exp_dec => '-0d2.0000000p+0000' , convSpec => 7 }; # extra: coverage for low p -push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.00000000p+0000' , exp_dec => '-0d2.00000000p+0000' , convSpec => 8 }; # extra: coverage for low p -push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.000000000p+0000' , exp_dec => '-0d2.000000000p+0000' , convSpec => 9 }; # extra: coverage for low p +push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.0p+0000' , exp_dec => '-0d2.0p+0000' , convSpec => 1 }; # extra: coverage for low number of digits +push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.00p+0000' , exp_dec => '-0d2.00p+0000' , convSpec => 2 }; # extra: coverage for low number of digits +push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.000p+0000' , exp_dec => '-0d2.000p+0000' , convSpec => 3 }; # extra: coverage for low number of digits +push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.0000p+0000' , exp_dec => '-0d2.0000p+0000' , convSpec => 4 }; # extra: coverage for low number of digits +push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.00000p+0000' , exp_dec => '-0d2.00000p+0000' , convSpec => 5 }; # extra: coverage for low number of digits +push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.000000p+0000' , exp_dec => '-0d2.000000p+0000' , convSpec => 6 }; # extra: coverage for low number of digits +push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.0000000p+0000' , exp_dec => '-0d2.0000000p+0000' , convSpec => 7 }; # extra: coverage for low number of digits +push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.00000000p+0000' , exp_dec => '-0d2.00000000p+0000' , convSpec => 8 }; # extra: coverage for low number of digits +push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.000000000p+0000' , exp_dec => '-0d2.000000000p+0000' , convSpec => 9 }; # extra: coverage for low number of digits push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.0000000000p+0000' , exp_dec => '-0d2.0000000000p+0000' , convSpec => 10 }; -push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.00000000000p+0000' , exp_dec => '-0d2.00000000000p+0000' , convSpec => 11 }; # extra: coverage for low p -push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.000000000000p+0000' , exp_dec => '-0d2.000000000000p+0000' , convSpec => 12 }; # extra: coverage for low p +push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.00000000000p+0000' , exp_dec => '-0d2.00000000000p+0000' , convSpec => 11 }; # extra: coverage for low number of digits +push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x2.000000000000p+0000' , exp_dec => '-0d2.000000000000p+0000' , convSpec => 12 }; # extra: coverage for low number of digits push @tests, { src => 'BFFFFFFFFFFFFFFF', exp_hex => '-0x1.fffffffffffffp+0000', exp_dec => '-0d2.0000000000000p+0000' , convSpec => 13 }; push @tests, { src => '3FF0FFFFFFFFFFFF', exp_hex => '+0x1.1p+0000' , exp_dec => '+0d1.1p+0000' , convSpec => 1 }; # extra: coverage for msb rounding @@ -302,36 +302,52 @@ push @tests, { src => '3FFCFFFFFFFFFFFF', exp_hex => '+0x1.dp+0000' , push @tests, { src => '3FFDFFFFFFFFFFFF', exp_hex => '+0x1.ep+0000' , exp_dec => '+0d1.9p+0000' , convSpec => 1 }; # extra: coverage for msb rounding push @tests, { src => '3FFEFFFFFFFFFFFF', exp_hex => '+0x1.fp+0000' , exp_dec => '+0d1.9p+0000' , convSpec => 1 }; # extra: coverage for msb rounding +push @tests, { src => '3FF000000FFFFFFF', exp_hex => '+0x1.00000p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF000001FFFFFFF', exp_hex => '+0x1.00000p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF000002FFFFFFF', exp_hex => '+0x1.00000p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF000003FFFFFFF', exp_hex => '+0x1.00000p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF000004FFFFFFF', exp_hex => '+0x1.00000p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF000005FFFFFFF', exp_hex => '+0x1.00000p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF000006FFFFFFF', exp_hex => '+0x1.00000p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF000007FFFFFFF', exp_hex => '+0x1.00000p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF000008FFFFFFF', exp_hex => '+0x1.00001p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF000009FFFFFFF', exp_hex => '+0x1.00001p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF00000AFFFFFFF', exp_hex => '+0x1.00001p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF00000BFFFFFFF', exp_hex => '+0x1.00001p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF00000CFFFFFFF', exp_hex => '+0x1.00001p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF00000DFFFFFFF', exp_hex => '+0x1.00001p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding +push @tests, { src => '3FF00000EFFFFFFF', exp_hex => '+0x1.00001p+0000' , exp_dec => '+0d1.00000p+0000' , convSpec => 5 }; # extra: coverage for lsb rounding + push @tests, { src => '4000000000000000', exp_hex => '+0x1.0000000000000p+0001', exp_dec => '+0d1.0000000000000000p+0001' }; push @tests, { src => '4000000000000000', exp_hex => '+0x1.0000000000000p+0001', exp_dec => '+0d1.0000000000000000p+0001' , convSpec => undef }; -push @tests, { src => '4000000000000000', exp_hex => '+0x1.0p+0001' , exp_dec => '+0d1.0p+0001' , convSpec => 1 }; # extra: coverage for low p -push @tests, { src => '4000000000000000', exp_hex => '+0x1.00p+0001' , exp_dec => '+0d1.00p+0001' , convSpec => 2 }; # extra: coverage for low p -push @tests, { src => '4000000000000000', exp_hex => '+0x1.000p+0001' , exp_dec => '+0d1.000p+0001' , convSpec => 3 }; # extra: coverage for low p -push @tests, { src => '4000000000000000', exp_hex => '+0x1.0000p+0001' , exp_dec => '+0d1.0000p+0001' , convSpec => 4 }; # extra: coverage for low p -push @tests, { src => '4000000000000000', exp_hex => '+0x1.00000p+0001' , exp_dec => '+0d1.00000p+0001' , convSpec => 5 }; # extra: coverage for low p -push @tests, { src => '4000000000000000', exp_hex => '+0x1.000000p+0001' , exp_dec => '+0d1.000000p+0001' , convSpec => 6 }; # extra: coverage for low p -push @tests, { src => '4000000000000000', exp_hex => '+0x1.0000000p+0001' , exp_dec => '+0d1.0000000p+0001' , convSpec => 7 }; # extra: coverage for low p -push @tests, { src => '4000000000000000', exp_hex => '+0x1.00000000p+0001' , exp_dec => '+0d1.00000000p+0001' , convSpec => 8 }; # extra: coverage for low p -push @tests, { src => '4000000000000000', exp_hex => '+0x1.000000000p+0001' , exp_dec => '+0d1.000000000p+0001' , convSpec => 9 }; # extra: coverage for low p +push @tests, { src => '4000000000000000', exp_hex => '+0x1.0p+0001' , exp_dec => '+0d1.0p+0001' , convSpec => 1 }; # extra: coverage for low number of digits +push @tests, { src => '4000000000000000', exp_hex => '+0x1.00p+0001' , exp_dec => '+0d1.00p+0001' , convSpec => 2 }; # extra: coverage for low number of digits +push @tests, { src => '4000000000000000', exp_hex => '+0x1.000p+0001' , exp_dec => '+0d1.000p+0001' , convSpec => 3 }; # extra: coverage for low number of digits +push @tests, { src => '4000000000000000', exp_hex => '+0x1.0000p+0001' , exp_dec => '+0d1.0000p+0001' , convSpec => 4 }; # extra: coverage for low number of digits +push @tests, { src => '4000000000000000', exp_hex => '+0x1.00000p+0001' , exp_dec => '+0d1.00000p+0001' , convSpec => 5 }; # extra: coverage for low number of digits +push @tests, { src => '4000000000000000', exp_hex => '+0x1.000000p+0001' , exp_dec => '+0d1.000000p+0001' , convSpec => 6 }; # extra: coverage for low number of digits +push @tests, { src => '4000000000000000', exp_hex => '+0x1.0000000p+0001' , exp_dec => '+0d1.0000000p+0001' , convSpec => 7 }; # extra: coverage for low number of digits +push @tests, { src => '4000000000000000', exp_hex => '+0x1.00000000p+0001' , exp_dec => '+0d1.00000000p+0001' , convSpec => 8 }; # extra: coverage for low number of digits +push @tests, { src => '4000000000000000', exp_hex => '+0x1.000000000p+0001' , exp_dec => '+0d1.000000000p+0001' , convSpec => 9 }; # extra: coverage for low number of digits push @tests, { src => '4000000000000000', exp_hex => '+0x1.0000000000p+0001' , exp_dec => '+0d1.0000000000p+0001' , convSpec => 10 }; -push @tests, { src => '4000000000000000', exp_hex => '+0x1.00000000000p+0001' , exp_dec => '+0d1.00000000000p+0001' , convSpec => 11 }; # extra: coverage for low p -push @tests, { src => '4000000000000000', exp_hex => '+0x1.000000000000p+0001' , exp_dec => '+0d1.000000000000p+0001' , convSpec => 12 }; # extra: coverage for low p +push @tests, { src => '4000000000000000', exp_hex => '+0x1.00000000000p+0001' , exp_dec => '+0d1.00000000000p+0001' , convSpec => 11 }; # extra: coverage for low number of digits +push @tests, { src => '4000000000000000', exp_hex => '+0x1.000000000000p+0001' , exp_dec => '+0d1.000000000000p+0001' , convSpec => 12 }; # extra: coverage for low number of digits push @tests, { src => '4000000000000000', exp_hex => '+0x1.0000000000000p+0001', exp_dec => '+0d1.0000000000000p+0001' , convSpec => 13 }; push @tests, { src => 'C000000000000000', exp_hex => '-0x1.0000000000000p+0001', exp_dec => '-0d1.0000000000000000p+0001' }; push @tests, { src => 'C000000000000000', exp_hex => '-0x1.0000000000000p+0001', exp_dec => '-0d1.0000000000000000p+0001' , convSpec => undef }; -push @tests, { src => 'C000000000000000', exp_hex => '-0x1.0p+0001' , exp_dec => '-0d1.0p+0001' , convSpec => 1 }; # extra: coverage for low p -push @tests, { src => 'C000000000000000', exp_hex => '-0x1.00p+0001' , exp_dec => '-0d1.00p+0001' , convSpec => 2 }; # extra: coverage for low p -push @tests, { src => 'C000000000000000', exp_hex => '-0x1.000p+0001' , exp_dec => '-0d1.000p+0001' , convSpec => 3 }; # extra: coverage for low p -push @tests, { src => 'C000000000000000', exp_hex => '-0x1.0000p+0001' , exp_dec => '-0d1.0000p+0001' , convSpec => 4 }; # extra: coverage for low p -push @tests, { src => 'C000000000000000', exp_hex => '-0x1.00000p+0001' , exp_dec => '-0d1.00000p+0001' , convSpec => 5 }; # extra: coverage for low p -push @tests, { src => 'C000000000000000', exp_hex => '-0x1.000000p+0001' , exp_dec => '-0d1.000000p+0001' , convSpec => 6 }; # extra: coverage for low p -push @tests, { src => 'C000000000000000', exp_hex => '-0x1.0000000p+0001' , exp_dec => '-0d1.0000000p+0001' , convSpec => 7 }; # extra: coverage for low p -push @tests, { src => 'C000000000000000', exp_hex => '-0x1.00000000p+0001' , exp_dec => '-0d1.00000000p+0001' , convSpec => 8 }; # extra: coverage for low p -push @tests, { src => 'C000000000000000', exp_hex => '-0x1.000000000p+0001' , exp_dec => '-0d1.000000000p+0001' , convSpec => 9 }; # extra: coverage for low p +push @tests, { src => 'C000000000000000', exp_hex => '-0x1.0p+0001' , exp_dec => '-0d1.0p+0001' , convSpec => 1 }; # extra: coverage for low number of digits +push @tests, { src => 'C000000000000000', exp_hex => '-0x1.00p+0001' , exp_dec => '-0d1.00p+0001' , convSpec => 2 }; # extra: coverage for low number of digits +push @tests, { src => 'C000000000000000', exp_hex => '-0x1.000p+0001' , exp_dec => '-0d1.000p+0001' , convSpec => 3 }; # extra: coverage for low number of digits +push @tests, { src => 'C000000000000000', exp_hex => '-0x1.0000p+0001' , exp_dec => '-0d1.0000p+0001' , convSpec => 4 }; # extra: coverage for low number of digits +push @tests, { src => 'C000000000000000', exp_hex => '-0x1.00000p+0001' , exp_dec => '-0d1.00000p+0001' , convSpec => 5 }; # extra: coverage for low number of digits +push @tests, { src => 'C000000000000000', exp_hex => '-0x1.000000p+0001' , exp_dec => '-0d1.000000p+0001' , convSpec => 6 }; # extra: coverage for low number of digits +push @tests, { src => 'C000000000000000', exp_hex => '-0x1.0000000p+0001' , exp_dec => '-0d1.0000000p+0001' , convSpec => 7 }; # extra: coverage for low number of digits +push @tests, { src => 'C000000000000000', exp_hex => '-0x1.00000000p+0001' , exp_dec => '-0d1.00000000p+0001' , convSpec => 8 }; # extra: coverage for low number of digits +push @tests, { src => 'C000000000000000', exp_hex => '-0x1.000000000p+0001' , exp_dec => '-0d1.000000000p+0001' , convSpec => 9 }; # extra: coverage for low number of digits push @tests, { src => 'C000000000000000', exp_hex => '-0x1.0000000000p+0001' , exp_dec => '-0d1.0000000000p+0001' , convSpec => 10 }; -push @tests, { src => 'C000000000000000', exp_hex => '-0x1.00000000000p+0001' , exp_dec => '-0d1.00000000000p+0001' , convSpec => 11 }; # extra: coverage for low p -push @tests, { src => 'C000000000000000', exp_hex => '-0x1.000000000000p+0001' , exp_dec => '-0d1.000000000000p+0001' , convSpec => 12 }; # extra: coverage for low p +push @tests, { src => 'C000000000000000', exp_hex => '-0x1.00000000000p+0001' , exp_dec => '-0d1.00000000000p+0001' , convSpec => 11 }; # extra: coverage for low number of digits +push @tests, { src => 'C000000000000000', exp_hex => '-0x1.000000000000p+0001' , exp_dec => '-0d1.000000000000p+0001' , convSpec => 12 }; # extra: coverage for low number of digits push @tests, { src => 'C000000000000000', exp_hex => '-0x1.0000000000000p+0001', exp_dec => '-0d1.0000000000000p+0001' , convSpec => 13 }; push @tests, { src => '4000000000000001', exp_hex => '+0x1.0000000000001p+0001', exp_dec => '+0d1.0000000000000002p+0001' }; From aa5aa86c5006301513f426038255b1d7df42ce71 Mon Sep 17 00:00:00 2001 From: PeterCJ Date: Sun, 1 Oct 2017 10:39:08 -0700 Subject: [PATCH 6/6] v0.018004: final bugfix for convertToHexString() with ivsize=4; ready to reintegrate to trunk --- CHANGES | 4 ++++ lib/Data/IEEE754/Tools.pm | 33 ++------------------------------- t/02-converttostr.t | 11 ----------- 3 files changed, 6 insertions(+), 42 deletions(-) diff --git a/CHANGES b/CHANGES index 2174d13..fe92975 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ Revision history for Perl module Data::IEEE754::Tools. +v0.018003 2017-Oct-01 + - binary64_convertToHexString(): bugfix verified; now works on ivsize=4; + remove debug code + v0.018003 2017-Sep-29 - Completely reworked the function, so it deals with one nibble at a time, thus avoiding any overflow (easier to code than doing sub-32b groupings) diff --git a/lib/Data/IEEE754/Tools.pm b/lib/Data/IEEE754/Tools.pm index a371400..ee1ba16 100644 --- a/lib/Data/IEEE754/Tools.pm +++ b/lib/Data/IEEE754/Tools.pm @@ -6,7 +6,7 @@ use Carp; use Exporter 'import'; # just use the import() function, without the rest of the overhead of ISA use Config; -our $VERSION = '0.018003'; +our $VERSION = '0.018004'; # use rrr.mmm_aaa, where rrr is major revision, mmm is ODD minor revision, and aaa is alpha sub-revision (for ALPHA code) # use rrr.mmmsss, where rrr is major revision, mmm is EVEN minor revision, and sss is a sub-revision (usually sss=000) (for releases) @@ -401,34 +401,12 @@ hex-digits or 16 decimal-digits). =cut -sub DBG_SPRINTF { - return unless $Data::IEEE754::Tools::CPANTESTERS_DEBUG; - my $fmt = shift; - warn sprintf("# __%04d__\t", (caller)[2]), sprintf( $fmt, @_ ), "\n"; -} -use Devel::Peek (); -sub DBG_PEEK { - return unless $Data::IEEE754::Tools::CPANTESTERS_DEBUG; - my ($name, $var) = @_; - open( my $ek , '>&STDERR') or die "dup STDERR: $!"; - close(STDERR); - my $txt; - open(STDERR, '>', \$txt) or die "STDERR to var: $!"; - Devel::Peek::Dump($var); - close(STDERR); - open(STDERR, ">&", $ek) or die "STDERR back to orig: $!"; - $txt =~ s/^/# \t\t# /gims; - $txt =~ s/\s*$//gims; - DBG_SPRINTF("__%04d__\tDevel::Peek::Dump(%s):\n%s", (caller)[2], $name, $txt); -} sub binary64_convertToHexString { # thanks to BrowserUK @ http://perlmonks.org/?node_id=1167146 for slighly better decision factors # I tweaked it to use the two 32bit words instead of one 64bit word (which wouldn't work on some systems) -print STDERR "#\n" if $Data::IEEE754::Tools::CPANTESTERS_DEBUG; + # v0.018003: to fix integer overflow on ivsize=4, reworked to pure nibbles my $v = shift; my $p = defined $_[0] ? shift : 13; -DBG_SPRINTF('binary64_convertToHexString(%+24.16e, digits:%d)', $v, $p); -DBG_SPRINTF("\t%-16s = %d", $_ => $Config{$_}) foreach( qw/nvsize ivsize doublesize intsize longsize ptrsize/ ); my ($msb,$lsb) = $_helper64_arr2x32b->($v); my $sbit = ($msb & 0x80000000) >> 31; my $sign = $sbit ? '-' : '+'; @@ -436,8 +414,6 @@ DBG_SPRINTF("\t%-16s = %d", $_ => $Config{$_}) foreach( qw/nvsize ivsize doubles my $mhex = sprintf '%05x', $msb & 0x000FFFFF; my $lhex = sprintf '%08x', $lsb & 0xFFFFFFFF; my $mant = $mhex . $lhex; -DBG_SPRINTF('[msb][lsb] = 0x%08x %08x => digits=%d', $msb, $lsb, $p); -DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, '?', $mant, $exp); if($exp == 1024) { my $z = "0"x (($p<5?4:$p)-4); return $sign . "0x1.#INF${z}p+0000" if $mant eq '0000000000000'; @@ -446,14 +422,11 @@ DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, '?', $mant, $exp); return $sign . ( (($msb & 0x00080000) != 0x00080000) ? "0x1.#SNAN${z}p+0000" : "0x1.#QNAN${z}p+0000"); # v0.012 coverage note: '!=' condition only triggered on systems with SNAN; ignore Devel::Cover failures on this line on systems which quiet all SNAN to QNAN } my $implied = 1; -DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, $implied, $mant, $exp); if( $exp == -1023 ) { # zero or denormal $implied = 0; $exp = $mant eq '0000000000000' ? 0 : -1022; # 0 for zero, -1022 for denormal } -DBG_SPRINTF('... = %s %s . %s pwr %d', $sign, $implied, $mant, $exp); if( $p>12 ) { -DBG_SPRINTF('ret(%+24.16e,%d)=%s0x%1u.%13.13sp%+05d', $v, $p, $sign, $implied, $mant . '0'x($p-13), $exp); return sprintf '%s0x%1u.%13.13sp%+05d', $sign, $implied, $mant . '0'x($p-13), $exp; } else { my $roundhex = substr $mant, 0, $p; @@ -466,10 +439,8 @@ DBG_SPRINTF('ret(%+24.16e,%d)=%s0x%1u.%13.13sp%+05d', $v, $p, $sign, $implied, $ $nibble = sprintf '%01x', $v; substr($roundhex, -$cp, 1) = $nibble; } -DBG_SPRINTF('{%02d} %13.13s => [%13.13s] [%1.1s] <%01d>', $p, $mant, $roundhex, $nibble, $carry); $implied += $carry; my $ret = sprintf '%s0x%1u%s%*sp%+05d', $sign, $implied, $p?'.':'', $p, $roundhex, $exp; -DBG_SPRINTF('ret(%+24.16e,%d)=%s', $v, $p, $ret); return $ret; } } diff --git a/t/02-converttostr.t b/t/02-converttostr.t index bd19c28..caf14de 100644 --- a/t/02-converttostr.t +++ b/t/02-converttostr.t @@ -24,17 +24,6 @@ sub fptest { $h->{src}, $val, defined $h->{convSpec} ? $h->{convSpec} : '') ); - if( $h->{src} eq '3FFFFFFFFFFFFFFF') { - $Data::IEEE754::Tools::CPANTESTERS_DEBUG = 1; - my $s = convertToHexString($val, $h->{convSpec}); - diag sprintf(qq(__%04d__\t/exited DEBUG:convertToHexString(ieee754(%-16.16s) = %-+24.16e, %s) = "%s"), - __LINE__, $h->{src}, $val, - defined $h->{convSpec} ? $h->{convSpec} : '', - $s - ); - diag ''; - undef $Data::IEEE754::Tools::CPANTESTERS_DEBUG; - } } else { like( $got = convertToHexString($val), qr/$exp/,