我要评分
获取效率
正确性
完整性
易理解

erf

Error function. The input parameter is a real number.

Interface Definition

C interface:

float erff(float x);

double erf(double x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For erff, x is of single-precision floating-point type.
  • For erf, x is of double-precision floating-point type.

Floating-point value of the input data

Input

Return Value

  • The error function computing result y of the input parameter x is returned. y ∈ [–1, +1]
  • If the input is NaN, the return value is NaN.
  • If the input is +∞, the return value is 1.
  • If the input is –∞, the return value is –1.
  • For the float interface, if x ≥ 0x1.F5AAp1, the return value is 1.
  • For the float interface, if x ≤ –0x1.F5AAp1, the return value is –1.
  • For the double interface, if x ≥ 0x1.7afb48dc96628p+2, the return value is 1.
  • For the double interface, if x ≤ –0x1.7afb48dc96628p+2, the return value is –1.

Dependencies

C: "km.h"

Examples

C interface:
    // print result
    printf("erf(0.0) = %.15f\n", erf(0.0));
    printf("erf(-0.0) = %.15f\n", erf(-0.0));
    printf("erf(0.25) = %.15f\n", erf(0.25));
    printf("erf(-0.25) = %.15f\n", erf(-0.25));
    printf("erf(0.5) = %.15f\n", erf(0.5));
    printf("erf(-0.5) = %.15f\n", erf(-0.5));
    printf("erf(1.0) = %.15f\n", erf(1.0));
    printf("erf(-1.0) = %.15f\n", erf(-1.0));
    printf("erf(2.0) = %.15f\n", erf(2.0));
    printf("erf(-2.0) = %.15f\n", erf(-2.0));
    printf("erf(INFINITY) = %.15f\n", erf(INFINITY));
    printf("erf(-INFINITY) = %.15f\n", erf(-INFINITY));
    printf("erf(NAN) = %.15f\n", erf(NAN));
    printf("erf(-NAN) = %.15f\n", erf(-NAN));
    /* 
     * erf(0.0) = 0.000000000000000
     * erf(-0.0) = -0.000000000000000
     * erf(0.25) = 0.276326390168237
     * erf(-0.25) = -0.276326390168237
     * erf(0.5) = 0.520499877813047
     * erf(-0.5) = -0.520499877813047
     * erf(1.0) = 0.842700792949715
     * erf(-1.0) = -0.842700792949715
     * erf(2.0) = 0.995322265018953
     * erf(-2.0) = -0.995322265018953
     * erf(INFINITY) = 1.000000000000000
     * erf(-INFINITY) = -1.000000000000000
     * erf(NAN) = nan
     * erf(-NAN) = -nan
     * 
     * */