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:
T.v.Dein
2023-11-06 16:09:56 +01:00
committed by GitHub
parent 2b79f3f9ca
commit b5430403fd
11 changed files with 470 additions and 64 deletions

45
calc.go
View File

@@ -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