![The C Standard Library Reference](/c_standard_library/images/c-mini-logo.jpg)
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <complex.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <fenv.h>
- C Library - <float.h>
- C Library - <inttypes.h>
- C Library - <iso646.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdalign.h>
- C Library - <stdarg.h>
- C Library - <stdbool.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <tgmath.h>
- C Library - <time.h>
- C Library - <wctype.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library - ERANGE Macro
The C library ERANGE Macro represents a range error, which occurs if an input argument is outside the range, over which the mathematical function is defined and errno is set to ERANGE.
The ERANGE associated with mathematical functions that set to input ranges. By setting errno to ERANGE, it represents the result of operation which is not representable within the valid range.
Syntax
Following is the C library syntax of the ERANGE Macro.
#define ERANGE some_value
Parameters
This function is known for macros. So, it doesn't accept any parameter.
Return Value
This function doesn't return any value.
Example 1
Following is the C library program that shows the usage of ERANGE Macro.
#include <stdio.h> #include <errno.h> #include <math.h> int main () { double x; double value; x = 2.000000; 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.000000; 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; }
Output
On compiling of above code, it will produce the following result −
Log(2.000000) = 0.693147 Log(1.000000) = 0.000000 Log(0.000000) is out of range
Example 2
Here, we are building the program for the calculation of logarithm number using the mathematical functions log() and exp() which encounter the range errors.
#include <stdio.h> #include <math.h> #include <errno.h> int main() { double x = 1000; double result = exp(x); if (errno == ERANGE) { printf("exp(%f) is out of range\n", x); } else { printf("exp(%f) = %f\n", x, result); } return 0; }
Output
On execution of above code, we get the following result −
exp(1000.000000) is out of range