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
);
參數
- x, y
浮點數的值。
傳回值
如果成功,則 hypot 會傳回斜邊的長度;若溢位, hypot 會傳回 INF (無限大),而且 errno 變數會設定為 ERANGE。 您可以使用 _matherr 修改錯誤處理。
如需傳回碼的詳細資訊,請參閱errno、_doserrno、_sys_errlist 和 _sys_nerr。
備註
給定直角三角形的兩邊長 x 和 y,hypot 函式會計算斜邊長度 (也就是,x2 + y2 的平方根)。
具有前置底線的函式是為先前標準提供相容性。 它們的行為與沒有前置底線的版本相同。 建議您在新的程式碼中使用沒有前置底線的版本。
需求
常式 |
必要的標頭 |
---|---|
hypot, hypotf, hypotl, _hypot, _hypotf, _hypotl |
<math.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 ) );
}
.NET Framework 對等用法
不適用。若要呼叫標準 C 函式,請使用 PInvoke。如需詳細資訊,請參閱平台叫用範例。