Namespaces
Variants

expm1, expm1f, expm1l

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
(C23)
(C99)
expm1
(C99)
(C23)
(C23)

Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
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 expm1f ( float arg ) ;
(1) (C99以降)
double expm1 ( double arg ) ;
(2) (C99以降)
long double expm1l ( long double arg ) ;
(3) (C99以降)
ヘッダーで定義 <tgmath.h>
#define expm1( arg )
(4) (C99以降)
1-3) 与えられたべき乗 arg に対する e (オイラー数、 2.7182818 )の計算結果から 1.0 を減算します。 arg がゼロに近い場合、この関数は式 exp ( arg ) - 1.0 よりも高精度です。
4) 型総称マクロ: arg の型が long double の場合、 expm1l が呼び出される。それ以外の場合、 arg が整数型または double 型の場合、 expm1 が呼び出される。それ以外の場合、 expm1f が呼び出される。

目次

パラメータ

arg - 浮動小数点値

戻り値

エラーが発生しない場合、 e arg
-1
が返されます。

オーバーフローによる範囲エラーが発生した場合、 +HUGE_VAL +HUGE_VALF または +HUGE_VALL が返されます。

アンダーフローによる範囲エラーが発生した場合、正しい結果(丸め後)が返されます。

エラー処理

エラーは math_errhandling で指定された通りに報告されます。

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

  • 引数が±0の場合、変更されずに返される
  • 引数が-∞の場合、-1が返される
  • 引数が+∞の場合、+∞が返される
  • 引数がNaNの場合、NaNが返される

注記

expm1 関数と log1p 関数は金融計算で有用です。例えば、小さな日次金利の計算時: (1+x) n
-1
expm1 ( n * log1p ( x ) ) と表現できます。これらの関数は正確な逆双曲線関数の記述も簡素化します。

IEEE互換型 double の場合、 709.8 < arg のときオーバーフローが保証されます。

#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
// #pragma STDC FENV_ACCESS ON
int main(void)
{
    printf("expm1(1) = %f\n", expm1(1));
    printf("Interest earned in 2 days on $100, compounded daily at 1%%\n"
           " on a 30/360 calendar = %f\n",
           100*expm1(2*log1p(0.01/360)));
    printf("exp(1e-16)-1 = %g, but expm1(1e-16) = %g\n",
           exp(1e-16)-1, expm1(1e-16));
    // special values
    printf("expm1(-0) = %f\n", expm1(-0.0));
    printf("expm1(-Inf) = %f\n", expm1(-INFINITY));
    //error handling
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("expm1(710) = %f\n", expm1(710));
    if (errno == ERANGE)
        perror("    errno == ERANGE");
    if (fetestexcept(FE_OVERFLOW))
        puts("    FE_OVERFLOW raised");
}

出力例:

expm1(1) = 1.718282
Interest earned in 2 days on $100, compounded daily at 1%
 on a 30/360 calendar = 0.005556
exp(1e-16)-1 = 0, but expm1(1e-16) = 1e-16
expm1(-0) = -0.000000
expm1(-Inf) = -1.000000
expm1(710) = inf
    errno == ERANGE: Result too large
    FE_OVERFLOW raised

参考文献

  • C23規格 (ISO/IEC 9899:2024):
  • 7.12.6.3 expm1関数 (p: TBD)
  • 7.25 総称数学 <tgmath.h> (p: TBD)
  • F.10.3.3 expm1関数 (p: TBD)
  • C17規格 (ISO/IEC 9899:2018):
  • 7.12.6.3 expm1関数 (p: 177)
  • 7.25 総称数学 <tgmath.h> (p: 272-273)
  • F.10.3.3 expm1関数 (p: 379)
  • C11規格 (ISO/IEC 9899:2011):
  • 7.12.6.3 expm1関数 (p: 243)
  • 7.25 型総称数学 <tgmath.h> (p: 373-375)
  • F.10.3.3 expm1関数 (p: 521)
  • C99規格 (ISO/IEC 9899:1999):
  • 7.12.6.3 expm1関数 (p: 223-224)
  • 7.22 総称数学 <tgmath.h> (p: 335-337)
  • F.9.3.3 expm1関数 (p: 458)

関連項目

(C99) (C99)
指定された累乗に e を累乗した値を計算する ( e x )
(関数)
(C99) (C99) (C99)
指定された累乗に 2 を累乗した値を計算する ( 2 x )
(関数)
(C99) (C99) (C99)
1 に指定された数値を加えた値の自然(底 e )対数を計算する ( ln(1+x) )
(関数)