[Bug c++/125127] New: Different results of double division followed by casts with the -m32 flag
ddvamp007 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri May 1 10:57:34 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125127
Bug ID: 125127
Summary: Different results of double division followed by casts
with the -m32 flag
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ddvamp007 at gmail dot com
Target Milestone: ---
When converting the result of division by a double type variable to int, the
result differs if you add an intermediate conversion to double (double to
double).
https://godbolt.org/z/nsh3Yc1fW
#include <iostream>
int main() {
double a = 0.5;
double b = 0.01;
std::cout << (int)(double)(a / b) << std::endl
<< (int)(a / b) << std::endl
<< (int)(double)(0.5 / b) << std::endl
<< (int)(0.5 / b) << std::endl
<< (int)(double)(a / 0.01) << std::endl
<< (int)(a / 0.01) << std::endl
<< (int)(double)(0.5 / 0.01) << std::endl
<< (int)(0.5 / 0.01) << std::endl;
}
x86-64 gcc-13.1(-thrunk), -m32 --std=c++11 -O0 -pedantic -Wall -Wextra
Output:
50
49
50
49
50
50
50
50
More information about the Gcc-bugs
mailing list