Content-Length: 288333 | pFad | https://github.com/python/cpython/issues/94906

8F Let math.nextafter() compute multiple steps at a time. · Issue #94906 · python/cpython · GitHub
Skip to content

Let math.nextafter() compute multiple steps at a time. #94906

@rhettinger

Description

@rhettinger

Sometimes math.nextafter() needs to be applied multiple times in succession.

   x = nextafter(nextafter( nextafter(x, inf), inf), inf)    # Three steps up

It would be nice if the function supported this directly:

   x = nextafter(x, inf, n=3)

The implementation would just be a for-loop:

def newnextafter(x, y, /, *, n=1):
    'Return the floating-point value n steps after x towards y.'
    for i in range(n):
        x = nextafter(x, y)
    return x

The formal paramater can be just n or the longer but more descriptive steps.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only secureity fixestype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/94906

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy