473,320 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

GNU pow( ) works only sometimes

anyone know why this works:

float y;

y = powf ( 2.0, 2.0 );


...and this does not (undefined reference to 'powf')?

float x, y, z;

x = 2.0;
z = 2.0;

y = powf ( x, z );

...can't be a library issue, as alluded to by the error msg, because using literals instead of variables works. The horror...
Sep 22 '06 #1
3 2686
dush
27
Hi

I am using g++ and including <math.h>, everything works fine.
Have you tried pow instead of powf ?
pow is overloaded for float arguments too

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. int main () {
  7.  
  8. float x, y, z;
  9.  
  10. x = 2.1;
  11. z = 2.5;
  12.  
  13. cout << powf ( x, z ) << endl;
  14. cout << pow ( x, z );
  15.  
  16. return 0;
  17. }
  18.  
output:

6.3907
6.3907
Sep 22 '06 #2
Its library problem......

compile like this

gcc -lm program.c

Here lm option specifies that the C file contains some functions belonging to the libm library.
Sep 22 '06 #3
Thanks for the tips!
yeah, Im just wondering why it works with literals and not variables.

the -lm links in the math lib & variables work, sure.
And pow had the same hangup.

Its my first day using this compiler & I thought it a bit strange...

My code works..maybe I should just be happy:)
Sep 22 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: silly | last post by:
/* hello, I have some fairly naive queries here related to optimising code! I know the first answer is 'don't' but leave that to one side for the moment. 1) I'm looking for constructive comments...
5
by: Magix | last post by:
#include <math.h> double pow( double base, double exp ); will pow (2, -30) works fine ? (exp is negative value). If not, what are the workaround for exp to be negative?
6
by: Victo | last post by:
I tried to use pow() and sin(). but even I included <math.h>, I can't use the 2 functions.... Why's that???? for example,
52
by: Michel Rouzic | last post by:
I obtain an unwanted behavior from the pow() function : when performing pow(2, 0.5), i obtain 1.414214 when performing pow(2, 1/2), i obtain 1.000000 when performing a=0.5; pow(2, a), i obtain...
42
by: John Smith | last post by:
In a C program I need to do exponentiation where the base is negative and the exponent is a fraction. In standard C this would be something like t = pow(-11.5, .333), but with this combination of...
13
by: siggi | last post by:
Hi all, this is a newbie question on : Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32 PC with WinXP In http://www.python.org/doc/2.3.5/lib/module-math.html I read:
5
by: aaragon | last post by:
Hi everyone, I wrote a very simple function to try to understand the casting of variables in C++. The function is function foo() { std::vector<inttest(100); randomize(test); unsigned long...
18
by: Peng Yu | last post by:
Hi, I'm wondering if there is any general guideline on when to using something like std::pow(x, n) rather than x * x * x * ... * x (n x's). Thanks, Peng
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.