Namespaces
Variants

frexp, frexpf, frexpl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
frexp
(C99) (C99)
(C99) (C23)
(C99)
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
ヘッダー <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 が呼び出される。

目次

翻訳のポイント: - 「Contents」を「目次」に翻訳 - HTMLタグ、属性、リンク先は一切変更せず保持 - C++関連の用語(Parameters、Return value、Error handling、Notes、Example、References、See also)は原文のまま保持 - 数字の書式は変更せず保持 - 構造とフォーマットは完全に維持

パラメータ

arg - 浮動小数点値
exp - 指数を格納する整数値へのポインタ

戻り値

arg がゼロの場合、ゼロを返し、 *exp にゼロを格納します。

それ以外の場合( arg がゼロでない場合)、エラーが発生しなければ、範囲 (-1;-0.5], [0.5; 1) 内の値 x を返し、 * exp に整数値を格納して、 x×2 (*exp)
=arg
となるようにする。

*exp に格納される値が int の範囲外である場合、動作は未定義です。

arg が浮動小数点数でない場合、動作は未定義です。

エラーハンドリング

この関数は math_errhandling で指定されているいかなるエラーにも影響されません。

IEEE浮動小数点演算(IEC 60559)を実装がサポートしている場合、

  • arg が±0の場合、変更されずに返され、 * exp 0 が格納されます。
  • arg が±∞の場合、その値が返され、 * exp には未規定の値が格納されます。
  • arg がNaNの場合、NaNが返され、 * exp には未規定の値が格納されます。
  • 浮動小数点例外は発生しません。
  • FLT_RADIX 2 (または2の累乗)の場合、返される値は正確であり、 現在の丸めモード は無視されます。

注記

バイナリシステム( FLT_RADIX 2 の場合)では、 frexp は以下のように実装される可能性があります

{
    *exp = (value == 0) ? 0 : (int)(1 + logb(value));
    return scalbn(value, -(*exp));
}

関数 frexp は、その双対である ldexp と共に、浮動小数点数の表現を直接的なビット操作なしで操作するために使用できます。

#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

参考文献

  • C23規格 (ISO/IEC 9899:2024):
  • 7.12.6.4 frexp関数群 (p: TBD)
  • 7.25 総称数学 <tgmath.h> (p: TBD)
  • F.10.3.4 frexp関数群 (p: TBD)
  • C17規格 (ISO/IEC 9899:2018):
  • 7.12.6.4 frexp関数群 (p: TBD)
  • 7.25 総称数学 <tgmath.h> (p: TBD)
  • F.10.3.4 frexp関数群 (p: TBD)
  • C11規格 (ISO/IEC 9899:2011):
  • 7.12.6.4 frexp関数群 (p: 243)
  • 7.25 総称数学 <tgmath.h> (p: 373-375)
  • F.10.3.4 frexp関数群 (p: 521)
  • C99規格 (ISO/IEC 9899:1999):
  • 7.12.6.4 frexp関数 (p: 224)
  • 7.22 総称数学 <tgmath.h> (p: 335-337)
  • F.9.3.4 frexp関数 (p: 458)
  • C89/C90標準 (ISO/IEC 9899:1990):
  • 4.5.4.2 frexp関数

関連項目

数値を2の累乗で乗算する
(関数)
(C99) (C99) (C99)
指定された数値の指数を抽出する
(関数)
(C99) (C99) (C99)
指定された数値の指数を抽出する
(関数)
(C99) (C99)
数値を整数部と小数部に分解する
(関数)