public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/53738] New: Problem with pow() function when calculating power of 10
@ 2012-06-21 3:06 chirayu.chiripal at gmail dot com
2012-06-21 3:26 ` [Bug c/53738] " chirayu.chiripal at gmail dot com
2012-06-21 3:33 ` [Bug target/53738] " pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: chirayu.chiripal at gmail dot com @ 2012-06-21 3:06 UTC (permalink / raw)
To: gcc-bugs
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: unassigned@gcc.gnu.org
ReportedBy: chirayu.chiripal@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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/53738] Problem with pow() function when calculating power of 10
2012-06-21 3:06 [Bug c/53738] New: Problem with pow() function when calculating power of 10 chirayu.chiripal at gmail dot com
@ 2012-06-21 3:26 ` chirayu.chiripal at gmail dot com
2012-06-21 3:33 ` [Bug target/53738] " pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: chirayu.chiripal at gmail dot com @ 2012-06-21 3:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53738
--- Comment #1 from Chirayu Chiripal <chirayu.chiripal at gmail dot com> 2012-06-21 03:26:13 UTC ---
Also Tried compiling it with:
gcc -Wall -Wextra
and
-fno-strict-aliasing -fwrapv
but the result was same.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug target/53738] Problem with pow() function when calculating power of 10
2012-06-21 3:06 [Bug c/53738] New: Problem with pow() function when calculating power of 10 chirayu.chiripal at gmail dot com
2012-06-21 3:26 ` [Bug c/53738] " chirayu.chiripal at gmail dot com
@ 2012-06-21 3:33 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-06-21 3:33 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53738
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target| |i?86-*-mingw32
Status|UNCONFIRMED |RESOLVED
Component|c |target
Resolution| |MOVED
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-06-21 03:33:23 UTC ---
Works for me correctly on linux:
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
>Works fine when run on IDEONE in C(gcc-4.3.4)
That is most likely linux too.
In fact there is nothing GCC can do since pow is not provided by GCC but rather
who ever provides your libc. I would report this to the mingw folks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-06-21 3:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-21 3:06 [Bug c/53738] New: Problem with pow() function when calculating power of 10 chirayu.chiripal at gmail dot com
2012-06-21 3:26 ` [Bug c/53738] " chirayu.chiripal at gmail dot com
2012-06-21 3:33 ` [Bug target/53738] " pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).