From ada378e290e7f0ec8883878d0aeaef2c62571920 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Fri, 21 Jul 2017 12:15:15 +0200 Subject: [PATCH] Add functions sin, cos, tan, exp and constant e --- rpn | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rpn b/rpn index 927db1f..e8ed2f4 100755 --- a/rpn +++ b/rpn @@ -43,6 +43,20 @@ while (<>) { } elsif (m{^ld$}) { my $x = pop @stack; 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]+$}) { no warnings 'portable'; push @stack, hex($_);