Documentation
¶
Overview ¶
Package operatorslist implements postfix calculator in two loops by editing the string containing the calculation.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RPNOperatorsList ¶
RPNOperatorsList returns the result of a string in reverse polish notation (postfix) by exploding the string to a slice and editing the slice. Each iteration replaces an operation by its result until only a number is left.
If the expression is invalid, it fails failing if the expression is invalid. An invalid sign is interpreted as a value and the next operation panics.
A list of authorized operators is kept to find the fist one in the list. The expression is kept in a string.
Multiple conversions to test the validity of the expression is lowering efficiency. Removing subroutines has no visible impact here.
Example ¶
if fmt.Print has an output (debug mode)
fmt.Printf("%f", RPNOperatorsList(values.RPNInput))
Output: 30.000000
Example (Exp) ¶
fmt.Printf("%.13f", RPNOperatorsList(values.Input))
Output: 3.0001220703125
Types ¶
This section is empty.