Skip to content
Related Articles

Related Articles

Python math function – nextafter()

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 12 Nov, 2020

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.

Python3




import math
  
  
print(math.nextafter(2, math.inf))

Output:

2.0000000000000004

Example 2: math.nextafter(x, -math.inf) goes down: towards minus infinity.

Python3




import math
  
  
print(math.nextafter(2, -math.inf))

Output:

1.9999999999999998

Example 3: math.nextafter(x, 0.0) goes towards zero.

Python3




import math
  
  
print(math.nextafter(2, 0.0))

Output:

2.0000000000000004


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!