summaryrefslogtreecommitdiff
path: root/lisp/calc/calc-bin.el
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2019-07-16 17:18:32 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2019-07-16 17:37:46 +0200
commita87840fffbf471d53eba17ea683728125d2d4767 (patch)
tree3529d052a679c420f27a7d44bdbb8d80d9f7779d /lisp/calc/calc-bin.el
parent0a2461be9edb218bf9ca56156d8966a2421f13a7 (diff)
downloademacs-a87840fffbf471d53eba17ea683728125d2d4767.tar.gz
emacs-a87840fffbf471d53eba17ea683728125d2d4767.tar.bz2
emacs-a87840fffbf471d53eba17ea683728125d2d4767.zip
Fix calc number formatting with digit grouping (bug#36689)
The functions math-format-hex and math-format-octal were not implemented, yet called, leading to a crash when using hex or octal radix with digit grouping. * test/lisp/calc/calc-tests.el (calc-test-format-radix): New test. * lisp/calc/calc-ext.el: Don't declare non-existing functions. (math--format-integer-fancy): Don't call non-existing functions. * lisp/calc/calc-bin.el (math-format-binary, math-binary-digits): Simplify, fixing 0-padding bug.
Diffstat (limited to 'lisp/calc/calc-bin.el')
-rw-r--r--lisp/calc/calc-bin.el13
1 files changed, 2 insertions, 11 deletions
diff --git a/lisp/calc/calc-bin.el b/lisp/calc/calc-bin.el
index b4371bdaf98..558e309e472 100644
--- a/lisp/calc/calc-bin.el
+++ b/lisp/calc/calc-bin.el
@@ -506,18 +506,9 @@
a (/ a calc-number-radix)))
s)))
-(defconst math-binary-digits ["000" "001" "010" "011"
- "100" "101" "110" "111"])
(defun math-format-binary (a) ; [X S]
- (if (< a 8)
- (if (< a 0)
- (concat "-" (math-format-binary (- a)))
- (aref math-binary-digits a))
- (let ((s ""))
- (while (> a 7)
- (setq s (concat (aref math-binary-digits (% a 8)) s)
- a (/ a 8)))
- (concat (math-format-binary a) s))))
+ (let ((calc-number-radix 2))
+ (math-format-radix a)))
;;; Decompose into integer and fractional parts, without depending
;;; on calc-internal-prec.