[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [newbie] unexpected behaviour for x^x
From: |
Jean Dubois |
Subject: |
Re: [newbie] unexpected behaviour for x^x |
Date: |
Fri, 12 Dec 2014 13:47:23 +0100 |
2014-12-12 13:40 GMT+01:00 Julien Bect <address@hidden>:
> Le 12/12/2014 13:16, Jean Dubois a écrit :
>>
>> I was surprised to found out that when I calculated x^x with octave, using
>> floats which approach zero I get two different results depending on the
>> direction
>> in which zero is approached, this is what I mean:
>>
>> octave:1> 0.001^0.001
>> ans = 0.99312
>>
>> octave:2> -0.001^-0.001
>> ans = -1.0069
>
>
> Hello Jean,
>
> First thing, be careful with operator precedence:
>
> octave:1> -0.001^-0.001== - (0.001 ^ (- 0.001))
> ans = 1
>
> So the minus sign in front of your second expression gives the minus sign in
> front of your second result, nothing surprising.
>
>
> Now, without the minus sign, I get
>
> octave:1> format short
>
> octave:2> 0.001^0.001
> ans = 0.99312
>
> octave:3> 0.001^-0.001
> ans = 1.0069
>
> which is the correct result, because
>
> octave:4> 1 / (0.001^-0.001)
> ans = 0.99312
>
>
> Last thing, x^x with a negative x will give you a complex result, but still
> converging to 1:
>
> octave:5> (-0.001) ^ (-0.001)
> ans = 1.00692669984728 - 0.00316336393000065i
>
> octave:6> (-1e-10) ^ (-1e-10)
> ans = 1.00000000230259 - 3.14159266082358e-10i
>
>
> I hope this helps.
>
Julien and Bärd, I now see my error, thanks for taking the time to
explain it to me
jean