http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53738
Bug #: 53738 Summary: Problem with pow() function when calculating power of 10 Classification: Unclassified Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: chirayu.chiri...@gmail.com Created attachment 27671 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27671 Screenshot of the Bug My program is calculating the log=log10(num) and then using pow(10,log-1) to get the power of 10 one less than its log. Here is the code: // Sandbox.c #include<stdio.h> #include<math.h> int main() { int t,n,log,po; printf("\nTest Cases:"); scanf("%d",&t); while(t--) { printf("\nNumber:"); scanf("%d",&n); log=log10(n); printf("\nlog=%d\n",log); po=pow(10,log); printf("pow(10,log)=%d\n",po); po=pow(10,log-1); printf("pow(10,log-1)=%d\n",po); po=pow(10,log); printf("pow(10,log)=%d\n",po); po=pow(10,log)/10; printf("pow(10,log)/10=%d\n\n",po); } return 0; } OUTPUT (Expected): Test Cases:2 Number:1020 log=3 pow(10,log)=1000 pow(10,log-1)=100 pow(10,log)=1000 pow(10,log)/10=100 Number:10230 log=4 pow(10,log)=10000 pow(10,log-1)=1000 pow(10,log)=10000 pow(10,log)/10=1000 OUTPUT (Actual): Test Cases:2 Number:1020 log=3 pow(10,log)=1000 pow(10,log-1)=99 // Problem Here pow(10,log)=1000 pow(10,log)/10=100 Number:10230 log=4 pow(10,log)=10000 pow(10,log-1)=1000 pow(10,log)=9999 // Problem Here pow(10,log)/10=999 // Problem Here Compiler Options Used in CMD: >gcc sandbox.c -o sand >sand Version shown by "gcc -v": Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe Target: mingw32 Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,obj c,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgo mp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-r untime-libs --build=mingw32 --prefix=/mingw Thread model: win32 gcc version 4.6.2 (GCC) System Specs: Win 7 Home Premium 64 bit Intel Core i7-2670QM @ 2.20 GHz Works fine when run on IDEONE in C(gcc-4.3.4) http://ideone.com/cQRrY