There are two interesting questions about the 1926/100 example. (1) Why are there extra digits at the end? (A1.1) Because floating-point arithmetic is imprecise. (A1.2) Because the default behaviour is to show answers quite precisely. (Note: it is IMPORTANT to be able to write out a floating point number, read it back, and get the *SAME* number you started with. At one time Quintus Prolog got that wrong, VERY embarrassing. The Scheme standards actually require write/read round-tripping.) (2) Why are the extra digits at the end DIFFERENT from what one gets from C? (A2.1) Idunno, why ARE they different? ============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------
(1) Why are there extra digits at the end? (A1.1) Because floating-point arithmetic is imprecise. (A1.2) Because the default behaviour is to show answers quite precisely.
Because (A1.1) and, aiming at (A1.2), the default behavior was to show more digits than IEEE arithmetic ensures to be correct.
(Note: it is IMPORTANT to be able to write out a floating point number, read it back, and get the *SAME* number you started with. At one time Quintus Prolog got that wrong, VERY embarrassing. The Scheme standards actually require write/read round-tripping.)
Yes, true. Indeed, the ISO Prolog standard requires that if the quoted(true) write-option is effective.
(2) Why are the extra digits at the end DIFFERENT from what one gets from C? (A2.1) Idunno, why ARE they different?
Because printf is not used to generate and print the result.
Hi, I'm checking the problem with the 19.26 example. At this moment I don't know what happen with Ciao Prolog, but the correct value is the given by the C language.
I made a test, with the next results:
19.26 converted to IEEE 64 bits is: 1 .0011010000101000111101011100001010001111010111000011(in base 2) * 2^4 (you can see that in http://babbage.cs.qc.edu/courses/cs341/IEEE-754.html)
calculating this value in base 10 with about 50 decimal digits in bc: 19.260000000000001563194018672220408916473388671875
using printf("\nX = %.20lf\n", 19.26) in GNU C language gives: X = 19.26000000000000156319
using X is 19.26 in Ciao Prolog 1.8 gives: X = 19.2600000000000029
Obviously, the prolog value is wrong.
I hope that this remark help to understand the problem,
Edison. ============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------