C library Macro - ERANGE

Advertisements


Description

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 = 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, this will produce the following result:

Log(1.000000) = 1.609438
Log(0.000000) is out of range


Advertisements
Advertisements