C 语言标准库宏 - ERANGE
C 语言标准库宏 ERANGE 表示一个范围错误。在输入参数超出数学函数定义的范围时,errno 被设置为 ERANGE
头文件
#include <errno.h>
宏声明
下面是 ERANGE 宏的声明
#define ERANGE some_value
参数
无
返回值
无
范例
下面的范例演示了 ERANGE 宏的用法
/** * file: main.c * author: 简单教程(www.twle.cn) * * Copyright © 2015-2065 www.twle.cn. All rights reserved. */ #include <stdio.h> #include <errno.h> #include <math.h> int main() { double x; double value; printf("the value of ERANGE is: %d\n",ERANGE); x = 3.141592653589793238; value = log(x); if( errno == ERANGE ) { printf("Log(%f) is out of range\n", x); } else { printf("Log(%f) = %f\n", x, value); } x = 1.4142135623731; value = log(x); if( errno == ERANGE ) { printf("Log(%f) is out of range\n", x); } else { printf("Log(%f) = %f\n", x, value); } x = 0.000000; value = log(x); if( errno == ERANGE ) { printf("Log(%f) is out of range\n", x); } else { printf("Log(%f) = %f\n", x, value); } return 0; }
编译运行以上范例,输出结果如下
$ gcc main.c && ./a.out the value of ERANGE is: 34 Log(3.141593) = 1.144730 Log(1.414214) = 0.346574 Log(0.000000) = -inf