math.nextafter() is a function introduced in python 3.9.0. nextafter(x,y) returns the next float value after x towards y, if x is equal to y then y is returned.
Syntax: math.nextafter(x, y)
Parameter:
x and y are two integers/floating point values.
Returns:
Return the next floating-point value after x towards y. If x is equal to y, return y.
Example 1: math.nextafter(x, math.inf) goes up: towards positive infinity.
import math
print(math.nextafter(2, math.inf))
Output:
2.0000000000000004
Example 2: math.nextafter(x, -math.inf) goes down: towards minus infinity.
import math
print(math.nextafter(2, -math.inf))
Output:
1.9999999999999998
Example 3: math.nextafter(x, 0.0) goes towards zero.
import math
print(math.nextafter(2, 0.0))
Output:
2.0000000000000004