cyber
cyber copied to clipboard
`nan_f64` compilation errors with latest Zig
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});
}
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.