Rate This Document
Findability
Accuracy
Completeness
Readability

nextafter

Return the next representable value of the specified return format after x in the direction of y.

Interface Definition

C interface:

float nextafterf(float x, float y);

double nextafter(double x, double y);

Parameters

Parameter

Type

Description

Input/Output

x

  • For nextafterf, x is of single-precision floating-point type.
  • For nextafter, x is of double-precision floating-point type.

Floating-point value of the input data.

Input

y

  • For nextafterf, y is of single-precision floating-point type.
  • For nextafter, y is of double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • The next representable value of the specified return format after x in the direction of y is returned.
  • errno: ERANGE is returned in overflow scenarios.
  • The special values are listed in the following table.

    Input Value (x)

    Input Value (y)

    Output Value (result)

    Any value but NaN

    nan

    nan

    nan

    Any value but NaN

    nan

    nan

    nan

    nan

    inf

    inf

    inf

    -inf

    -inf

    -inf

    inf

    -inf

    0x7fefffffffffffff(double)

    0x7f7fffff(float)

    -inf

    inf

    0xffefffffffffffff(double)

    0xff7fffff(float)

Dependency

C: "km.h"

Example

C interface:
    // typical usage
    double x1 = 1.0, y1 = 2.0, x2 = 3.0, y2 = 4.0;
    // print result
    printf("nextafter(x1, y1) = %.15f\n", nextafter(x1, y1));
    printf("nextafter(x2, y2) = %.15f\n", nextafter(x2, y2));
    /*
     * nextafter(x1, y1) = 1.000000000000000
     * nextafter(x2, y2) = 3.000000000000000
     */