release 1.11.2
[descalc.git] / 32_math.pm
similarity index 73%
rename from 31_math.pm
rename to 32_math.pm
index dd4d7d8f5a247fcee933896017e3b0d93f4d0140..96447e1ff44a360d91133feb6b652b1b0fb349a1 100644 (file)
@@ -1,16 +1,23 @@
 # math for DCT, by Shiar
 
-# 1.09.1 200410022255 - moved from 1.9 main
+# 1.10.4 200410282330 - trig functions from basic menu
+# 1.10.3 200410152245 - rnd, atan, pi
+#                     - trigonometry functions seperated
+# 1.10.2 200410132050 - probability functions: comb, perm, rdz
+# 1.10.1 200410112340 - adds menu items via addmenu() call
 # 1.09.2 200410112050 - functions don't handle stack themselves,
 #                       but behave like real functions
-# 1.10.1 200410112340 - adds menu items via addmenu() call
-#     .2 200410132050 - probability functions: comb, perm, rdz
+# 1.09.1 200410022255 - moved from 1.9 main
+
+#todo: check for errors, eg division by zero
 
 use strict;
 use warnings;
 use utf8;
 
-my %newaction = (
+%action = (
+       %action,
+
        '+'    => [2, sub { $_[1] + $_[0] }], # addition
        '-'    => [2, sub { $_[1] - $_[0] }], # substraction
        '*'    => [2, sub { $_[1] * $_[0] }], # multiplication
@@ -31,21 +38,6 @@ my %newaction = (
        'exp'  => [1, sub { exp $_[0] }], # e^x
        'expm' => [1, sub { exp($_[0]) - 1 }], # exp(x)-1
 
-       # hyperbolic
-       'sin'  => [1, sub { sin $_[0] }], # sine
-       'asin' => [1, sub { atan2($_[0], sqrt(1 - $_[0]*$_[0])) }], # inverse sine
-       'cos'  => [1, sub { cos $_[0] }], # cosine
-       'acos' => [1, sub { atan2(sqrt(1 - $_[0]*$_[0]), $_[0]) }], # inverse cosine
-       'tan'  => [1, sub { sin($_[0]) / cos($_[0]) }], # tangent
-#      'atan' => [1, sub { }], # arctangent
-
-       'sinh' => [1, sub { (exp($_[0]) - exp(-$_[0])) / 2 }], # hyperbolic sine
-       'cosh' => [1, sub { (exp($_[0]) + exp(-$_[0])) / 2 }], # hyperbolic cosine
-       'tanh' => [1, sub { (exp($_[0]) - exp(-$_[0])) / (exp($_[0]) + exp(-$_[0])) }], # hyperbolic tangent (sinh/cosh)
-       'asinh'=> [1, sub { log(sqrt($_[0]**2+1) + $_[0]) }], # inverse hyperbolic sine
-       'acosh'=> [1, sub { log(sqrt($_[0]**2-1) + $_[0]) }], # inverse hyperbolic cosine
-       'atanh'=> [1, sub { log((1+$_[0]) / (1-$_[0])) / 2 }], # inverse hyperbolic tangent
-
        # binary
        'and'  => [2, sub { $_[1] & $_[0] }], # bitwise and
        'or'   => [2, sub { $_[1] | $_[0] }], # bitwise or
@@ -59,12 +51,12 @@ my %newaction = (
 #      '%ch'  => [2, sub { $val{i} = 100*(shift(@_)-$val{i})/$val{i} }], # percentage change
 #      '%t'   => [2, sub { $val{i} = 100*$val{i}/shift(@_) }], # percentage total
 
-       'abs'  => [1, sub { abs $_[0] }], # absolute #todo
+       'abs'  => [1, sub { abs $_[0] }], # absolute
        'sign' => [1, sub { $_[0] <=> 0 }], # sign
        'ip'   => [1, sub { int $_[0] }], # integer part
        'fp'   => [1, sub { $_[0] - int $_[0] }], # fractional part
 
-#      'rnd'  => [1, sub { local $_ = 10**$_[0]; $val{i} = int(($val{i}+.5)*$_)/$_ }], # round
+       'rnd'  => [1, sub { sprintf "%.0f", $_[0] }], # round
 #      'trnc' => [1, sub { local $_ = 10**$_[0]; $val{i} = int($val{i}*$_)/$_ }], # truncate
        'floor'=> [1, sub { int $_[0] }], # floor
        'ceil' => [1, sub { int $_[0]+.9999 }], # ceil
@@ -101,15 +93,12 @@ my %newaction = (
 #      'utpf' => [3], # F distribution
 ); # newaction
 
-#while (my ($cmd, $val) = each %newaction) {$action{$cmd} = $val}
-$action{$_} = $newaction{$_} for keys %newaction;
-
 addmenu(["main", 0], "math",
-       [qw(basic log alog ln exp sin cos tan asin acos atan sq sqrt ^ xroot)],
+       [qw(basic sq sqrt ^ xroot log alog ln exp)],
 #      [qw(vector)],
 #      [qw(matrix)],
 #      [qw(list)],
-       [qw(hyperbolic sinh cosh tanh asinh acosh atanh expm lnp1)],
+#      [qw(hyperbolic sinh cosh tanh asinh acosh atanh expm lnp1)],
        [qw(real % %ch %t min max mod abs sign mant xpon ip fp rnd trnc floor ceil r>d d>r)],
        [qw(base dec bin oct hex),
                [qw(logic and or xor not)],
@@ -125,6 +114,6 @@ addmenu(["main", 0], "math",
 return {
        author  => "Shiar",
        title   => "basic math",
-       version => "1.10.2",
+       version => "1.10.4",
 };