Skip to content
Related Articles
Python math function – nextafter()
• 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
```

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up