Re: Floating-point arithmetic in CL
sketerpot_at_gmail.com
Date: 11/22/04
- Next message: Glen Able: "Re: newbie - more on my search program"
- Previous message: Kenny Tilton: "Re: Why the dataflow paradigm?"
- In reply to: Ossi Herrala: "Floating-point arithmetic in CL"
- Next in thread: David Sletten: "Re: Floating-point arithmetic in CL"
- Reply: David Sletten: "Re: Floating-point arithmetic in CL"
- Reply: Christophe Rhodes: "Re: Floating-point arithmetic in CL"
- Reply: Pascal Bourguignon: "Re: Floating-point arithmetic in CL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Nov 2004 13:24:29 -0800
Try this code:
(defmacro define-exact-binary-operation (name)
(let ((x (gensym))
(y (gensym)))
`(defun ,(intern (format nil "~AE" name)) (,x ,y)
(float (,name (rationalize ,x)
(rationalize ,y))))))
(define-exact-binary-operation +)
(define-exact-binary-operation -)
(define-exact-binary-operation *)
(define-exact-binary-operation /)
;; insert any more you want done with rationals inside
(- 0.9 0.5) ; inexact; darn floats
(-e 0.9 0.5) ; As exact as I can get it while still dealing with floats
If I made a mistake here, I invite anybody better-versed in
floating-point arithmetic to point it out to me. It's a definite
possibility.
-Peter Scott
- Next message: Glen Able: "Re: newbie - more on my search program"
- Previous message: Kenny Tilton: "Re: Why the dataflow paradigm?"
- In reply to: Ossi Herrala: "Floating-point arithmetic in CL"
- Next in thread: David Sletten: "Re: Floating-point arithmetic in CL"
- Reply: David Sletten: "Re: Floating-point arithmetic in CL"
- Reply: Christophe Rhodes: "Re: Floating-point arithmetic in CL"
- Reply: Pascal Bourguignon: "Re: Floating-point arithmetic in CL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|