fabs是求浮点数的绝对值的库函数。它有穗亮一个double型形参,返回一个double型数据。当不关心浮点数的符号只关心其数字部分时用fabs取得其绝培陵对值配族戚。举例代码如下:
创新互联公司为您提适合企业的网站设计 让您的网站在搜索引擎具有高度排名,让您的网站具备超强的网络竞争力!结合企业自身,进行网站设计及把握,最后结合企业文化和具体宗旨等,才能创作出一份性化解决方案。从网站策划到成都网站设计、网站制作, 我们的网页设计师为您提供的解决方案。
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
#include "math.h"
int main(void){
double x=3.1415926,y=-x;
printf("x = %f\tfabs(x) = %f\n",x,fabs(x));
printf("y = %f\tfabs(y) = %f\n",y,fabs(y));
return 0;
}
输出是:
FLT_RADIX
radix of floating-point representations
FLT_ROUNDS
floating-point rounding mode
Where the prefix FLT pertains to type float, DBL to type double, and LDBL to type long double:
FLT_DIG
DBL_DIG
LDBL_DIG
precision (in decimal digits)
FLT_EPSILON
DBL_EPSILON
LDBL_EPSILON
smallest number x such that 1.0 + x != 1.0
FLT_MANT_DIG
DBL_MANT_DIG
LDBL_MANT_DIG
number of digits, base FLT_RADIX, in mantissa
FLT_MAX
DBL_MAX
LDBL_MAX
maximum number
FLT_MAX_EXP
DBL_MAX_EXP
LDBL_MAX_EXP
largest positive integer exponent to which FLT_RADIX can be raised and remain representable
FLT_MIN
DBL_MIN
LDBL_MIN
minimum normalised number
FLT_MIN_EXP
DBL_MIN_EXP
LDBL_MIN_EXP
smallest negative integer exponent to which FLT_RADIX can be raised and remain representable
可以蚂档含采用库函数atof, 头文件为#include stdlib.h
函数名: atof
功 能:闷笑 把字符串蠢闷转换成浮点数
用 法: double atof(const char *nptr);
实例:
#includestdlib.h
#includestdio.h
intmain()
{
double d;
char*str="12345.67";
d=atof(str);
printf("string=%sdouble=%lf\n",str,d);
return 0;
}