in reply to How to get better exponentiation?

I had my doubts and did some quick research

German Wikipedia states that it's disputed, if the cube root of a negative real number was defined.°

I couldn't find it in English sources in the hurry, but I suppose it's the old problem of having functions which fulfill certain qualities like reversibility in order to play well with the whole mathematical model.

In the end you'll have to handle two definitions of odd roots.

Hence your approach to define your own sub cube_root() looks fine for me. :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) https://de.wikipedia.org/wiki/Wurzel_(Mathematik)#Wurzeln_aus_negativen_Zahlen

update

Here the google translate for the laziest of lazy ...

Replies are listed 'Best First'.
Re^2: How to get better exponentiation? (undefined)
by syphilis (Archbishop) on Jan 24, 2022 at 12:28 UTC
    German Wikipedia states that it's disputed, if the cube root of a negative real number was defined

    I finally got around to taking a look at the C89, C99 and C11 standards.
    There's no mention of "cbrt" in C89, but in C99 and C11 it's quite acceptable for cbrt/cbrtf/cbrtl to take a negative argument.
    However, if pow/powf/powl are given a first argument that is negative && the second argument has a non-integer value, then a "domain error" occurs.

    Cheers,
    Rob
      Yes, thanks.

      But I was talking about mathematical definitions and these are CS standards.

      For instance: pure math has no big notion of floating point numbers.

      Personally I'm fine with allowing root($x,$o) with $x<0 and $o odd integer in a computer.

      But I could imagine reasons in the realm of mathematical modeling of functions to consider them undefined.

      > the second argument has a non-integer value

      I'd say because there is no way to express 1/$o loss free as binary floating point number ('$o odd integer')

      update

      see also https://en.wikipedia.org/wiki/Cube_root#Complex_numbers

        With this definition, the principal cube root of a negative number is a complex number, and for instance 3√−8 will not be −2, but rather 1 + i√3.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        see also https://en.wikipedia.org/wiki/Cube_root#Complex_numbers

        I don't think they are intending to cast aspersions on the validity of taking a cube root of a -ve Real number.
        They even state "For real numbers, we can define a unique cube root of all real numbers.".
        They follow that immediately with "If this definition is used, the cube root of a negative number is a negative number."
        That wording is a bit odd, but I don't think they're suggesting that there's some alternative stance to take wrt cube roots of -ve Real numbers in the *Real* field.
        Rather, I think they're acknowledging that this definition is deficient in the Complex field (even for -ve Real numbers in the Complex field) because, in the *Complex* field, the relationship between a -ve Real and its cube root is no longer one-to-one. It's one-to-three.

        Cheers,
        Rob