C library Macro - ERANGE



Description

As mentioned above, the C library macro ERANGE 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.

Declaration

Following is the declaration for ERANGE Macro.

#define ERANGE some_value

Parameters

  • NA

Return Value

  • NA

Example

The following example 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;
}

Let us compile and run the above program that will produce the following result −

Log(2.000000) = 0.693147                                      
Log(1.000000) = 0.000000                                      
Log(0.000000) is out of range
errorno_h.htm
Advertisements