authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-08-03 20:53:56-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-08-03 21:04:04-04:00
log97ced1272df0236a01a72deaaf55e895f2bf62b0
treefb36416ab1472743f7e48e75ecbfa1357641652b
parent4b726207b8eb5a8a0605f3cc164ff0364733c31b

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.

1 files changed, 3 insertions(+), 3 deletions(-)

lib/std/math/float.zig+3-3
...@@ -112,17 +112,17 @@ pub fn FloatRepr(comptime Float: type) type {...@@ -112,17 +112,17 @@ pub fn FloatRepr(comptime Float: type) type {
112 /// This currently truncates denormal values, which needs to be fixed before this can be used to112 /// This currently truncates denormal values, which needs to be fixed before this can be used to
113 /// produce a rounded value.113 /// produce a rounded value.
114 pub fn reconstruct(normalized: Normalized, sign: std.math.Sign) Float {114 pub fn reconstruct(normalized: Normalized, sign: std.math.Sign) Float {
115 if (normalized.exponent > BiasedExponent.max_normal.unbias()) return @bitCast(Repr{115 if (normalized.exponent > comptime BiasedExponent.max_normal.unbias()) return @bitCast(Repr{
116 .mantissa = 0,116 .mantissa = 0,
117 .exponent = .infinite,117 .exponent = .infinite,
118 .sign = sign,118 .sign = sign,
119 });119 });
120 const mantissa = @as(Mantissa, 1 << fractional_bits) | normalized.fraction;120 const mantissa = @as(Mantissa, 1 << fractional_bits) | normalized.fraction;
121 if (normalized.exponent < BiasedExponent.min_normal.unbias()) return @bitCast(Repr{121 if (normalized.exponent < comptime BiasedExponent.min_normal.unbias()) return @bitCast(Repr{
122 .mantissa = @truncate(std.math.shr(122 .mantissa = @truncate(std.math.shr(
123 Mantissa,123 Mantissa,
124 mantissa,124 mantissa,
125 BiasedExponent.min_normal.unbias() - normalized.exponent,125 (comptime BiasedExponent.min_normal.unbias()) - normalized.exponent,
126 )),126 )),
127 .exponent = .denormal,127 .exponent = .denormal,
128 .sign = sign,128 .sign = sign,