commit a64989ee704255f61639c9714c5a38b4d6eb0a9e (tree)
parent ec58ddf46c4e1ac060333c6d0780955acae22442
Author: Marc Tiehuis <marc@tiehu.is>
Date: Sat, 15 Jan 2022 02:52:34 +1300
stage1: fix bigint_init_bigfloat for single-limb negative floats
Fixes #10592.
Diffstat:
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/stage1/bigint.cpp b/src/stage1/bigint.cpp
@@ -219,7 +219,7 @@ void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {
ui64_to_f128M(UINT64_MAX, &max_u64);
if (f128M_le(&abs_val, &max_u64)) {
dest->digit_count = 1;
- dest->data.digit = f128M_to_ui64(&op->value, softfloat_round_minMag, false);
+ dest->data.digit = f128M_to_ui64(&abs_val, softfloat_round_minMag, false);
bigint_normalize(dest);
return;
}
diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig
@@ -66,3 +66,9 @@ fn testDifferentSizedFloatComparisons() !void {
// try expect(@nearbyint(a) == -4);
// }
//}
+
+test "negative f128 floatToInt at compile-time" {
+ const a: f128 = -2;
+ var b = @floatToInt(i64, a);
+ try expect(@as(i64, -2) == b);
+}