From 7b9b0469cbc1d1e9926fd53b973957f1e35f737c Mon Sep 17 00:00:00 2001 From: InKryption <59504965+InKryption@users.noreply.github.com> Date: Sat, 27 Nov 2021 06:03:15 +0100 Subject: [PATCH] glfw: un-hardcode constant Make the constant extracted from GLFW source into `time.setTime`, into a better-documented set of comptime instructions --- glfw/src/time.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/glfw/src/time.zig b/glfw/src/time.zig index 02a01ba7..e1435e20 100644 --- a/glfw/src/time.zig +++ b/glfw/src/time.zig @@ -58,9 +58,11 @@ pub inline fn setTime(time: f64) void { std.debug.assert(!std.math.isNan(time)); std.debug.assert(time >= 0); - // TODO: Look into why GLFW uses this hardcoded float literal as the maximum valid value for 'time'. - // Maybe propose upstream to name this constant. - std.debug.assert(time <= 18446744073.0); + // assert time is lteq to largest number of seconds representable by u64 with nanosecond precision + std.debug.assert(time <= max_time: { + const @"2^64" = std.math.maxInt(u64); + break :max_time @divTrunc(@"2^64", std.time.ns_per_s); + }); c.glfwSetTime(time); getError() catch |err| return switch (err) {