Python Tutorial Python Advanced Python References Python Libraries

Python math - nextafter() Function



The Python math.nextafter() function returns the next floating-point value after the first argument towards second argument. If both arguments compare as equal a value equivalent to the second argument is returned.

Syntax

#New in version 3.9
math.nextafter(x, y)

Parameters

x Required. Specify the number.
y Required. Specify the number.

Return Value

Returns the next floating-point value after the first argument in the direction of the second argument.

Example:

The example below shows the usage of nextafter() function.

import math

print(math.nextafter(10, 100))
print(math.nextafter(10, -100))
print(math.nextafter(10, 0))

The output of the above code will be:

10.000000000000002
9.999999999999998
9.999999999999998

❮ Python Math Module