From ba4ed58519a513c7395f35ac5d85f104e21ad4d7 Mon Sep 17 00:00:00 2001 From: toy <toy> Date: Wed, 19 Jun 2002 15:08:55 +0000 Subject: [PATCH] A ratio divided by zero was returning 1/0 instead of signaling an error. Catch this in BUILD-RATIO and signal a divide-by-zero error. Based on the bug report and patch by Wolfhard Buss. --- code/numbers.lisp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/code/numbers.lisp b/code/numbers.lisp index b996425e6..06275f036 100644 --- a/code/numbers.lisp +++ b/code/numbers.lisp @@ -5,7 +5,7 @@ ;;; Carnegie Mellon University, and has been placed in the public domain. ;;; (ext:file-comment - "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/numbers.lisp,v 1.41 2002/03/14 21:29:42 toy Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/numbers.lisp,v 1.42 2002/06/19 15:08:55 toy Exp $") ;;; ;;; ********************************************************************** ;;; @@ -244,12 +244,17 @@ (declaim (inline build-ratio)) (defun build-ratio (num den) (multiple-value-bind (num den) - (if (minusp den) - (values (- num) (- den)) - (values num den)) - (if (eql den 1) - num - (%make-ratio num den)))) + (if (minusp den) + (values (- num) (- den)) + (values num den)) + (cond ((eql den 1) + num) + ((eql den 0) + (error 'division-by-zero + :operands (list num den) + :operation 'build-ratio)) + (t + (%make-ratio num den))))) ;;; MAYBE-TRUNCATE -- Internal -- GitLab