On Tue, Dec 9, 2008 at 4:48 PM, Tim Lahey <[EMAIL PROTECTED]> wrote:
>
>
> On Dec 9, 2008, at 7:38 PM, William Stein wrote:
>
>>
>> This is not the answer.  Look at this example:
>>
>> sage: srange(0,1.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,
>> 1.10000000000000,
>> 1.20000000000000]
>>
>> That's not right no matter what.  The documentation says:
>> "        Return list of numbers a, a+step, ..., a+k*step,
>>        where a+k*step < b and a+(k+1)*step > b."
>> where a,b are the first two inputs.
>>
>> Thus the implementation of srange is simply buggy because the person
>> (me!) who implemented didn't take proper care of how floating point
>> numbers behave.
>>
>
> I ran across this in some timestepping code I wrote for a ODE solver
> for systems of second order ODEs. The general trick I used is to set
> the first n-1 terms based upon the formula and set the final one to
> the endpoint. It means that the final one may be shorter, but that way
> it always ends at the set endpoint.

Any chance you could dive in and fixe srange?  It's a pure Python function in
  sage/misc/misc.py

William

--~--~---------~--~----~------------~-------~--~----~
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