Easy Tutorial
❮ C Function Snprintf C Examples Sizeof Operator ❯

C Library Macro - ERANGE

C Standard Library - <errno.h>

Description

The C library macro ERANGE represents a range error, which occurs when an input parameter is outside the range defined by mathematical functions, and errno is set to ERANGE.

Declaration

Below is the declaration for the ERANGE macro.

#define ERANGE some_value

Parameters

Return Value

Example

The following example demonstrates the usage of the 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's compile and run the above program, which will produce the following result:

Log(2.000000) = 0.693147
Log(1.000000) = 0.000000
Log(0.000000) = -inf

C Standard Library - <errno.h>

❮ C Function Snprintf C Examples Sizeof Operator ❯