Re: An arithmetic puzzle, equality of numbers.
- To: mathgroup at smc.vnet.net
- Subject: [mg103088] Re: An arithmetic puzzle, equality of numbers.
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Tue, 8 Sep 2009 05:54:34 -0400 (EDT)
- References: <h829m8$3ue$1@smc.vnet.net>
On 2009.09.07. 8:36, Richard Fateman wrote: > For[i = 1.11111111111111111111, i> 0, Print[i = 2*i - i]] > > This came to my attention (again), and I thought it might amuse > current readers of this newsgroup. > > What looks like an infinite loop terminates with i==0 being true. also > i==2 is true. (Tested in Mathematica 6.0; I don't have access to 7 yet.) > It's because of precision loss: For[i = 1.11111111111111111111, i > 0, Print[i = 2*i - i, "\t", Precision[i]]] For similar results to what C/Fortran/etc. would give (no high precision arithmetic with precision tracking), use machine precision numbers: For[i = 1.1111111111111111, i > 0, Print[i = 2*i - i, "\t", Precision[i]]]