The math.nextafter()
method is used to get a float value between x
and y
where x, y are argument values. This return float value will be towards y.
This method
math.nextafter()
is available from the latest version of Python i.e.,Python 3.9
math.nextafter(x, y)
It takes two argument values.
x
: The lower numeric value.y
: The upper numeric value.It will return a single float value.
x=y
, then it will return a y
value.In the code snippet below, we have different argument values.
x=Any_Number
,y=Any_Number
, then it will return the value towards y.x=Any_Number
, y=math.inf
, then it will go up towards positive infinity.x=Any_Number
, y=-math.inf
, then it will go down towards minus infinity.x=Any_Number
, y=0.0
, then it will go towards zero.import mathprint(math.nextafter(3, 4.2))
import mathprint(math.nextafter(3, math.inf))
import mathprint(math.nextafter(3, -math.inf))
import mathprint(math.nextafter(3, 0.0))