Latest web development tutorials

C 庫宏– ERANGE

C 標準庫 - <errno.h> C標準庫- <errno.h>

描述

C庫宏ERANGE表示一個範圍錯誤,它在輸入參數超出數學函數定義的範圍時發生,errno被設置為ERANGE。

聲明

下面是ERANGE 宏的聲明。

#define ERANGE some_value

參數

  • NA

返回值

  • NA

實例

下面的實例演示了ERANGE 宏的用法。

#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;
}

讓我們編譯並運行上面的程序,這將產生以下結果:

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

C 標準庫 - <errno.h> C標準庫- <errno.h>