Skip to content

nthroot function #47565

@stevengj

Description

@stevengj

@oscardssmith mentioned on discourse that IEEE 2018 recommends an nthroot(x, n) that computes the real nth-root of a real x, similar to the Matlab function nthroot and generalizing cbrt.

A possible implementation could be as simple as:

nthroot(x::Real, n::Integer) =
    isodd(n) || x  0 ? copysign(abs(x)^(1//n), x) :
    throw(DomainError("Exponentiation yielding a complex result requires a complex argument.  Replace nthroot(x, n) with complex(x)^(1//n)."))

though it's possible that we could have faster/more-accurate implementations in some special cases.

As discussed in #36534, it probably only makes sense to define this for x::Real arguments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestsmathsMathematical functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions