mirror of
https://codeberg.org/scip/rpnc.git
synced 2025-12-17 04:21:01 +01:00
Internal/add gh actions and tests (#3)
* add gh actions and templates * add show-versions in Makefile * force go 1.20 * added test facilities
This commit is contained in:
45
calc.go
45
calc.go
@@ -20,7 +20,6 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -376,50 +375,6 @@ func (c *Calc) Debug(msg string) {
|
||||
}
|
||||
}
|
||||
|
||||
// do simple calculations
|
||||
func (c *Calc) simple(op byte) {
|
||||
c.stack.Backup()
|
||||
|
||||
for c.stack.Len() > 1 {
|
||||
b := c.stack.Pop()
|
||||
a := c.stack.Pop()
|
||||
var x float64
|
||||
|
||||
c.Debug(fmt.Sprintf("evaluating: %.2f %c %.2f", a, op, b))
|
||||
|
||||
switch op {
|
||||
case '+':
|
||||
x = a + b
|
||||
case '-':
|
||||
x = a - b
|
||||
case 'x':
|
||||
fallthrough // alias for *
|
||||
case '*':
|
||||
x = a * b
|
||||
case '/':
|
||||
if b == 0 {
|
||||
fmt.Println("error: division by null!")
|
||||
return
|
||||
}
|
||||
x = a / b
|
||||
case '^':
|
||||
x = math.Pow(a, b)
|
||||
default:
|
||||
panic("invalid operator!")
|
||||
}
|
||||
|
||||
c.stack.Push(x)
|
||||
|
||||
c.History("%f %c %f = %f", a, op, b, x)
|
||||
|
||||
if !c.batch {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
c.Result()
|
||||
}
|
||||
|
||||
func (c *Calc) luafunc(funcname string) {
|
||||
// called from calc loop
|
||||
var x float64
|
||||
|
||||
Reference in New Issue
Block a user