hypot ()- 計算斜邊

格式

#include <math.h>
double hypot(double side1, double side2);

語言層次

ANSI

安全執行緒

說明

hypot() 函數會根據兩側 side1side2的長度,來計算直角三角形的斜邊長度。 對 hypot() 函數的呼叫相當於:
   sqrt(side1 * side1 + side2 * side2);

回覆值

hypot() 函數會傳回斜邊的長度。 如果溢位結果, hypot() 會將 errno 設為 ERANGE ,並傳回值 HUGE_VAL。 如果下溢產生結果, hypot() 會將錯誤碼設為 ERANGE 並傳回零。 錯誤碼的值也可以設為 EDOM。

範例

此範例計算具有 3.0 和 4.0側面的直角三角形的斜邊。
#include <math.h>
 
int main(void)
{
   double x, y, z;
 
   x = 3.0;
   y = 4.0;
   z = hypot(x,y);
 
   printf("The hypotenuse of the triangle with sides %lf and %lf"
          " is %lf\n", x, y, z);
}
 
/********************  Output should be similar to:  **************
 
The hypotenuse of the triangle with sides 3.000000 and 4.000000 is 5.000000
*/

相關資訊