Jason Grout wrote:
> mabshoff wrote:
>> vger reported the following odd behavior in #sage-devel. Looks like a
>> bug to me. If so can someone open a ticket?
>>
>> Cheers,
>>
>> Michael
>>
>> ----------------------------------------------------------------------
>> | SAGE Version 3.1.2, Release Date: 2008-09-16                       |
>> | Type notebook() for the GUI, and license() for information.        |
>> ----------------------------------------------------------------------
>>
>> sage: srange(0,1,0.1,include_endpoint=true)
>>
>> [0.000000000000000,
>>  0.100000000000000,
>>  0.200000000000000,
>>  0.300000000000000,
>>  0.400000000000000,
>>  0.500000000000000,
>>  0.600000000000000,
>>  0.700000000000000,
>>  0.800000000000000,
>>  0.900000000000000,
>>  1.00000000000000]
>> sage: srange(0.5,1,0.1,include_endpoint=true)
>>
>> [0.500000000000000,
>>  0.600000000000000,
>>  0.700000000000000,
>>  0.800000000000000,
>>  0.900000000000000,
>>  1.00000000000000,
>>  1.10000000000000]
>> sage:
> 
> My guess is that this is related to: 
> http://groups.google.com/group/sage-devel/browse_thread/thread/d92823169658d969/013037cc62c6a260?lnk=gst&q=srange#013037cc62c6a260

The problem seems to be in lines 698-701 in misc.py:

             count = (end-start)/step
             if count == int(float(count)):
                 end += step

It seems here that if the number of steps calculated to the endpoint is 
exactly the number of steps we thought, then we mistakenly go one more 
than we need.  Perhaps the if statement should have some fuzz in the 
floating point arithmetic.

Incidentally, I also think that part of the problem here is that sage 
takes the shortcut that a+6*b is the same as a+b+b+b+b+b+b (see line 713 
in misc.py, "# we assume that a+b*c = a + b + ... + b")

Ah, the joys of inexact arithmetic!

sage: a=0.5
sage: b=0.1
sage: a+b+b+b+b+b
1.00000000000000
sage: a+b+b+b+b+b<1.0
True
sage: a+b+b+b+b+b+b<1.1
False
sage: a+b+b+b+b+b+b == a+6*b
False
sage: a+6*b == 1.1
True

Jason


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to