operatorslist

package
v0.0.0-...-40e32b8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2022 License: BSD-2-Clause Imports: 4 Imported by: 0

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

func RPNOperatorsList(RPNInput string) float64

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL