nearbyint
Return the rounded value of x based on the current rounding mode.
Interface Definition
C interface:
float nearbyintf(float x);
double nearbyint(double x);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of the input data |
Input |
Return Value
- The rounded value of 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.5, x4 = -2.5;
// special handing
double a = INFINITY, b = -INFINITY, c = NAN;
// pnearbyint result
printf("nearbyint(0.0) = %.15f\n", nearbyint(x1));
printf("nearbyint(-0.0) = %.15f\n", nearbyint(x2));
printf("nearbyint(1.5) = %.15f\n", nearbyint(x3));
printf("nearbyint(-2.5) = %.15f\n", nearbyint(x4));
printf("nearbyint(INFINITY) = %.15f\n", nearbyint(a));
printf("nearbyint(-INFINITY) = %.15f\n", nearbyint(b));
printf("nearbyint(NAN) = %.15f\n", nearbyint(c));
/*
* nearbyint(0.0) = 0.000000000000000
* nearbyint(-0.0) = -0.000000000000000
* nearbyint(1.5) = 2.000000000000000
* nearbyint(-2.5) = -2.000000000000000
* nearbyint(INFINITY) = inf
* nearbyint(-INFINITY) = -inf
* nearbyint(NAN) = nan
* */
Parent topic: Rounding Functions