hypot()、hypotf()、hypotl() - 2 つの引数の二乗の平方根の計算

標準

標準/拡張機能 C/C++ 依存項目

SAA
XPG4
XPG4.2
C99
Single UNIX Specification、バージョン 3
C++ TR1 C99

両方  

z/OS V1R7

形式

SAA:
#include <math.h>

double hypot(double side1, double side2);

SAA コンパイラー・オプション: LANGLVL(EXTENDED), LANGLVL(SAA)、 または LANGLVL(SAAL2)

XPG4:
#define _XOPEN_SOURCE
#include <math.h>

double hypot(double side1, double side2);
C99:
#define _ISOC99_SOURCE
#include <math.h>

float hypotf(float side1, float side2);
long double hypotl(long double side1, long double side2);
C++ TR1 C99:
#define _TR1_C99
#include <math.h>

float hypot(float side1, float side2); 
long double hypot(long double side1, long double side2);

機能説明

hypot() ファミリーの関数は、2 つの辺 side1 および side2 の長さに基づいて、直角三角形の斜辺の長さを計算します。hypot() の呼び出しは次の式と同じです。
 sqrt(side1* side1 + side2 * side2);
注: 下表は、これらの関数の実行可能な形式を示しています。 IEEE 2 進数浮動小数点の詳細は、IEEE 2 進数浮動小数点を参照してください。
関数 SPC Hex IEEE
hypot X X X
hypotf   X X
hypotl   X X
制約事項: hypotf() 関数は、_FP_MODE_VARIABLE フィーチャー・テスト・マクロをサポートしません。

戻り値

hypot() ファミリーの関数は、計算された斜辺の長さを戻します。

正しい値が表示可能な値の範囲外である場合は、±HUGE_VAL が、値の符号に応じて戻されます。マクロ ERANGE の値が errno に保管され、計算値が範囲外であることを示します。正しい値がアンダーフローを起こした場合は、0 が戻され、マクロ ERANGE の値が errno に保管されます。

IEEE の特殊な動作: 正常に実行された場合、hypot() ファミリーの関数は、計算された斜辺の長さを戻します。 正しい値がオーバーフローすると、hypot() は errno に ERANGE を設定し、HUGE_VAL を戻します。

CELEBH01
⁄* CELEBH01                                      

   This example calculates the hypotenuse of a right-angled                     
   triangle with sides of 3.0 and 4.0.                                          
                                                                                
 *⁄                                                                             
#include <math.h>                                                               
#include <stdio.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);                                                
}                                                                               
出力:
The hypotenuse of the triangle with sides 3.000000 and 4.000000 is 5.000000

関連情報