Re: Bizarre arithmetic results

2010-02-27 Thread Aahz
In article , Steven D'Aprano wrote: > >[st...@sylar ~]$ cat ws-example.rb Ahhh, you're a Heroes fan. ;-) -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "Many customs in this life persist because they ease friction and promote productivity as a result of unive

Re: Bizarre arithmetic results

2010-02-23 Thread Steven D'Aprano
On Tue, 23 Feb 2010 05:48:09 -0800, Mark Dickinson wrote: > On Feb 23, 8:11 am, Steven D'Aprano > wrote: >> Making spaces significant in that fashion is mind-bogglingly awful. >> Let's look at a language that does this: >> >> [st...@sylar ~]$ cat ws-example.rb >> def a(x=4) >>     x+2 >> end >> >

Re: Bizarre arithmetic results

2010-02-23 Thread Mark Dickinson
On Feb 23, 8:11 am, Steven D'Aprano wrote: > Making spaces significant in that fashion is mind-bogglingly awful. Let's > look at a language that does this: > > [st...@sylar ~]$ cat ws-example.rb > def a(x=4) >     x+2 > end > > b = 1 > print (a + b), (a+b), (a+ b), (a +b), "\n" > > [st...@sylar ~]

Re: Bizarre arithmetic results

2010-02-23 Thread Steven D'Aprano
On Mon, 22 Feb 2010 18:01:44 +, Albert van der Horst wrote: > In article , > Terrence Cole wrote: >>Can someone explain to me what python is doing here? >> >>Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) [GCC 4.3.4] on linux2 >>Type "help", "copyright", "credits" or "license" for more inf

Re: Bizarre arithmetic results

2010-02-22 Thread Albert van der Horst
In article , Terrence Cole wrote: >Can someone explain to me what python is doing here? > >Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) >[GCC 4.3.4] on linux2 >Type "help", "copyright", "credits" or "license" for more information. -0.1 ** 0.1 Python 4.0 Warning: misleading blank space,

Re: Bizarre arithmetic results

2010-02-12 Thread Jussi Piitulainen
Terry Reedy writes: > On 2/12/2010 4:40 AM, Jussi Piitulainen wrote: > > Terry Reedy writes: > >> On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: > >>> Robert Kern writes: > On 2010-02-11 06:31 AM, Shashwat Anand wrote: > > There is a little issue here that '>>> -.1 ** .1' should give yo

Re: Bizarre arithmetic results

2010-02-12 Thread Terry Reedy
On 2/12/2010 4:40 AM, Jussi Piitulainen wrote: Terry Reedy writes: On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: Robert Kern writes: On 2010-02-11 06:31 AM, Shashwat Anand wrote: There is a little issue here that '>>> -.1 ** .1' should give you error message. That is it. No, fractional

Re: Bizarre arithmetic results

2010-02-12 Thread Jussi Piitulainen
Terry Reedy writes: > On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: > > Robert Kern writes: > >> On 2010-02-11 06:31 AM, Shashwat Anand wrote: > >>> There is a little issue here that '>>> -.1 ** .1' should give you > >>> error message. That is it. > >> > >> No, fractional powers of negative numb

Re: Bizarre arithmetic results

2010-02-12 Thread Grant Edwards
On 2010-02-11, Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. -0.1 ** 0.1 > -0.7943282347242815 a = -0.1; b

Re: Bizarre arithmetic results

2010-02-11 Thread Aahz
In article , Grant Edwards wrote: > >Didn't we just do this one last week? Let's do the Time Warp again! -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as

Re: Bizarre arithmetic results

2010-02-11 Thread Terry Reedy
On 2/11/2010 11:23 AM, Jussi Piitulainen wrote: Robert Kern writes: On 2010-02-11 06:31 AM, Shashwat Anand wrote: There is a little issue here that '>>> -.1 ** .1' should give you error message. That is it. No, fractional powers of negative numbers are perfectly valid mathematically. The res

Re: Bizarre arithmetic results

