Skip to content

Replace decimal.Decimal with dual int64/float64 number representation#138

Merged
kaidesu merged 1 commit into1.0from
nervous-johnson
Apr 2, 2026
Merged

Replace decimal.Decimal with dual int64/float64 number representation#138
kaidesu merged 1 commit into1.0from
nervous-johnson

Conversation

@kaidesu
Copy link
Copy Markdown
Member

@kaidesu kaidesu commented Apr 2, 2026

Summary

  • Removes the shopspring/decimal dependency entirely
  • Replaces Ghost's single decimal.Decimal number type with a dual int64/float64 internal representation (Lua 5.3 style)
  • Integer operations stay int64; any operation involving a float promotes to float64
  • Division always produces a float (5 / 22.5, like Python 3)
  • floor() and round(0) return integers

Motivation

decimal.Decimal uses arbitrary-precision math backed by big.Int, meaning every number literal and every arithmetic result allocates on the heap. In game engine workloads (e.g. Lumen's tilemap renderer doing ~15,000 iterations/frame), this is the dominant performance bottleneck. float64 is more than sufficient for games, and a separate decimal module can be added later for financial/scientific precision when needed.

Changes

  • object/number.go — new Number struct with i int64, f float64, isFloat bool; constructors NewInt/NewFloat; arithmetic, comparison, and math methods
  • ast/number.goIntValue int64, FloatValue float64, IsFloat bool fields
  • parser/number.go — parses integers with strconv.ParseInt, floats (. or e) with strconv.ParseFloat
  • evaluator/ — updated number eval, postfix, prefix, index, for-in, assign
  • object/ — updated string, list, map, object helpers
  • library/modules/ — updated math, time, random, os
  • Tests updated throughout; all passing

Test plan

  • go test ./... passes

🤖 Generated with Claude Code

Removes the shopspring/decimal dependency and replaces all number
handling with a dual int64/float64 internal representation (Lua 5.3
style). Integer operations stay int64, float operations use float64,
and division always promotes to float (Python 3 style). This
eliminates the massive allocation overhead from arbitrary-precision
math in hot loops — the primary performance bottleneck for game
engine workloads in Lumen.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kaidesu kaidesu merged commit f20cf2a into 1.0 Apr 2, 2026
1 check passed
@kaidesu kaidesu deleted the nervous-johnson branch April 2, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant