English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

C Library Macro – ERANGE Usage and Example

C Standard Library - <errno.h>

Description

C Library Macro ERANGE Indicates a range error that occurs when the input parameter is out of the range defined by the mathematical function, and errno is set to ERANGE.

Declaration

The following is the declaration of the ERANGE macro.

#define ERANGE some_value

Parameters

  • NA

Return Value

  • NA

Online 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) 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) 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) 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>