Rate This Document
Findability
Accuracy
Completeness
Readability

trunc

Return the value rounded towards zero for x.

Interface Definition

C interface:

float truncf(float x);

double trunc(double x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For truncf, x is of single-precision floating-point type.
  • For trunc, x is of double-precision floating-point type.

Floating-point value of the input data

Input

Return Value

  • The value rounded towards zero for x is returned. x ∈ (-INF, INF).
  • If the input is +0, the return value is +0.
  • If the input is -0, the return value is -0.
  • If the input is ±∞, the return value is ±∞.
  • If the input is NaN, the return value is NaN.

Dependencies

C: "km.h"

Examples

C interface:
    // typical usage
    double x1 = 0.0, x2 = -0.0, x3 = 1.4, x4 = -2.7;
    // special handing
    double a = INFINITY, b = -INFINITY, c = NAN;
    printf("trunc(0.0) = %.15f\n", trunc(x1));
    printf("trunc(-0.0) = %.15f\n", trunc(x2));
    printf("trunc(1.4) = %.15f\n", trunc(x3));
    printf("trunc(-2.7) = %.15f\n", trunc(x4));
    printf("trunc(INFINITY) = %.15f\n", trunc(a));
    printf("trunc(-INFINITY) = %.15f\n", trunc(b));
    printf("trunc(NAN) = %.15f\n", trunc(c));
    /* 
     * trunc(0.0) = 0.000000000000000
     * trunc(-0.0) = -0.000000000000000
     * trunc(1.4) = 1.000000000000000
     * trunc(-2.7) = -2.000000000000000
     * trunc(INFINITY) = inf
     * trunc(-INFINITY) = -inf
     * trunc(NAN) = nan
     * */