Commit d04a1456df

Andrew Kelley <andrew@ziglang.org>
2019-03-21 21:35:18
hex float parsing: solve another case
this works now: 0x1.edcb34a235253948765432134674fp-1
1 parent af509c6
Changed files (2)
src
test
stage1
behavior
src/tokenizer.cpp
@@ -365,6 +365,9 @@ static void end_float_token(Tokenize *t) {
                 bigint_init_unsigned(&shift_bigint, -shift);
                 BigInt shifted_significand;
                 bigint_shr(&shifted_significand, &t->significand, &shift_bigint);
+                if (t->exponent_in_bin_or_dec == -1) {
+                    bigint_incr(&shifted_significand);
+                }
                 bigint_write_twos_complement(&shifted_significand, (uint8_t*) f_bits.repr, 128, false);
             } else {
                 uint64_t sig_bits[2] = {0, 0};
test/stage1/behavior/math.zig
@@ -310,8 +310,14 @@ test "quad hex float literal parsing accurate" {
 
     const S = struct {
         fn doTheTest() void {
-            var f1: f128 = 0x1.2eab345678439abcdefea56782346p+5;
-            expect(@bitCast(u128, f1) == 0x40042eab345678439abcdefea5678234);
+            {
+                var f1: f128 = 0x1.2eab345678439abcdefea56782346p+5;
+                expect(@bitCast(u128, f1) == 0x40042eab345678439abcdefea5678234);
+            }
+            {
+                var f: f128 = 0x1.edcb34a235253948765432134674fp-1;
+                expect(@bitCast(u128, f) == 0x3ffeedcb34a235253948765432134675);
+            }
             const exp2ft = []f64{
                 0x1.6a09e667f3bcdp-1,
                 0x1.7a11473eb0187p-1,