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

Fix constant folding of division and reminder with zero divisor #2797

Merged
merged 1 commit into from
Jul 31, 2023

Commits on Jul 31, 2023

  1. Fix constant folding of division and reminder with zero divisor

    Previously constant folding of zero division (e.x. 1/0) produces a
    compile error. This was incorrectly implemented by checking if the
    division result is infinite, so produces wrong results compared to the
    query where no constant folding is processed (e.x. 1e308/0.1). This
    patch delays the operation when the divisor is zero. This makes the
    results more consistent, but changes the exit code on zero division from
    3 to 5. Also 0/0 now produces the zero division error, not NaN.
    
    This patch also fixes the modulo operation. Previously constant folding
    logic does not take care of the % operator, but now it folds if the both
    dividend and divisor are safe numbers to cast to the integer type, and
    the divisor is not zero. This patch also fixes some code that relies on
    undefined cast behaviors in C. The modulo operation produces NaN if
    either the dividend or divisor is NaN.
    itchyny committed Jul 31, 2023
    Configuration menu
    Copy the full SHA
    00a04b2 View commit details
    Browse the repository at this point in the history