Interval with floats has nil element , bug or feature?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Interval with floats has nil element , bug or feature?

Christopher J. Demers
If one inspects the code bellow one will find that the last element is nil.
(120.0 to: 135.0 by: 0.3) collect: [:temp | temp].

The code bellow works as expected.
(120.0s to: 135.0s by: 0.3s) collect: [:temp | temp].

I roughly understand and accept the math issue.  It has to do with the
imprecise representation of floats in binary form.  However I am not sure if
Dolphin should include nil as the last element in the first example.  Is
this a bug or feature?

I guess the moral of the story is to always use ScaledDecimal's rather than
Float's with Intervals.

Chris


Reply | Threaded
Open this post in threaded view
|

Re: Interval with floats has nil element , bug or feature?

John Brant
"Christopher J. Demers" <[hidden email]> wrote in
message news:akj7mg$1iov2a$[hidden email]...
> If one inspects the code bellow one will find that the last element is
nil.
> (120.0 to: 135.0 by: 0.3) collect: [:temp | temp].
>
> The code bellow works as expected.
> (120.0s to: 135.0s by: 0.3s) collect: [:temp | temp].
>
> I roughly understand and accept the math issue.  It has to do with the
> imprecise representation of floats in binary form.  However I am not sure
if
> Dolphin should include nil as the last element in the first example.  Is
> this a bug or feature?

Interval>>collect: is buggy. It is calculating the values by adding them up
instead of doing "start + (step * i)". If you remove the Interval>>collect:
method, then everything seems to work fine. SequenceableCollection>>collect:
uses the same method that #do: uses.


John Brant