Share via


hypot, hypotf, hypotl, _hypot, _hypotf, _hypotl

計算斜邊。

語法

double hypot(
   double x,
   double y
);
float hypotf(
   float x,
   float y
);
long double hypotl(
   long double x,
   long double y
);
double _hypot(
   double x,
   double y
);
float _hypotf(
   float x,
   float y
);
long double _hypotl(
   long double x,
   long double y
);
#define hypotf(X, Y) // Requires C11 or higher

參數

x, y
浮點值。

傳回值

如果成功,hypot 會傳回斜邊的長度;溢位時,hypot 會傳回 INF (無限大),同時 errno 變數會被設為 ERANGE。 您可以使用 _matherr 修改錯誤處理。

如需傳回碼的詳細資訊,請參閱 errno_doserrno_sys_errlist_sys_nerr

備註

提供兩個邊的長度 xyhypot 函式會計算直角三角形斜邊的長度 (亦即,x2 + y2 的平方根)。

具有前置底線的函式版本提供舊版標準的相容性。 其行為與不具有前置底線的版本完全相同。 建議針對新程式碼使用不具有前置底線的版本。

如果您使用 < tgmath.h >hypot() 宏,引數的類型會決定選取哪一個函式版本。 如需詳細資訊,請參閱 類型泛型數學

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

常式 必要的標頭
hypot, hypotf, hypotl, _hypot, _hypotf, _hypotl <math.h>
hypot 宏觀 <tgmath.h>

如需相容性詳細資訊,請參閱相容性

範例

// crt_hypot.c
// This program prints the hypotenuse of a right triangle.

#include <math.h>
#include <stdio.h>

int main( void )
{
   double x = 3.0, y = 4.0;

   printf( "If a right triangle has sides %2.1f and %2.1f, "
           "its hypotenuse is %2.1f\n", x, y, _hypot( x, y ) );
}
If a right triangle has sides 3.0 and 4.0, its hypotenuse is 5.0

另請參閱

數學和浮點支援
_cabs
_matherr