Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!hao!ames!elroy!cit-vax!ucla-cs!zen!ucbvax!ji.Berkeley.EDU!holmer From: holmer@ji.Berkeley.EDU (Bruce K. Holmer) Newsgroups: comp.lang.prolog Subject: Integer/floating point type conversion in Prolog Message-ID: <21812@ucbvax.BERKELEY.EDU> Date: Mon, 16-Nov-87 21:43:14 EST Article-I.D.: ucbvax.21812 Posted: Mon Nov 16 21:43:14 1987 Date-Received: Thu, 19-Nov-87 05:31:22 EST Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: holmer@ji.Berkeley.EDU (Bruce K. Holmer) Followup-To: comp.lang.prolog Organization: University of California, Berkeley Lines: 46 [] In your opinion, what is the proper behavior of the following code fragments? % Is type conversion is done before test? main1 :- a(1.0, 1). a(X, Y) :- X == Y, write(a), fail. a(X, Y) :- X = Y, write(b), fail. a(X, Y) :- X =:= Y, write(c), fail. % What about round-off errors? main2 :- X is (2.0/7.0)*7.0, Z is X - 2.0, write(Z), b(X, 2.0). b(X, Y) :- X == Y, write(a), fail. b(X, Y) :- X = Y, write(b), fail. b(X, Y) :- X =:= Y, write(c), fail. To save you the work, here are the results for prologs we use: C-Prolog (version 1.5) main1: abc main2: 0abc Quintus (VAX version 1.6 interpreted): main1: c main2: -1.9073e-06 Quintus (VAX version 1.6 compiled): main1: c main2: 0.0abc SB-Prolog (version 2.2 compiled) main1: bc main2: -0.000000b As you can see, no one can agree on what the correct answers are! So should type conversion be done before =/2 or ==/2? Quintus says no, C-Prolog says yes, and SB-Prolog is in between. Concerning round-off errors, Quintus compiled code probably computes multi-operation expressions with full precision (and rounds the answer), whereas execution time floating point is 29-bit for all operations. My opinion is that a program should produce identical results, regardless of whether it is interpreted or compiled. SB-Prolog uses an 'EPSILON' during unification to do a 'prettymuch_equal', but I would think that anything that is '=/2' should also be '=:=/2'. Thanks for your comments, Bruce