关于连接math.h的问题
- dugowe
- 帖子: 34
- 注册时间: 2006-06-14 13:43
- 联系:
关于连接math.h的问题
#include <stdio.h>
dugowe@dugowesbox:~/program$ more power.c
#include <math.h>
int main()
{
float x = 10;
float y = 2;
float z;
z = power(x, y);
printf("%d",z);
return 0;
}
dugowe@dugowesbox:~/program$ gcc power.c -lm -o power
/tmp/ccqeMycv.o: In function `main':power.c:(.text+0x3c):对‘power’未定义的引用
collect2: ld 返回 1
----------------------------
lib中也没见math函数库,只有
libm-2.3.6.so
libmemusage.so
libm.so.6
我想知道这个到底是该怎么写?从新利得上面也没找到math库,呵呵,
谢谢大家帮忙
dugowe@dugowesbox:~/program$ more power.c
#include <math.h>
int main()
{
float x = 10;
float y = 2;
float z;
z = power(x, y);
printf("%d",z);
return 0;
}
dugowe@dugowesbox:~/program$ gcc power.c -lm -o power
/tmp/ccqeMycv.o: In function `main':power.c:(.text+0x3c):对‘power’未定义的引用
collect2: ld 返回 1
----------------------------
lib中也没见math函数库,只有
libm-2.3.6.so
libmemusage.so
libm.so.6
我想知道这个到底是该怎么写?从新利得上面也没找到math库,呵呵,
谢谢大家帮忙
- jaguar00
- 帖子: 227
- 注册时间: 2005-10-19 23:48
- 来自: 大山丛林
- leal
- 帖子: 1119
- 注册时间: 2005-08-29 14:49
- 来自: 杭州
- 联系:
Re: 关于连接math.h的问题
你确定有 power函数吗?去查查标准库函数吧dugowe 写了:#include <stdio.h>
dugowe@dugowesbox:~/program$ more power.c
#include <math.h>
int main()
{
float x = 10;
float y = 2;
float z;
z = power(x, y);
printf("%d",z);
return 0;
}
dugowe@dugowesbox:~/program$ gcc power.c -lm -o power
/tmp/ccqeMycv.o: In function `main':power.c:(.text+0x3c):对‘power’未定义的引用
collect2: ld 返回 1
----------------------------
lib中也没见math函数库,只有
libm-2.3.6.so
libmemusage.so
libm.so.6
我想知道这个到底是该怎么写?从新利得上面也没找到math库,呵呵,
谢谢大家帮忙
power -> pow !
libm 就是 数学库
- dugowe
- 帖子: 34
- 注册时间: 2006-06-14 13:43
- 联系:
- nobrain
- 帖子: 808
- 注册时间: 2005-08-25 13:58
- 来自: ustc
- 联系:
- jaguar00
- 帖子: 227
- 注册时间: 2005-10-19 23:48
- 来自: 大山丛林
- jaguar00
- 帖子: 227
- 注册时间: 2005-10-19 23:48
- 来自: 大山丛林
想起来了,在stl的algorithms中是有一个power的函数。不过是c++啊。不是c
不过是用在 #include <numeric>中的
原型是:
#include <numeric>
inline TYPE power( TYPE x, int N );
The power() function returns x raised to the power of N, where N is some non-negative integer.
-------------
c中只有pow
不过是用在 #include <numeric>中的
原型是:
#include <numeric>
inline TYPE power( TYPE x, int N );
The power() function returns x raised to the power of N, where N is some non-negative integer.
-------------
c中只有pow
It is no use doing what you like; you have got to like what you do!
- ngc1275
- 帖子: 21
- 注册时间: 2006-08-22 18:05
函数 pow(计算次方值)
-------------
相关函数
exp,log,log10
表头文件
#include<math.h>
定义函数
double pow(double x,double y);
函数说明
pow()用来计算以x为底的y次方值,即xy值,然后将结果返回。
返回值
返回x的y次方计算结果。
错误代码
EDOM 参数x为负数且参数y不是整数。
附加说明
使用GCC编译时请加入-lm。
范例
#include <math.h>
main()
{
double answer;
answer =pow(2,10);
printf("2^10 = %f\n", answer);
}
执行
2^10 = 1024.000000
-------------
相关函数
exp,log,log10
表头文件
#include<math.h>
定义函数
double pow(double x,double y);
函数说明
pow()用来计算以x为底的y次方值,即xy值,然后将结果返回。
返回值
返回x的y次方计算结果。
错误代码
EDOM 参数x为负数且参数y不是整数。
附加说明
使用GCC编译时请加入-lm。
范例
#include <math.h>
main()
{
double answer;
answer =pow(2,10);
printf("2^10 = %f\n", answer);
}
执行
2^10 = 1024.000000