Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Floating point modulus - the "why not"



On Jan 13,  5:18pm, Vincent Lefevre wrote:
} Subject: Re: Floating point modulus - the "why not"
}
} On 2015-01-13 10:10:16 +0000, Peter Stephenson wrote:
} > On Mon, 12 Jan 2015 21:38:52 -0800
} > Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > > torch% print $(( 9.1 % 1.3 ))    
} > > 1.2999999999999994
} 
} The problem actually comes from the decimal to binary conversions,

Yes, I know; the point is that you can't guarantee a consistent result
from floating-point division, and this is particularly significant for
modulus because the error may be (almost) as large as the divisor; so
it's easy to see why that operation may have been left unimplemented.

(Compare division

torch% print $(( 9.1 / 1.3 ))     
6.9999999999999991

where the error is a tiny fraction of the result.)



Messages sorted by: Reverse Date, Date, Thread, Author