Thank you, everyone!

Note, it appears that the fifth root of -12.17 is not complex, try this:

% perl -wle '$_=(-1.648382957144284)**5; print'

... but I don't blame perl for not finding it.

Thanks for the tips on -wle, and for the info on print.  I'm not sure how
I'll do it, but I really need to remember those things.  This list is
awesome.

- Bryan





> Bryan R Harris wrote:
>> 
>> Can someone explain this behavior?
>> 
>> % perl -e 'print -12.17**0.2, "\n"'
>> -1.64838295714428
> 
> This means
> 
>   print(-(12.17 ** 0.2), "\n")
> 
> because exponentiation has a higher priority than unary minus. (See the table
> of
> priorities in perldoc perlop).
> 
>> % perl -e 'print (-12.17)**(0.2), "\n"'
>> -12.17
> 
> This means
> 
>   (print(-12.17)) ** 0.2, "\n"
> 
> because list operators have a highrt priority than exponentiation.
> 
> What this does is to print -12.17, and then evaluate the fifth root of the
> result of the call to print() which should be 1, and immediately discard this
> value. The newline string after the comma operator is simply thrown away, as
> if
> you'd written
> 
>   (print(-12.17)) ** 0.2;
>   "\n";
> 
>> % perl -e 'print ((-12.17)**(0.2)), "\n"'
>> nan%
> 
> This means
> 
>   print((-12.17) ** 0.2), "\n"
> 
> and Perl prints 'nan' since the fifth root of -12.17 is a complex number. The
> newline is just thrown away as before..
> 
>> Yes, the "\n" isn't getting printed for some reason on the 2nd two examples.
> 
> Because they're not within the print's parameter list.
> 
> 
>> Bottom line:
>> 
>> -12.17**0.2  ==> -1.65
>> (-12.17)**(0.2) ==> -12.17
>> ((-12.17)**(0.2)) ==> nan
>> 
>> I have absolutely zero idea what could be going on here...  Please help!
> 
> HTH,
> 
> Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to