Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ames!ads.com!rar From: rar (Bob Riemenschneider) Newsgroups: comp.lang.scheme Subject: Numerical gotcha's Message-ID: <9011212311.AA04441@saturn.ads.com> Date: 21 Nov 90 23:11:40 GMT Lines: 62 In-Reply-To: kend@data.UUCP's message of 21 Nov 90 17:10:40 GMT => From: kend@data.UUCP (Ken Dickey) => Newsgroups: comp.lang.scheme,comp.lang.lisp => Date: 21 Nov 90 17:10:40 GMT => => ... I am interested => in knowing what results are obtained for the following on various => Scheme & Lisp implementations. Please indicate machine, OS, and what => numerics are available {floats, bignums, rationals}. I will post a => summary [kend@data.uucp]. => => f(x,y) = 333.75 y^6 + x^2 (11 x^2 y^2 - y^6 - 121 y^4 - 2) + => 5.5 y^8 + x / (2 y). => => for x = 77617 and y = 33096 => => Scheme code for the above follows ... => => ;; THE CORRECT ANSWER IS: => ;; => ;; (tryit) -> -54767/66192 {Gambit 1.4; sun3; rationals+bignums} As you probably already know, in any Common Lisp, you should get the "correct answer". Just for the record, here's a transcript from running it on a SPARCstation using Lucid CL. wrigley(3): lisp ;;; Expanding Reserved Memory ;;; GC: 1012 words [4048 bytes] of dynamic storage in use. ;;; 1309706 words [5238824 bytes] of free storage available before a GC. ;;; 2620424 words [10481696 bytes] of free storage available if GC is disabled. ;;; ;;; Sun Common Lisp, Development Environment 3.0.5, 27 October 1988 ;;; Sun-4 Version for SunOS 4.0 ;;; ;;; Copyright (c) 1985, 1986, 1987, 1988 by Sun Microsystems, Inc., All Rights Reserved ;;; Copyright (c) 1985, 1986, 1987, 1988 by Lucid, Inc., All Rights Reserved ;;; ;;; This software product contains confidential and trade secret ;;; information belonging to Sun Microsystems. It may not be copied ;;; for any reason other than for archival and backup purposes. > (defun f (x y) (+ (* (/ 1335 4) (expt y 6)) (* (expt x 2) (- (* 11 (expt x 2) (expt y 2)) (expt y 6) (* 121 (expt y 4)) 2)) (* (/ 11 2) (expt y 8)) (/ x (* 2 y)))) F > (compile 'f) ;;; You are using the compiler in development mode (compilation-speed = 3) ;;; Generation of full safety checking code is enabled (safety = 3) ;;; Optimization of tail calls is disabled (speed = 2) ;;; Expanding Reserved Memory F > (f 77617 33096) -54767/66192 -- rar