Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect parsing of large hex float literals #2083

andrewrk opened this Issue Mar 21, 2019 · 1 comment


None yet
1 participant
Copy link

commented Mar 21, 2019


export fn entry() void {
    var f: f128 = 0x1.2eab345678439abcdefea56782346p+5;

const builtin = @import("builtin");
pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
    while (true) {}

zig build-obj test.zig --verbose-llvm-ir:

define void @entry() #2 !dbg !41 {
  %f = alloca fp128, align 16
  store fp128 0xL00000000000000004004000000000000, fp128* %f, align 16, !dbg !48
  call void @llvm.dbg.declare(metadata fp128* %f, metadata !45, metadata !DIExpression()), !dbg !48
  ret void, !dbg !49

here's a failing test:

const expect = @import("std").testing.expect;

test "aoeu" {
    var f1: f128 = 0x1.2eab345678439abcdefea56782346p+5;
    var f2: f128 = 0x1.2eab445678439abcdefea56782346p+5;
    expect(@bitCast(u128, f1) == 0x40042eab345678439abcdefea5678234);
    expect(f1 != f2);

@andrewrk andrewrk added the bug label Mar 21, 2019

@andrewrk andrewrk added this to the 0.4.0 milestone Mar 21, 2019

@andrewrk andrewrk added the stage1 label Mar 21, 2019


This comment has been minimized.

Copy link
Member Author

commented Mar 21, 2019

Seems to be a problem in src/tokenizer.cpp::end_float_token:

            int significand_magnitude_in_bin = 127 - bigint_clz(&t->significand, 128);
// signficand_magnitude_in_bin = 116
            const uint64_t shift = 112 - significand_magnitude_in_bin;
// shift = 18446744073709551612

I think that's not supposed to overflow.

@andrewrk andrewrk closed this in af509c6 Mar 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.