Add functions sin, cos, tan, exp and constant e

This commit is contained in:
Peter J. Holzer 2017-07-21 12:15:15 +02:00
parent 0f0027d73c
commit ada378e290
1 changed files with 14 additions and 0 deletions

14
rpn
View File

@ -43,6 +43,20 @@ while (<>) {
} elsif (m{^ld$}) { } elsif (m{^ld$}) {
my $x = pop @stack; my $x = pop @stack;
push @stack, log($x) / log(2); push @stack, log($x) / log(2);
} elsif (m{^sin$}) {
my $x = pop @stack;
push @stack, sin($x);
} elsif (m{^cos$}) {
my $x = pop @stack;
push @stack, cos($x);
} elsif (m{^tan$}) {
my $x = pop @stack;
push @stack, tan($x);
} elsif (m{^e$}) {
push @stack, exp(1);
} elsif (m{^exp$}) {
my $x = pop @stack;
push @stack, exp($x);
} elsif (m{^0x[0-9a-fA-F]+$}) { } elsif (m{^0x[0-9a-fA-F]+$}) {
no warnings 'portable'; no warnings 'portable';
push @stack, hex($_); push @stack, hex($_);