Rate This Document
Findability
Accuracy
Completeness
Readability

finite

Check whether the input x is a finite number. The return value is an integer.

Interface Definition

C interface:

int finitef(float x);

int finite(double x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For finitef, x is of single-precision floating-point type.
  • For finite, x is of double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • Result that determines whether x is a finite number.
  • If the input is a floating-point number, the return value is 1.
  • If the input is ±∞, the return value is 0.
  • If the input is NaN, the return value is 0.

Dependencies

C: "km.h"

Examples

C interface:
    // typical usage
    double x1 = 0.0, x2 = -0.0, x3 = 1.5, x4 = -2.5;
    // special handling
    double a = INFINITY, b = -INFINITY, c = NAN;
    // print result
    printf("finite(0.0) = %d\n", finite(x1));
    printf("finite(-0.0) = %d\n", finite(x2));
    printf("finite(1.5) = %d\n", finite(x3));
    printf("finite(-2.5) = %d\n", finite(x4));
    printf("finite(INFINITY) = %d\n", finite(a));
    printf("finite(-INFINITY) = %d\n", finite(b));
    printf("finite(NAN) = %d\n", finite(c));
    /* 
     * finite(0.0) = 1
     * finite(-0.0) = 1
     * finite(1.5) = 1
     * finite(-2.5) = 1
     * finite(INFINITY) = 0
     * finite(-INFINITY) = 0
     * finite(NAN) = 0
     * 
     * */