in reply to Re: root function
in thread root function

linux:
$ perl -le'print -3 ** (1/3)' -1.44224957030741
ActivePerl:
>perl -le"print -3 ** (1/3)" -1.44224957030741

Update: Oops, precedence problem

$ perl -le'print( (-3) ** (1/3) )' nan
>perl -e"print( (-3) ** (1/3) )" -1.#IND

Replies are listed 'Best First'.
Re^3: root function
by psini (Deacon) on Jun 21, 2008 at 21:42 UTC
    sini@ordinalfabetix:~$ perl -le"print ((-3)**(1/3));" nan sini@ordinalfabetix:~$

    Exponent operator ** has higher priority than unary minus so you are doing -(3**(1/3)) instead of ((-3)**(1/3)).

    This gives you accidentally the right result but it would tell you that square root of -2 == -1.414265...

    Careful with that hash Eugene.

      Too slow!

      This gives you accidentally the right result but it would tell you that square root of -2 == -1.414265...

      But -1.414265... is a square root of 2. :)

      Update: Ack! ignore this post.

        More to the point: it is not the square root of -2.

        sas

        Too slow?

        No, it is only that if I wait before answering, my answers worth more... proposition for Voting system :)

        Careful with that hash Eugene.