diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2023-07-28 20:52:03 -0230 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2023-07-28 20:52:03 -0230 |
| commit | 9dae90cfdc1a4cb5f42e9a533a2277a3904b629f (patch) | |
| tree | 2dbc7ccedd6567c8e1c03479056cdfb0073e1a58 | |
| parent | 3516ab494570f077df967bfe1222acc0dfcdf5da (diff) | |
| download | pfc-9dae90cfdc1a4cb5f42e9a533a2277a3904b629f.zip | |
exponentiation operator
| -rw-r--r-- | calculator.go | 3 | ||||
| -rw-r--r-- | ui.go | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/calculator.go b/calculator.go index d2371b7..fb1fc90 100644 --- a/calculator.go +++ b/calculator.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "math" "strconv" ) @@ -58,6 +59,8 @@ func parseOp(op byte) (func(lhs *float64, rhs float64), error) { *lhs = float64(int64(*lhs) % int64(rhs)) } }, nil + case '^': + return func(lhs *float64, rhs float64) { *lhs = math.Pow(*lhs, rhs) }, nil } return nil, OpError{op} } @@ -37,7 +37,7 @@ func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg.String() { case "ctrl+c", "Q": return ui, tea.Quit - case "+", "-", "*", "/", "%": + case "+", "-", "*", "/", "%", "^": if err := ui.calc.performOp(msg.String()[0]); err != nil { panic(err) } |