Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

CC: increase numeric precision a bit

%g is a very poor choice to keep double precision, as it defaults to 6 digits.
double needs 16-17 digits, 16 usually the best.
Also note that the ops do not use NV as long double, even if d_longdbl is defined.
A NV is double.

%.16g is enough precision to pass the shootout nbody test.
  • Loading branch information...
commit 3fc61aa69af24d438a2983a15996362207443f43 1 parent 61f4f1a
Reini Urban authored October 04, 2012

Showing 2 changed files with 16 additions and 11 deletions. Show diff stats Hide diff stats

  1. 5  lib/B/C.pm
  2. 22  lib/B/CC.pm
5  lib/B/C.pm
@@ -810,6 +810,11 @@ sub nvx ($) {
810 810
   my $dblmax = "1.79769313486232e+308";
811 811
   # my $ldblmax = "1.18973149535723176502e+4932L"
812 812
   my $ll = $Config{d_longdbl} ? "LL" : "L";
  813
+  if ($nvgformat eq 'g') { # a very poor choice to keep precision
  814
+    # on intel 17-18, on ppc 31, on sparc64/s390 34
  815
+    # $nvgformat = $Config{d_longdbl} ? '.17Lg' : '.16g';
  816
+    $nvgformat = '.16g'; # typedef double NV
  817
+  }
813 818
   my $sval = sprintf("%${nvgformat}%s", $nvx, $nvx > $dblmax ? $ll : "");
814 819
   if ($nvx < -$dblmax) {
815 820
     $sval = sprintf("%${nvgformat}%s", $nvx, $ll);
22  lib/B/CC.pm
@@ -1041,10 +1041,10 @@ sub declare_pad {
1041 1041
     declare( "IV",
1042 1042
       $type == T_INT ? sprintf( "%s=0", $pad[$ix]->{iv} ) : $pad[$ix]->{iv} )
1043 1043
       if $pad[$ix]->save_int;
1044  
-    declare( "double",
  1044
+    declare( "NV",
1045 1045
       $type == T_DOUBLE
1046  
-      ? sprintf( "%s = 0", $pad[$ix]->{nv} )
1047  
-      : $pad[$ix]->{nv} )
  1046
+        ? sprintf( "%s = 0", $pad[$ix]->{nv} )
  1047
+        : $pad[$ix]->{nv} )
1048 1048
       if $pad[$ix]->save_double;
1049 1049
 
1050 1050
   }
@@ -1732,7 +1732,7 @@ sub numeric_binop {
1732 1732
         );
1733 1733
       }
1734 1734
       else {
1735  
-        my $rightruntime = B::Pseudoreg->new( "double", "rnv" );
  1735
+        my $rightruntime = B::Pseudoreg->new( "NV", "rnv" );
1736 1736
         runtime( sprintf( "$$rightruntime = %s;\t/* %s */", $right, $op->name ) );
1737 1737
         runtime(
1738 1738
           sprintf(
@@ -1754,8 +1754,8 @@ sub numeric_binop {
1754 1754
       $targ->set_int( &$operator( $$left, $$right ) );
1755 1755
     }
1756 1756
     else {
1757  
-      my $right = B::Pseudoreg->new( "double", "rnv" );
1758  
-      my $left  = B::Pseudoreg->new( "double", "lnv" );
  1757
+      my $right = B::Pseudoreg->new( "NV", "rnv" );
  1758
+      my $left  = B::Pseudoreg->new( "NV", "lnv" );
1759 1759
       runtime(
1760 1760
         sprintf( "$$right = %s; $$left = %s;\t/* %s */",
1761 1761
                  pop_numeric(), pop_numeric, $op->name ) );
@@ -1787,7 +1787,7 @@ sub pp_ncmp {
1787 1787
       runtime "}";
1788 1788
     }
1789 1789
     else {
1790  
-      my $rightruntime = B::Pseudoreg->new( "double", "rnv" );
  1790
+      my $rightruntime = B::Pseudoreg->new( "NV", "rnv" );
1791 1791
       runtime( sprintf( "$$rightruntime = %s;\t/* %s */", $right, $op->name ) );
1792 1792
       runtime sprintf( qq/if ("TOPn" > %s){/, $rightruntime );
1793 1793
       runtime sprintf("  sv_setiv(TOPs,1);");
@@ -1802,8 +1802,8 @@ sub pp_ncmp {
1802 1802
   }
1803 1803
   else {
1804 1804
     my $targ  = $pad[ $op->targ ];
1805  
-    my $right = B::Pseudoreg->new( "double", "rnv" );
1806  
-    my $left  = B::Pseudoreg->new( "double", "lnv" );
  1805
+    my $right = B::Pseudoreg->new( "NV", "rnv" );
  1806
+    my $left  = B::Pseudoreg->new( "NV", "lnv" );
1807 1807
     runtime(
1808 1808
       sprintf( "$$right = %s; $$left = %s;\t/* %s */",
1809 1809
                pop_numeric(), pop_numeric, $op->name ) );
@@ -1898,8 +1898,8 @@ sub bool_int_binop {
1898 1898
 # coverage: ?
1899 1899
 sub bool_numeric_binop {
1900 1900
   my ( $op, $operator ) = @_;
1901  
-  my $right = B::Pseudoreg->new( "double", "rnv" );
1902  
-  my $left  = B::Pseudoreg->new( "double", "lnv" );
  1901
+  my $right = B::Pseudoreg->new( "NV", "rnv" );
  1902
+  my $left  = B::Pseudoreg->new( "NV", "lnv" );
1903 1903
   runtime(
1904 1904
     sprintf( "$$right = %s; $$left = %s;\t/* %s */",
1905 1905
              pop_numeric(), pop_numeric(), $op->name ) );

0 notes on commit 3fc61aa

Please sign in to comment.
Something went wrong with that request. Please try again.