[Mingw-msys] [mingw - MSYS] RE: bash empty for-loop
- Date: Fri, 7 Sep 2007 19:13:19 -0500
- From: "Michael Chen" <vancouver.michael@xxxxxxxxx>
- Subject: Re: [Mingw-msys] pow(5,2)=24 ?????!!!!!
Thanks for all the replies! I followed the suggestions and got
satisfactory results.
Now my question changes focus:
If I compile using GCC, I got wrong answer pow(5,2)=24, but if I use
Lcc-win32, I got correct one. Can anybody explain? Is there a GCC
switch which can alter the behavior? What are your commonly used GCC
switches?
Michael Chen
> int s = (int) pow(l,d);
> printf("%d\t%d\t%d\n",l,d,s);
>
>
> And I tried several (l,d), results are:
> 2 2 4
> 3 2 9
> 4 2 16
> 5 2 24 <= this one is wrong
> 6 2 36
> ....
>
> What shall I use then? my variable s, l, and d are integers!
On 9/7/07, Brian Dessent <brian@xxxxxxxxxxx> wrote:
> Michael Chen wrote:
>
> > So I should always add 0.5 to pow() and modf() as shown, when my input
> > parameters and output are all integers?
>
> That, or use an explicit rounding function such as round(). The problem
> is that the C language specifies that simply casting a double or float
> to an integer, as you do with "(int)pow(L,D)", does not do any rounding
> -- it simply discards the fractional parts. So you should never use a
> cast where you want something rounded to the nearest integer.
>
> Brian
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Mingw-msys mailing list
> Mingw-msys@xxxxxxxxxxxxxxxxxxxxx
> https://lists.sourceforge.net/lists/listinfo/mingw-msys
>
--
Michael Chen
PhD Candidate
Northwestern University
2145 Sheridan Road IEMS
Evanston, IL 60208-3119
Phone: 847.467.2043
Fax: 847.491.8005
Web: http://users.iems.northwestern.edu/~mchen/
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Mingw-msys mailing list
Mingw-msys@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/mingw-msys