From e90988a097746c0bbef5b690d94da6541699485a Mon Sep 17 00:00:00 2001 From: Jay Belanger Date: Sat, 7 Jul 2007 04:15:40 +0000 Subject: [PATCH] (math-read-number): Replace number by variable. (math-read-number-simple): Properly parse small integers. --- lisp/ChangeLog | 5 +++++ lisp/calc/calc.el | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f362942db4c..4aedca28f86 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2007-07-07 Jay Belanger + + * calc/calc.el (math-read-number): Replace number by variable. + (math-read-number-simple): Properly parse small integers. + 2007-07-07 Dan Nicolaescu * vc.el: Fix doc for the checkout function. diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el index d81c1070b9f..922a7c8d7f8 100644 --- a/lisp/calc/calc.el +++ b/lisp/calc/calc.el @@ -3401,6 +3401,7 @@ largest Emacs integer.") ;;; Parse a simple number in string form. [N X] [Public] (defun math-read-number (s) + "Convert the string S into a Calc number." (math-normalize (cond @@ -3411,7 +3412,7 @@ largest Emacs integer.") (> (length digs) 1) (eq (aref digs 0) ?0)) (math-read-number (concat "8#" digs)) - (if (<= (length digs) 6) + (if (<= (length digs) (* 2 math-bignum-digit-length)) (string-to-number digs) (cons 'bigpos (math-read-bignum digs)))))) @@ -3459,13 +3460,20 @@ largest Emacs integer.") ;;; Parse a very simple number, keeping all digits. (defun math-read-number-simple (s) + "Convert the string S into a Calc number. +S is assumed to be a simple number (integer or float without an exponent) +and all digits are kept, regardless of Calc's current precision." (cond ;; Integer ((string-match "^[0-9]+$" s) - (cons 'bigpos (math-read-bignum s))) + (if (<= (length s) (* 2 math-bignum-digit-length)) + (string-to-number s) + (cons 'bigpos (math-read-bignum s)))) ;; Minus sign ((string-match "^-[0-9]+$" s) - (cons 'bigneg (math-read-bignum (substring s 1)))) + (if (<= (length s) (1+ (* 2 math-bignum-digit-length))) + (string-to-number s) + (cons 'bigneg (math-read-bignum (substring s 1))))) ;; Decimal point ((string-match "^\\(-?[0-9]*\\)\\.\\([0-9]*\\)$" s) (let ((int (math-match-substring s 1)) -- 2.39.2