Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stringifying infinity #2112

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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
Loading