Repository navigation
fix(mathlib): define math.huge as positive infinity - #90
Merged
Merged
Conversation
math.huge was math.MaxFloat64, so math.huge ~= 1/0, math.huge * 2 ~= math.huge and values above DBL_MAX compared greater than math.huge. Lua defines math.huge as HUGE_VAL, which is +inf.
skhaz
approved these changes
Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Defect
math.hugeismath.MaxFloat64instead of+inf:Code that uses
math.hugeas an unbounded limit (x < math.huge,math.minseeds,-math.hugesentinels) misbehaves for values that overflow to infinity.Cause
OpenMathsetshugetoLNumber(math.MaxFloat64). Lua defines it asHUGE_VAL.Fix
math.hugeisLNumber(math.Inf(1)). Nothing else depends on the old value: the stdlib type isnumber, and no constant folding or serialization path special-cases it.Tests
mathlib_huge_test.gochecks thatmath.hugeis+Infand a float, its equality with1/0and-1/0, arithmetic saturation, ordering againstDBL_MAX, NaN frommath.huge - math.huge,math.max/math.min, and numericforloops withmath.hugeand-math.hugelimits. It fails onmain.Verification
go vet ./...,golangci-lintv2.8.0 with the CI flags,go test ./...(full fixture corpus), the coverage collector run, and the race "other" shard (go test -raceon all non-fixture tests and the non-regression fixture categories) pass. The regression-fixture race shards are left to CI.tostring(math.huge)now prints+Inf, the same astostring(1/0)already does; the float spelling inLNumber.Stringis a separate, known difference.The runtime picks this up through a go-lua dependency bump after merge.