From 97ced1272df0236a01a72deaaf55e895f2bf62b0 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Mon, 3 Aug 2026 20:53:56 -0400 Subject: [PATCH] std.math.float: evaluate some constants at comptime QEMU can mistranslate this code, but since it can be evaluated at comptime anyway, force comptime eval as both a workaround for the mistranslation and because it is a desirable change anyway. --- lib/std/math/float.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/math/float.zig b/lib/std/math/float.zig index 4bc67d494abac15c21e791f15fc56802e0fb87b8..e84bcdc4f295e1edad123673991df5b85f1cea4c 100644 --- a/lib/std/math/float.zig +++ b/lib/std/math/float.zig @@ -112,17 +112,17 @@ pub fn FloatRepr(comptime Float: type) type { /// This currently truncates denormal values, which needs to be fixed before this can be used to /// produce a rounded value. pub fn reconstruct(normalized: Normalized, sign: std.math.Sign) Float { - if (normalized.exponent > BiasedExponent.max_normal.unbias()) return @bitCast(Repr{ + if (normalized.exponent > comptime BiasedExponent.max_normal.unbias()) return @bitCast(Repr{ .mantissa = 0, .exponent = .infinite, .sign = sign, }); const mantissa = @as(Mantissa, 1 << fractional_bits) | normalized.fraction; - if (normalized.exponent < BiasedExponent.min_normal.unbias()) return @bitCast(Repr{ + if (normalized.exponent < comptime BiasedExponent.min_normal.unbias()) return @bitCast(Repr{ .mantissa = @truncate(std.math.shr( Mantissa, mantissa, - BiasedExponent.min_normal.unbias() - normalized.exponent, + (comptime BiasedExponent.min_normal.unbias()) - normalized.exponent, )), .exponent = .denormal, .sign = sign, -- 2.54.0