Feature/add converters and bitwise ops (#20)

* added:

- converters
- bitwise operators
- hex input and output support
This commit is contained in:
T.v.Dein
2023-11-13 15:51:07 +01:00
committed by GitHub
parent 127483eea1
commit 59241932e0
7 changed files with 176 additions and 3 deletions

11
calc.go
View File

@@ -62,6 +62,8 @@ const Help string = `
Operators:
basic operators: + - x * / ^ (* is an alias of x)
Bitwise operators: and or xor < (left shift) > (right shift)
Percent functions:
% percent
%- substract percent
@@ -235,6 +237,15 @@ func (c *Calc) Eval(line string) {
c.stack.Backup()
c.stack.Push(num)
} else {
// try hex
var i int
_, err := fmt.Sscanf(item, "0x%x", &i)
if err == nil {
c.stack.Backup()
c.stack.Push(float64(i))
continue
}
if contains(c.Constants, item) {
// put the constant onto the stack
c.stack.Backup()