Commit e90988a0 authored by Jay Belanger's avatar Jay Belanger
Browse files

(math-read-number): Replace number by variable.

(math-read-number-simple): Properly parse small integers.
parent dc5d263f
2007-07-07 Jay Belanger <jay.p.belanger@gmail.com>
* calc/calc.el (math-read-number): Replace number by variable.
(math-read-number-simple): Properly parse small integers.
2007-07-07 Dan Nicolaescu <dann@ics.uci.edu> 2007-07-07 Dan Nicolaescu <dann@ics.uci.edu>
* vc.el: Fix doc for the checkout function. * vc.el: Fix doc for the checkout function.
......
...@@ -3401,6 +3401,7 @@ largest Emacs integer.") ...@@ -3401,6 +3401,7 @@ largest Emacs integer.")
;;; Parse a simple number in string form. [N X] [Public] ;;; Parse a simple number in string form. [N X] [Public]
(defun math-read-number (s) (defun math-read-number (s)
"Convert the string S into a Calc number."
(math-normalize (math-normalize
(cond (cond
...@@ -3411,7 +3412,7 @@ largest Emacs integer.") ...@@ -3411,7 +3412,7 @@ largest Emacs integer.")
(> (length digs) 1) (> (length digs) 1)
(eq (aref digs 0) ?0)) (eq (aref digs 0) ?0))
(math-read-number (concat "8#" digs)) (math-read-number (concat "8#" digs))
(if (<= (length digs) 6) (if (<= (length digs) (* 2 math-bignum-digit-length))
(string-to-number digs) (string-to-number digs)
(cons 'bigpos (math-read-bignum digs)))))) (cons 'bigpos (math-read-bignum digs))))))
...@@ -3459,13 +3460,20 @@ largest Emacs integer.") ...@@ -3459,13 +3460,20 @@ largest Emacs integer.")
;;; Parse a very simple number, keeping all digits. ;;; Parse a very simple number, keeping all digits.
(defun math-read-number-simple (s) (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 (cond
;; Integer ;; Integer
((string-match "^[0-9]+$" s) ((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 ;; Minus sign
((string-match "^-[0-9]+$" s) ((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 ;; Decimal point
((string-match "^\\(-?[0-9]*\\)\\.\\([0-9]*\\)$" s) ((string-match "^\\(-?[0-9]*\\)\\.\\([0-9]*\\)$" s)
(let ((int (math-match-substring s 1)) (let ((int (math-match-substring s 1))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment