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

Casts are omitted when casting floating point and integers #86

Closed
Marcono1234 opened this issue Jan 16, 2020 · 1 comment
Closed

Casts are omitted when casting floating point and integers #86

Marcono1234 opened this issue Jan 16, 2020 · 1 comment

Comments

@Marcono1234
Copy link
Contributor

CFR version

0.149-SNAPSHOT (commit 22b3529)

Compiler

javac 11.0.5

Description

Some necessary casts are omitted when casting values to floating point and integer types.

Source:

class FloatingPointCasting {
    long getLong() {
        return 9223372036854775806L;
    }
    
    void test() {
        long b = (long) (double) getLong();
        System.out.println(b == getLong()); // Prints "false"
    }
    
    public static void main(String ... args) {
        new FloatingPointCasting().test();
    }
}

Decompiled output:

class FloatingPointCasting {
    FloatingPointCasting() {
    }

    long getLong() {
        return 0x7FFFFFFFFFFFFFFEL;
    }

    void test() {
        long l = this.getLong();
        System.out.println(l == this.getLong());
    }

    public static void main(String ... arrstring) {
        new CharCasting().test();
    }
}
@leibnitz27
Copy link
Owner

Damn. You're on form this week. I can't keep up. ;)

It's fun to notice that constant folding means this isn't always an issue (see https://github.com/leibnitz27/cfr_tests/blob/master/src_6/org/benf/cfr/tests/FloatingPointCasting2.java )

Anyway, fixed ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants