IsOdd: Bug?

Torsten Anders torsten.anders at plymouth.ac.uk
Sun Mar 30 13:19:55 CEST 2008


OK, now fixed in SVN.

Torsten

On Mar 18, 2008, at 7:56 AM, Raphael Collet wrote:
> Dear Torsten,
>
> What you observe is a feature of the operator 'mod', which may  
> return a
> negative value.  In math, X mod N is always in the range [0, N-1],  
> even
> for negative values of X.  But most computers don't follow that rule,
> and return -1 for -5 mod 2, for instance.
>
> There is, however, a simple fix in the case of IsOdd.  Just compare  
> the
> result to 0 instead of 1 (and ~1):
>
>     fun {IsOdd X} X mod 2 \= 0 end
>
> Cheers,
> raph
>
> Torsten Anders wrote:
>> Dear all,
>>
>> the function IsOdd currently always returns false for negative  
>> numbers.
>> Is there some reason for this? Otherwise I would change the current
>> implementation
>>
>>   fun {IsOdd X}  X mod 2 == 1 end
>>
>> into
>>
>>  fun {IsOdd X}  {Abs X mod 2} == 1 end
>>
>> Thanks!
>>
>> Best
>> Torsten
>>
>> PS: thanks to Wolfgang for his code navigator: finding the source of
>> IsOdd only took a single key stroke
>> :) 
>> _____________________________________________________________________ 
>> ____________
>>
>> mozart-hackers mailing list
>> mozart-hackers at mozart-oz.org
>> http://www.mozart-oz.org/mailman/listinfo/mozart-hackers
>
> ______________________________________________________________________ 
> ___________
> mozart-hackers mailing list                           mozart- 
> hackers at mozart-oz.org
> http://www.mozart-oz.org/mailman/listinfo/mozart-hackers

--
Torsten Anders
Interdisciplinary Centre for Computer Music Research
University of Plymouth
Office: +44-1752-233667
Private: +44-1752-558917
http://strasheela.sourceforge.net
http://www.torsten-anders.de






More information about the mozart-hackers mailing list