changed layout

This commit is contained in:
Grimsace
2026-02-10 08:49:31 -06:00
parent 547638f38d
commit 0693bc02fb
2 changed files with 62 additions and 33 deletions
+29
View File
@@ -2,6 +2,7 @@ package main
import (
"fmt"
"math"
"math/rand"
"regexp"
"sort"
@@ -233,6 +234,34 @@ func (p *parser) parseTerm() (float64, error) {
// parseFactor handles parentheses and unary operators (highest precedence)
func (p *parser) parseFactor() (float64, error) {
left, err := p.parsePower()
if err != nil {
return 0, err
}
for {
p.skipWhitespace()
if p.pos >= len(p.expr) {
break
}
if p.expr[p.pos] == '^' {
p.pos++
right, err := p.parseFactor()
if err != nil {
return 0, err
}
left = math.Pow(left, right)
} else {
break
}
}
return left, nil
}
// parsePower handles parentheses and unary operators
func (p *parser) parsePower() (float64, error) {
p.skipWhitespace()
if p.pos >= len(p.expr) {