[gnumeric] process-amath: filter cases we don't want.



commit 18aefa6554b8ae53a7517bf616e7a62669dd40e4
Author: Morten Welinder <terra gnome org>
Date:   Fri Nov 1 20:09:10 2013 -0400

    process-amath: filter cases we don't want.

 samples/amath.gnumeric |  Bin 39480 -> 38239 bytes
 tools/process-amath.pl |   52 ++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 48 insertions(+), 4 deletions(-)
---
diff --git a/samples/amath.gnumeric b/samples/amath.gnumeric
index 7bd084a..09ab5bf 100644
Binary files a/samples/amath.gnumeric and b/samples/amath.gnumeric differ
diff --git a/tools/process-amath.pl b/tools/process-amath.pl
index 6b4cd5c..9893b1f 100755
--- a/tools/process-amath.pl
+++ b/tools/process-amath.pl
@@ -5,6 +5,8 @@
 
 use strict;
 
+my $debug_underflow = 0;
+my $debug_arguments = 1;
 my $dir = $ARGV[0];
 
 my @test_files =
@@ -92,7 +94,12 @@ sub def_expr_handler {
 }
 
 my %expr_handlers =
-    ('r.dcauchy' => sub { &reorder_handler ("3,1,2", @_); },
+    ('beta' => \&non_negative_handler,
+     'gammaln' => \&non_negative_handler,
+     'factdouble' => \&non_negative_handler,
+     'pochhammer' => \&positive_handler, # We shouldn't need this
+     'combin' => \&non_negative_handler,
+     'r.dcauchy' => sub { &reorder_handler ("3,1,2", @_); },
      'r.pcauchy' => sub { &reorder_handler ("3,1,2", @_); },
      'r.qcauchy' => sub { &reorder_handler ("3,1,2", @_); },
      'r.dchisq' => sub { &reorder_handler ("2,1", @_); },
@@ -166,6 +173,18 @@ sub output_test {
 
 # -----------------------------------------------------------------------------
 
+sub interpret_number {
+    my ($s) = @_;
+
+    if ($s =~ /^[-+]?(\d+\.?|\d*\.\d+)([eE][-+]?\d+)?$/) {
+       return $s;
+    } else {
+       return undef;
+    }
+}
+
+# -----------------------------------------------------------------------------
+
 sub reorder_handler {
     my ($order,$f,$pargs) = @_;
 
@@ -177,6 +196,29 @@ sub reorder_handler {
     return &def_expr_handler ($f,\ res);
 }
 
+sub non_negative_handler {
+    my ($f,$pargs) = @_;
+
+    foreach (@$pargs) {
+       my $x = &interpret_number ($_);
+       print STDERR "$_ -> $x\n";
+       return undef unless defined ($x) && $x >= 0;
+    }    
+
+    return &def_expr_handler ($f,$pargs);
+}
+
+sub positive_handler {
+    my ($f,$pargs) = @_;
+
+    foreach (@$pargs) {
+       my $x = &interpret_number ($_);
+       return undef unless defined ($x) && $x > 0;
+    }    
+
+    return &def_expr_handler ($f,$pargs);
+}
+
 # -----------------------------------------------------------------------------
 
 sub simplify_val {
@@ -193,14 +235,16 @@ sub simplify_val {
     $val =~ s/\bldexp\s*\(\s*([-+.eE0-9_]+)\s*[,;]\s*([-+]?\d+)\s*\)/($1*2^$2)/g;
 
     if ($val =~ m{^[-+*/^() .eE0-9]+$}) {
-       print STDERR "ZZZ:$val\n" if $val =~ /^[-+]?[0-9.]+[eE][-+]?\d+$/ && $val == 0;
-       return 0 if $val =~ /^[-+]?[0-9.]+[eE][-+]?\d+$/ && $val == 0;
+       if ($val =~ /^[-+]?[0-9.]+[eE][-+]?\d+$/ && $val == 0) {
+           print STDERR "DEBUG: $val --> 0\n" if $debug_underflow;
+           return 0;
+       }
 
        return $val;
     } elsif (exists $pvars->{$val}) {
        return $pvars->{$val};
     } else {
-       print STDERR "XXX:[$val]\n";
+       print STDERR "DEBUG: Argument $val unresolved.\n" if $debug_arguments;
        return undef;
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]