From 2b79f3f9cabc9d97f6385940072cc10f380ef626 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Sun, 5 Nov 2023 17:39:15 +0100 Subject: [PATCH] updated docs --- calc.go | 30 +++++++++++++++++++----------- rpn.go | 34 +++++++++++++++++++++++++--------- rpn.pod | 34 +++++++++++++++++++++++++--------- 3 files changed, 69 insertions(+), 29 deletions(-) diff --git a/calc.go b/calc.go index 14d8e89..be15743 100644 --- a/calc.go +++ b/calc.go @@ -56,22 +56,26 @@ history display calculation history help|? show this message quit|exit|c-d|c-c exit program -Available operators: -basic operators: + - x / +Operators: +basic operators: + - x * / ^ (* is an alias of x) -Available math functions: -sqrt square root -mod remainder of division (alias: remainder) -max batch mode only: max of all values -min batch mode only: min of all values -mean batch mode only: mean of all values (alias: avg) -median batch mode only: median of all values +Percent functions: % percent %- substract percent %+ add percent -Math operators: -^ power` +Math functions (see https://pkg.go.dev/math): +mod sqrt abs acos acosh asin asinh atan atan2 atanh cbrt ceil cos cosh +erf erfc erfcinv erfinv exp exp2 expm1 floor gamma ilogb j0 j1 log +log10 log1p log2 logb pow round roundtoeven sin sinh tan tanh trunc y0 +y1 copysign dim hypot + +Batch functions: +sum sum of all values (alias: +) +max max of all values +min min of all values +mean mean of all values (alias: avg) +median median of all values` // commands, constants and operators, defined here to feed completion // and our mode switch in Eval() dynamically @@ -295,6 +299,10 @@ func (c *Calc) DoFuncall(funcname string) error { function = c.Funcalls[funcname] } + if function == nil { + panic("function not defined but in completion list") + } + var args Numbers batch := false diff --git a/rpn.go b/rpn.go index 648a79e..1441cdb 100644 --- a/rpn.go +++ b/rpn.go @@ -116,20 +116,36 @@ DESCRIPTION You can use the shift command to remove the last number from the stack. BUILTIN OPERATORS AND FUNCTIONS - Basic operators: + - x / + Basic operators: - Math functions: + + add + - substract + / divide + x multiply (alias: *) + ^ power + + Percent functions: - sqrt square root - mod remainder of division (alias: remainder) - max batch mode only: max of all values - min batch mode only: min of all values - mean batch mode only: mean of all values (alias: avg) - median batch mode only: median of all values % percent %- substract percent %+ add percent - ^ power + + Batch functions: + + sum sum of all values (alias: +) + max max of all values + min min of all values + mean mean of all values (alias: avg) + median median of all values + + Math functions: + + mod sqrt abs acos acosh asin asinh atan atan2 atanh cbrt ceil cos cosh + erf erfc erfcinv erfinv exp exp2 expm1 floor gamma ilogb j0 j1 log + log10 log1p log2 logb pow round roundtoeven sin sinh tan tanh trunc y0 + y1 copysign dim hypot + + Refer to https://pkg.go.dev/math for details about those functions. EXTENDING RPN USING LUA You can use a lua script with lua functions to extend the calculator. By diff --git a/rpn.pod b/rpn.pod index 994695f..d37e285 100644 --- a/rpn.pod +++ b/rpn.pod @@ -123,20 +123,36 @@ stack. =head2 BUILTIN OPERATORS AND FUNCTIONS -Basic operators: + - x / +Basic operators: -Math functions: + + add + - substract + / divide + x multiply (alias: *) + ^ power + +Percent functions: - sqrt square root - mod remainder of division (alias: remainder) - max batch mode only: max of all values - min batch mode only: min of all values - mean batch mode only: mean of all values (alias: avg) - median batch mode only: median of all values % percent %- substract percent %+ add percent - ^ power + +Batch functions: + + sum sum of all values (alias: +) + max max of all values + min min of all values + mean mean of all values (alias: avg) + median median of all values + +Math functions: + + mod sqrt abs acos acosh asin asinh atan atan2 atanh cbrt ceil cos cosh + erf erfc erfcinv erfinv exp exp2 expm1 floor gamma ilogb j0 j1 log + log10 log1p log2 logb pow round roundtoeven sin sinh tan tanh trunc y0 + y1 copysign dim hypot + +Refer to https://pkg.go.dev/math for details about those functions. =head1 EXTENDING RPN USING LUA