frexp, frexpf, frexpl
From cppreference.com
| ヘッダー <math.h> で定義 |
||
| float frexpf( float arg, int* exp ); |
(1) | (C99以降) |
| double frexp( double arg, int* exp ); |
(2) | |
| long double frexpl( long double arg, int* exp ); |
(3) | (C99以降) |
| ヘッダー <tgmath.h> で定義 |
||
| #define frexp( arg, exp ) |
(4) | (C99以降) |
1-3) 与えられた浮動小数点値
xを正規化された小数部と2の整数乗に分解します。4) 型汎用マクロ: arg の型が long double の場合、
frexplが呼び出されます。そうでなく、arg の型が整数型または double の場合、frexpが呼び出されます。それ以外の場合、それぞれfrexpfが呼び出されます。目次 |
[edit] パラメータ
| arg | - | floating-point value |
| exp | - | 指数を格納するための整数値へのポインタ |
[edit] 戻り値
argがゼロの場合、ゼロを返し、*expにゼロを格納します。
それ以外の場合(argがゼロでない場合)、エラーが発生しない場合、値xを範囲(-1;-0.5], [0.5; 1)で返し、*expに整数値を格納します。ここで、x×2(*exp)
=argです。
*expに格納される値がintの範囲外の場合、動作は未定義です。
argが浮動小数点数でない場合、動作は未定義です。
[edit] エラー処理
この関数は、math_errhandling で指定されたエラーの対象にはなりません。
実装がIEEE浮動小数点算術 (IEC 60559) をサポートしている場合、
argが±0の場合、変更されずに返され、*expに0が格納されます。argが±∞の場合、返され、*expに未定義の値が格納されます。argがNaNの場合、NaNが返され、*expに未定義の値が格納されます。- 浮動小数点例外は発生しません。
- もしFLT_RADIXが2(または2のべき乗)である場合、返される値は正確であり、現在の丸めモードは無視されます。
[edit] 注記
バイナリシステム(FLT_RADIXが2)では、frexpは以下のように実装される場合があります。
関数frexpとその双対であるldexpは、直接ビット操作なしに浮動小数点数の表現を操作するために使用できます。
[edit] 例
このコードを実行
#include <float.h> #include <math.h> #include <stdio.h> int main(void) { double f = 123.45; printf("Given the number %.2f or %a in hex,\n", f, f); double f3; double f2 = modf(f, &f3); printf("modf() makes %.0f + %.2f\n", f3, f2); int i; f2 = frexp(f, &i); printf("frexp() makes %f * 2^%d\n", f2, i); i = ilogb(f); printf("logb()/ilogb() make %f * %d^%d\n", f/scalbn(1.0, i), FLT_RADIX, i); }
実行結果の例
Given the number 123.45 or 0x1.edccccccccccdp+6 in hex, modf() makes 123 + 0.45 frexp() makes 0.964453 * 2^7 logb()/ilogb() make 1.92891 * 2^6
[edit] 参考文献
- C23標準 (ISO/IEC 9899:2024)
- 7.12.6.4 The frexp functions (p: TBD)
- 7.25 Type-generic math <tgmath.h> (p: TBD)
- F.10.3.4 The frexp functions (p: TBD)
- C17標準 (ISO/IEC 9899:2018)
- 7.12.6.4 The frexp functions (p: TBD)
- 7.25 Type-generic math <tgmath.h> (p: TBD)
- F.10.3.4 The frexp functions (p: TBD)
- C11標準 (ISO/IEC 9899:2011)
- 7.12.6.4 The frexp functions (p: 243)
- 7.25 型総称数学関数 <tgmath.h> (p: 373-375)
- F.10.3.4 The frexp functions (p: 521)
- C99標準 (ISO/IEC 9899:1999)
- 7.12.6.4 The frexp functions (p: 224)
- 7.22 型総称数学関数 <tgmath.h> (p: 335-337)
- F.9.3.4 The frexp functions (p: 458)
- C89/C90標準 (ISO/IEC 9899:1990)
- 4.5.4.2 The frexp function
[edit] 関連項目
| (C99)(C99) |
数に2のべき乗を掛ける (関数) |
| (C99)(C99)(C99) |
与えられた数の指数を抽出する (関数) |
| (C99)(C99)(C99) |
与えられた数の指数を抽出する (関数) |
| (C99)(C99) |
数を整数部と小数部に分割する (関数) |
| C++ ドキュメント for frexp
| |