John Beale
jpbea****@yahoo*****
Fri Feb 16 06:36:17 JST 2018
I noticed that I get two different answers when running the same code (below) with the same compiler (gcc 6.3.0) on the same machine (Lenovo Thinkpad P71). The difference is that one is MinGW on Win10, and the other is Ubuntu 16.04 running in VirtualBox, but both on the same Thinkpad. Maybe it's a 32bit vs 64bit difference? I wouldn't have guessed that affected the output of basic math though. I guess there is no guarantee about rounding when converting double to int. Note: this was not an academic exercise, it came from a real project, a pattern generator that had to fit an integer number of features into a given space, and it took me by surprise when I got different results. I am using the MINGW32 shell and gcc -v reports (MinGW.org GCC-6.3.0-1) 6.3.0 CODE: SELECT ALL #include <stdio.h> void main() { double a = 4.5; double b = 0.1; int i = a / b; printf("%d\n",i); }Ubuntu 16.04 on VirtualBox/Win10 result: 45Raspberry Pi Raspbian (ARM) result: 45 Online compiler demo: at www.onlinegdb.com/online_c_compiler : 45 MinGW32 gcc 6.3.0-1 result: 44 -------------- next part -------------- An HTML attachment was scrubbed... URL: https://lists.osdn.me/mailman/archives/mingw-users/attachments/20180215/78283bc1/attachment.htm