# HG changeset patch # User Jay Belanger # Date 1183781629 0 # Node ID c88370efde0df49ae993dadae27eb18bd04064db # Parent e7f1f230ec0d4d9d31433ea8f7e9e5f17c9d8bea (math-read-number): Replace number by variable. (math-read-number-simple): Properly parse small integers. diff -r e7f1f230ec0d -r c88370efde0d lisp/calc/calc.el --- a/lisp/calc/calc.el Sat Jul 07 01:53:20 2007 +0000 +++ b/lisp/calc/calc.el Sat Jul 07 04:13:49 2007 +0000 @@ -3401,6 +3401,7 @@ ;;; 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 @@ (> (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 @@ ;;; 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))