Skip to content

Commit

Permalink
Fix stringifying infinity (#2112)
Browse files Browse the repository at this point in the history
Co-authored-by: ike709 <[email protected]>
  • Loading branch information
ike709 and ike709 authored Dec 1, 2024
1 parent b9bfd6a commit 610688c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

/proc/RunTest()
var/a = 1#INF
var/b = -1#INF
var/c = -1#IND
ASSERT("[a]" == "inf")
ASSERT("[b]" == "-inf")
ASSERT("[c]" == "nan")
7 changes: 7 additions & 0 deletions OpenDreamRuntime/DreamValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ public string Stringify() {
case DreamValueType.Float:
var floatValue = MustGetValueAsFloat();

if (float.IsInfinity(floatValue)) {
var str = float.IsPositiveInfinity(floatValue) ? "inf" : "-inf";
return str;
}

if (floatValue > 16777216f) {
return floatValue.ToString("g6");
}
Expand All @@ -371,6 +376,8 @@ public string Stringify() {
return floatValue.ToString("g8");
}

if (float.IsNaN(floatValue)) return "nan";

return floatValue.ToString("g6");

case DreamValueType.DreamResource:
Expand Down

0 comments on commit 610688c

Please sign in to comment.