Skip to content

Commit

Permalink
Fix bug where 2^63 incorrectly converted into long
Browse files Browse the repository at this point in the history
  • Loading branch information
Kan18 committed Oct 6, 2024
1 parent f592f7d commit ea12430
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/squiddev/cobalt/LuaDouble.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public String toString() {
@Override
public LuaString checkLuaString() {
long l = (long) v;
if (l == v) return ValueFactory.valueOf(Long.toString(l));
if (l == v && l != Long.MAX_VALUE) return ValueFactory.valueOf(Long.toString(l));
if (Double.isNaN(v)) return STR_NAN;
if (Double.isInfinite(v)) return v < 0 ? STR_NEGINF : STR_POSINF;

Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/spec/base_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ describe("The base library", function()
expect('' .. 12):eq('12') expect(12.0 .. ''):eq('12')
expect(tostring(-1203 + 0.0)):eq("-1203")
end)

it("correctly handles 2^63", function()
expect(tostring(math.floor(2^63))):not_equals("9223372036854775807")
end)
end)

it("tables", function() expect(tostring {}):str_match('^table:') end)
Expand Down

0 comments on commit ea12430

Please sign in to comment.