[swift-evolution] implementing real (floating point) number comparison tolerance as a compiler directive.

ted van gaalen tedvgiosdev at gmail.com
Tue Mar 1 17:58:41 CST 2016


Yes, in APL it is global, but not in what I propose for Swift here.



ted van gaalen

> On 02 Mar 2016, at 00:48, Joe Groff <jgroff at apple.com> wrote:
> 
> 
>> On Mar 1, 2016, at 3:44 PM, ted van gaalen <tedvgiosdev at gmail.com> wrote:
>> 
>> They are not random tolerances and also not global as one
>> can set a specific (fine tuned) tolerance bandwidth for 1 or more
>> statements, following such a directive, until another, or a reset.
>> e.g.
>>     @floatingPointComparisonTolerance = 0.001 //tuned for a specific situation.
>> 
>>      if a == b {}     // this statement is affected..
>>          
>>       If   c != d {}   // ..and also this one.              
>>      @resetFloatingPointComparisonTolerance  // default is none
>>      if a == b   // here, no longer a tolerance band is active.
>>      
>> 
>> So, it is not global, but only in effect for statements in between/after these directives.
> 
> If we literally follow the APL model, then the tolerance is global state that nonlocally changes the behavior of every operation. We don't do this kind of implicit parameterization anywhere else, and similar features have proven to be brittle to use in practice (see also, for instance, the ability for Perl and some BASIC languages to dynamically set the array index base to 0 or 1, catastrophically breaking any code you call into that expects the other base).
> 
> -Joe
> 
>> Nothing new here. Comparison tolerance has been in use in e.g. APL since ca 1975, see here for a good explanation.
>> 
>> http://microapl.com/apl_help/ch_020_070_150.htm
> 
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160302/9cd5e65b/attachment.html>


More information about the swift-evolution mailing list