diff options
| author | Jay Belanger | 2008-08-05 03:38:24 +0000 |
|---|---|---|
| committer | Jay Belanger | 2008-08-05 03:38:24 +0000 |
| commit | 57675fb5578db241eb2b62fce41ad864dae56bdf (patch) | |
| tree | 8a978186b01930e191361cb3f6311b9a4c053123 | |
| parent | 4e6225928e54d42a7899dc20a5f56da51e056332 (diff) | |
| download | emacs-57675fb5578db241eb2b62fce41ad864dae56bdf.tar.gz emacs-57675fb5578db241eb2b62fce41ad864dae56bdf.zip | |
(math-read-number): Handle C numbers beginning with 0 correctly.
| -rw-r--r-- | lisp/calc/calc.el | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el index 0721e8a983f..a4a6387296b 100644 --- a/lisp/calc/calc.el +++ b/lisp/calc/calc.el | |||
| @@ -3455,7 +3455,7 @@ largest Emacs integer.") | |||
| 3455 | 3455 | ||
| 3456 | 3456 | ||
| 3457 | ;;; Parse a simple number in string form. [N X] [Public] | 3457 | ;;; Parse a simple number in string form. [N X] [Public] |
| 3458 | (defun math-read-number (s) | 3458 | (defun math-read-number (s &optional decimal) |
| 3459 | "Convert the string S into a Calc number." | 3459 | "Convert the string S into a Calc number." |
| 3460 | (math-normalize | 3460 | (math-normalize |
| 3461 | (cond | 3461 | (cond |
| @@ -3465,7 +3465,8 @@ largest Emacs integer.") | |||
| 3465 | (let ((digs (math-match-substring s 1))) | 3465 | (let ((digs (math-match-substring s 1))) |
| 3466 | (if (and (eq calc-language 'c) | 3466 | (if (and (eq calc-language 'c) |
| 3467 | (> (length digs) 1) | 3467 | (> (length digs) 1) |
| 3468 | (eq (aref digs 0) ?0)) | 3468 | (eq (aref digs 0) ?0) |
| 3469 | (null decimal)) | ||
| 3469 | (math-read-number (concat "8#" digs)) | 3470 | (math-read-number (concat "8#" digs)) |
| 3470 | (if (<= (length digs) (* 2 math-bignum-digit-length)) | 3471 | (if (<= (length digs) (* 2 math-bignum-digit-length)) |
| 3471 | (string-to-number digs) | 3472 | (string-to-number digs) |
| @@ -3492,8 +3493,8 @@ largest Emacs integer.") | |||
| 3492 | (frac (math-match-substring s 2))) | 3493 | (frac (math-match-substring s 2))) |
| 3493 | (let ((ilen (length int)) | 3494 | (let ((ilen (length int)) |
| 3494 | (flen (length frac))) | 3495 | (flen (length frac))) |
| 3495 | (let ((int (if (> ilen 0) (math-read-number int) 0)) | 3496 | (let ((int (if (> ilen 0) (math-read-number int t) 0)) |
| 3496 | (frac (if (> flen 0) (math-read-number frac) 0))) | 3497 | (frac (if (> flen 0) (math-read-number frac t) 0))) |
| 3497 | (and int frac (or (> ilen 0) (> flen 0)) | 3498 | (and int frac (or (> ilen 0) (> flen 0)) |
| 3498 | (list 'float | 3499 | (list 'float |
| 3499 | (math-add (math-scale-int int flen) frac) | 3500 | (math-add (math-scale-int int flen) frac) |
| @@ -3503,7 +3504,7 @@ largest Emacs integer.") | |||
| 3503 | ((string-match "^\\(.*\\)[eE]\\([-+]?[0-9]+\\)$" s) | 3504 | ((string-match "^\\(.*\\)[eE]\\([-+]?[0-9]+\\)$" s) |
| 3504 | (let ((mant (math-match-substring s 1)) | 3505 | (let ((mant (math-match-substring s 1)) |
| 3505 | (exp (math-match-substring s 2))) | 3506 | (exp (math-match-substring s 2))) |
| 3506 | (let ((mant (if (> (length mant) 0) (math-read-number mant) 1)) | 3507 | (let ((mant (if (> (length mant) 0) (math-read-number mant t) 1)) |
| 3507 | (exp (if (<= (length exp) (if (memq (aref exp 0) '(?+ ?-)) 8 7)) | 3508 | (exp (if (<= (length exp) (if (memq (aref exp 0) '(?+ ?-)) 8 7)) |
| 3508 | (string-to-number exp)))) | 3509 | (string-to-number exp)))) |
| 3509 | (and mant exp (Math-realp mant) (> exp -4000000) (< exp 4000000) | 3510 | (and mant exp (Math-realp mant) (> exp -4000000) (< exp 4000000) |