4 ms·
In Pyret, (1 / 3) resolves to (1 / 3), not 0.3333333333333333 or some equivalent, like it does in many other languages. (0.3333333333333333 * 3) is 0.9999999999
by fineIllregister 12y ago
In Pyret, (1 / 3) resolves to (1 / 3), not 0.3333333333333333 or some equivalent, like it does in many other languages. (0.3333333333333333 * 3) is 0.999999999999999, not 1.
- mgraczyk 12y agoThat makes sense, but unfortunately the Pyret page says nothing to indicate that arithmetic is done in the rational field. For the record, 1.0 compares equal to (1.0 / 3) * 3 in IEEE 754 32-bit floating point arithmetic. You may want to consider a more compelling example, ie float x = 1.0; for (int i = 0; i < 10; ++i) { x += 1.0 / 10; } x == 1.0 // False
- shriramkmurthi 12y agoSure. In general there are lots of examples that illustrate the ugliness of using floating points _unnecessarily_.