[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [newbie] unexpected behaviour for x^x
From: |
Bård Skaflestad |
Subject: |
Re: [newbie] unexpected behaviour for x^x |
Date: |
Fri, 12 Dec 2014 13:32:18 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 |
On 12/12/14 13:16, Jean Dubois wrote:
octave:1> 0.001^0.001
This compute x^x for x = 1e-3.
octave:2> -0.001^-0.001
This computes -(abs(x)^x) for x = -1e-3 because the exponentiation
operator binds more tightly than "-". You need to say
(-0.001)^-0.001
or the fully parenthesised expression
(-0.001)^(-0.001)
to get what you want. You'd get this behaviour automatically if you'd
use an intermediate variable 'x' to hold the value -0.001 rather than
writing the expression using explicit constants;
x = -0.001;
x^x
Sincerely,
--
Bård Skaflestad <address@hidden>
SINTEF ICT, Applied Mathematics