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...
3 2686
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 - #include <iostream>
-
#include <math.h>
-
-
using namespace std;
-
-
int main () {
-
-
float x, y, z;
-
-
x = 2.1;
-
z = 2.5;
-
-
cout << powf ( x, z ) << endl;
-
cout << pow ( x, z );
-
-
return 0;
-
}
-
output:
6.3907
6.3907
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.
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:)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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?
|
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,
|
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...
|
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...
|
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:
|
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...
|
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
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
| |