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

nan_f64 compilation errors with latest Zig #62

Open
moderation opened this issue Aug 27, 2023 · 1 comment
Open

nan_f64 compilation errors with latest Zig #62

moderation opened this issue Aug 27, 2023 · 1 comment

Comments

@moderation
Copy link

Trying to build from the latest I hit an error

Build Summary: 3/6 steps succeeded; 1 failed (disable with --summary none)
cli transitive failure
├─ zig build-exe cyber ReleaseFast native 1 errors
└─ install cyber transitive failure
   └─ zig build-exe cyber ReleaseFast native (+3 more reused dependencies)
/home/<username>/Library/zig/ziglang/lib/std/math.zig:93:21: error: Deprecated: use `nan(f64)` instead
pub const nan_f64 = @compileError("Deprecated: use `nan(f64)` instead");
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This fixed it. Happy to create a PR if this is the right approach.

diff --git a/src/builtins/math.zig b/src/builtins/math.zig
index 7b232cc..ddd6c08 100644
--- a/src/builtins/math.zig
+++ b/src/builtins/math.zig
@@ -25,7 +25,7 @@ pub fn initModule(c: *cy.VMcompiler, modId: cy.ModuleId) anyerror!void {
     try b.setVar("ln2", bt.Number, Value.initF64(std.math.ln2));

     // Not a number.
-    try b.setVar("nan", bt.Number, Value.initF64(-std.math.nan_f64));
+    try b.setVar("nan", bt.Number, Value.initF64(-std.math.nan(f64)));

     // Neg infinity.
     try b.setVar("neginf", bt.Number, Value.initF64(-std.math.inf(f64)));
diff --git a/src/vm.zig b/src/vm.zig
index cdba9b7..cb945cb 100644
--- a/src/vm.zig
+++ b/src/vm.zig
@@ -3403,7 +3403,7 @@ fn evalLoop(vm: *VM) linksection(cy.HotSection) error{StackOverflow, OutOfMemory
                 const left = framePtr[pc[1].arg];
                 const right = framePtr[pc[2].arg];
                 if (Value.bothNumbers(left, right)) {
-                    framePtr[pc[3].arg] = Value.initF64(std.math.mod(f64, left.asF64(), right.asF64()) catch std.math.nan_f64);
+                    framePtr[pc[3].arg] = Value.initF64(std.math.mod(f64, left.asF64(), right.asF64()) catch std.math.nan(f64));
                 } else {
                     return @call(.never_inline, panicExpectedNumber, .{vm});
                 }
@fubark
Copy link
Owner

fubark commented Aug 27, 2023

I've tried to keep it updated with Zig latest for awhile now and I think it's been more trouble than it's worth. So going forward we're just going to track Zig releases (currently 0.11). It's easy to keep different versions of Zig with marler8997/zigup.

Thanks for the fix though! Let's keep the issue open in case others find it useful.

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

No branches or pull requests

2 participants