On 10/31/2016 05:07 PM, Ben Coman wrote:
> So then why don't we *really* help the naive programmer make "x
> roundTo: 0.1" an error?
> Conceptually...
> 
>   Number>>roundTo: quantum
>       quantum < 1 ifTrue: [ quantum isFraction ifFalse: [
> SubtleArithmeticError signal ].
>       ^(self / quantum) rounded * quantum
> 
>   SubtleArithmeticError >> defaultAction
>        self inform: 'Decimals have an inexact Float representation, so
> rounding may not give you what you expect. Us Fractions instead.'.
> 
> cheers -ben
> 

While this is tempting, this philosophy would, I'm afraid, lead to
signaling this error on *all* uses of Floats, because Floats are *full*
of this kind of behavior that is surprising to the uninitiated.

Regards,

-Martin

Reply via email to