diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-11 20:53:58 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-11 20:53:58 +0300 |
| commit | 4465f7abdc72887a422b2ddd9afc43ee811b2e9b (patch) | |
| tree | 98182a806c34607810c97d832b1d0b3f2766267b /internal/rpn/variable.go | |
| parent | ead2412b0f0d23b2cfc3b265a3dae8841f8c84f7 (diff) | |
Refactor number.go to return errors instead of panicking
- Changed Number interface methods to return errors instead of panicking
- Float64() now returns (float64, error)
- Add, Sub, Mul, Pow, Compare, Bool() now return (Number, error) or (int, error)
- StringNum and Symbol now return errors for unsupported operations
- Added IsString() and IsSymbol() to Number interface
- Removed unused arithmetic.go file
- Updated operations.go, boolean_ops.go, hyper.go to handle errors
- Added constants registry (internal/rpn/constants.go) with built-in math constants
- Added constants_test.go with comprehensive unit tests
- Updated README.md with constants documentation
Diffstat (limited to 'internal/rpn/variable.go')
| -rw-r--r-- | internal/rpn/variable.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/internal/rpn/variable.go b/internal/rpn/variable.go index f3302df..6bde73d 100644 --- a/internal/rpn/variable.go +++ b/internal/rpn/variable.go @@ -26,7 +26,11 @@ func (o *VariableOperations) AssignVariable(stack *Stack, name string) error { } // Convert Number to float64 for variable storage - return o.vars.SetVariable(name, val.Float64()) + valF, err := val.Float64() + if err != nil { + return fmt.Errorf("failed to get float64 value for variable: %w", err) + } + return o.vars.SetVariable(name, valF) } // UseVariable pushes a variable's value onto the stack. |