2010-02-11 Thread Jussi Piitulainen
Robert Kern writes: > On 2010-02-11 06:31 AM, Shashwat Anand wrote: > > There is a little issue here that '>>> -.1 ** .1' should give you > > error message. That is it. > > No, fractional powers of negative numbers are perfectly valid > mathematically. The result is a complex number. In Python 3 (

Re: Bizarre arithmetic results

2010-02-11 Thread Robert Kern
On 2010-02-11 06:31 AM, Shashwat Anand wrote: Do you really believe that -0.1 ** 0.1 is a valid computational problem ? Can you raise a negative number to a fractional power ? Output on my console (python 2.6) >>> -.1 ** .1 -0.79432823472428149 >>> a,b = -.1,.1 >>> a**b Traceback (most recent

Re: Bizarre arithmetic results

2010-02-11 Thread Mark Dickinson
On Feb 11, 1:38 pm, Duncan Booth wrote: > Tim Chase wrote: > > But perhaps Py3 changes evaluation, returning an complex number. > > Yes, the change is documented > athttp://docs.python.org/3.1/reference/expressions.html#the-power-operator > > If it is in any of the "What's new in Python x.xx" do

Re: Bizarre arithmetic results

2010-02-11 Thread Duncan Booth
Tim Chase wrote: > But perhaps Py3 changes evaluation, returning an complex number. Yes, the change is documented at http://docs.python.org/3.1/reference/expressions.html#the-power-operator If it is in any of the "What's new in Python x.xx" documents or in a PEP somewhere I haven't spotted it

Re: Bizarre arithmetic results

2010-02-11 Thread Daniel Fetchinson
On 2/11/10, Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. -0.1 ** 0.1 > -0.7943282347242815 a = -0.1; b = 0.

Re: Bizarre arithmetic results

2010-02-11 Thread Tim Chase
Terrence Cole wrote: Can someone explain to me what python is doing here? Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. -0.1 ** 0.1 -0.7943282347242815 a = -0.1; b = 0.1 a ** b (0.75545104371175

Re: Bizarre arithmetic results

2010-02-11 Thread Jussi Piitulainen
Terrence Cole writes: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> -0.1 ** 0.1 > -0.7943282347242815 > >>> a = -0.1; b = 0.1 > >>>

Re: Bizarre arithmetic results

2010-02-11 Thread Shashwat Anand
Just realized my flaw >>> .1**.1 0.79432823472428149 >>> (-.1)**(.1) Traceback (most recent call last): File "", line 1, in ValueError: negative number cannot be raised to a fractional power - a ** b = - (a ** b) and not (-a) ** b, Thats why -.1**.1 giving you -0.79432823472428149 since .1 **

Re: Bizarre arithmetic results

2010-02-11 Thread Christian Heimes
Terrence Cole wrote: -0.1 ** 0.1 > -0.7943282347242815 a = -0.1; b = 0.1 a ** b > (0.7554510437117542+0.2454609236416552j) -abs(a ** b) > -0.7943282347242815 > > Why does the literal version return the signed magnitude and the > variable version return a complex? The binary po

Re: Bizarre arithmetic results

2010-02-11 Thread Shashwat Anand
Do you really believe that -0.1 ** 0.1 is a valid computational problem ? Can you raise a negative number to a fractional power ? Output on my console (python 2.6) >>> -.1 ** .1 -0.79432823472428149 >>> a,b = -.1,.1 >>> a**b Traceback (most recent call last): File "", line 1, in ValueError: neg

Re: Bizarre arithmetic results

2010-02-11 Thread Peter Otten
Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. -0.1 ** 0.1 > -0.7943282347242815 a = -0.1; b = 0.1 a **

Re: Bizarre arithmetic results

2010-02-11 Thread Mark Dickinson
On Feb 11, 12:44 am, Terrence Cole wrote: > Can someone explain to me what python is doing here? > >>> -0.1 ** 0.1 > -0.7943282347242815 Here you're computing -(0.1 ** 0.1). The exponentiation operator binds more strongly than the negation operator. > >>> a = -0.1; b = 0.1 > >>> a ** b > (0.75

Re: Bizarre arithmetic results

2010-02-11 Thread Andre Engels
On Thu, Feb 11, 2010 at 1:44 AM, Terrence Cole wrote: > Can someone explain to me what python is doing here? > > Python 3.1.1 (r311:74480, Feb  3 2010, 13:36:47) > [GCC 4.3.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. -0.1 ** 0.1 > -0.7943282347242815

Bizarre arithmetic results

2010-02-11 Thread Terrence Cole
Can someone explain to me what python is doing here? Python 3.1.1 (r311:74480, Feb 3 2010, 13:36:47) [GCC 4.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> -0.1 ** 0.1 -0.7943282347242815 >>> a = -0.1; b = 0.1 >>> a ** b (0.7554510437117542+0.24546092364