pow function working unexpectedly

2006-04-11 Thread Jonathan Herriott
I just want to make sure I'm not being stupid before I send in a bug. The problem seems to be with gcc when using the pow function in the math.h library. Here's code that works: #include #include int main() { printf("%f\n", pow(2,3)); return 0; } Now, the following will not compil

Re: pow function working unexpectedly

2006-04-11 Thread Nicolas Blais
On Tuesday 11 April 2006 18:54, Jonathan Herriott wrote: > I just want to make sure I'm not being stupid before I send in a bug. > The problem seems to be with gcc when using the pow function in the > math.h library. Here's code that works: > > #include > #include > > int main() > { > print

Re: pow function working unexpectedly

2006-04-11 Thread Jonathan Herriott
Question then. Why would it work when I don't use variables if I don't include the library? This question is just out of curiosity. On 4/11/06, Nicolas Blais <[EMAIL PROTECTED]> wrote: > On Tuesday 11 April 2006 18:54, Jonathan Herriott wrote: > > I just want to make sure I'm not being stupid b

Re: pow function working unexpectedly

2006-04-11 Thread Nicolas Blais
On Tuesday 11 April 2006 19:07, Jonathan Herriott wrote: > Question then. Why would it work when I don't use variables if I > don't include the library? This question is just out of curiosity. > > On 4/11/06, Nicolas Blais <[EMAIL PROTECTED]> wrote: > > On Tuesday 11 April 2006 18:54, Jonathan He

Re: pow function working unexpectedly

2006-04-11 Thread Andy Reitz
On Tue, 11 Apr 2006, Jonathan Herriott wrote: > Question then. Why would it work when I don't use variables if I > don't include the library? This question is just out of curiosity. That's a pretty good question. In the case where we have pow(x,y), I see this: [EMAIL PROTECTED]/src]$ gcc -c po

Re: pow function working unexpectedly

2006-04-11 Thread Erik Trulsson
On Tue, Apr 11, 2006 at 11:07:35PM +, Jonathan Herriott wrote: > Question then. Why would it work when I don't use variables if I > don't include the library? This question is just out of curiosity. Because the compiler recognizes that pow() when called with only constants as arguments can

Re: pow function working unexpectedly

2006-04-11 Thread Colin Percival
Andy Reitz wrote: > So, clearly, something is optimizing the pow() function away when the > arguments are hard-coded lvalues, instead of varibles. > > Now, what that thing *is*, I don't know. The C compiler precomputes constant expressions; your "pow(2,3)" is being rewritten to "8" by the compile

Re: pow function working unexpectedly

2006-04-11 Thread Svein Halvor Halvorsen
On 4/12/06, Jonathan Herriott <[EMAIL PROTECTED]> wrote: > Question then. Why would it work when I don't use variables if I > don't include the library? This question is just out of curiosity. Since you use only hard coded operands, the result is given, and gcc optimizes such arithmetics and fun

Re: pow function working unexpectedly

2006-04-11 Thread Jonathan Herriott
With reference to my first example given is what I was talking about. The first example properly ran with just compiling with: gcc test.c Here's the first example again: > > > > #include > > > > #include > > > > > > > > int main() > > > > { > > > > printf("%f\n", pow(2,3)); > > > > r

Re: pow function working unexpectedly

2006-04-11 Thread Nicolas Blais
On Tuesday 11 April 2006 19:24, Colin Percival wrote: > Andy Reitz wrote: > > So, clearly, something is optimizing the pow() function away when the > > arguments are hard-coded lvalues, instead of varibles. > > > > Now, what that thing *is*, I don't know. > > The C compiler precomputes constant exp

Re: pow function working unexpectedly

2006-04-11 Thread Jonathan Herriott
Yes, thank you. I wasn't going to report it as a bug after you pointed out my blatant mistake. Thanks again for the info. Jon On 4/11/06, Nicolas Blais <[EMAIL PROTECTED]> wrote: > On Tuesday 11 April 2006 19:24, Colin Percival wrote: > > Andy Reitz wrote: > > > So, clearly, something is optimi

Re: pow function working unexpectedly

2006-04-12 Thread Giorgos Keramidas
On 2006-04-11 22:54, Jonathan Herriott <[EMAIL PROTECTED]> wrote: > I just want to make sure I'm not being stupid before I send in a bug. > The problem seems to be with gcc when using the pow function in the > math.h library. Here's code that works: > > #include > #include > > int main() > { >