Function: math-format-number-fancy
math-format-number-fancy is a byte-compiled function defined in
calc-ext.el.gz.
Signature
(math-format-number-fancy A PREC)
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-ext.el.gz
(defun math-format-number-fancy (a prec)
(cond
((eq (car a) 'float) ; non-decimal radix
(if (Math-integer-negp (nth 1 a))
(concat "-" (math-format-number (math-neg a)))
(let ((str (if (and calc-radix-formatter
(not (memq calc-language '(c pascal))))
(funcall calc-radix-formatter
calc-number-radix
(math-format-radix-float a prec))
(format "%d#%s" calc-number-radix
(math-format-radix-float a prec)))))
(if (and prec (> prec 191) (string-search "*" str))
(concat "(" str ")")
str))))
((eq (car a) 'frac)
(setq a (math-adjust-fraction a))
(if (> (length (car calc-frac-format)) 1)
(if (Math-integer-negp (nth 1 a))
(concat "-" (math-format-number (math-neg a)))
(let ((q (math-idivmod (nth 1 a) (nth 2 a))))
(concat (let ((calc-frac-format nil))
(math-format-number (car q)))
(substring (car calc-frac-format) 0 1)
(let ((math-radix-explicit-format nil)
(calc-frac-format nil))
(math-format-number (cdr q)))
(substring (car calc-frac-format) 1 2)
(let ((math-radix-explicit-format nil)
(calc-frac-format nil))
(math-format-number (nth 2 a))))))
(concat (let ((calc-frac-format nil))
(math-format-number (nth 1 a)))
(car calc-frac-format)
(let ((math-radix-explicit-format nil)
(calc-frac-format nil))
(math-format-number (nth 2 a))))))
((eq (car a) 'cplx)
(if (math-zerop (nth 2 a))
(math-format-number (nth 1 a))
(if (null calc-complex-format)
(concat "(" (math-format-number (nth 1 a))
", " (math-format-number (nth 2 a)) ")")
(if (math-zerop (nth 1 a))
(if (math-equal-int (nth 2 a) 1)
(symbol-name calc-complex-format)
(if (math-equal-int (nth 2 a) -1)
(concat "-" (symbol-name calc-complex-format))
(if prec
(math-compose-expr (list '* (nth 2 a) '(cplx 0 1)) prec)
(concat (math-format-number (nth 2 a)) " "
(symbol-name calc-complex-format)))))
(if prec
(math-compose-expr (list (if (math-negp (nth 2 a)) '- '+)
(nth 1 a)
(list 'cplx 0 (math-abs (nth 2 a))))
prec)
(concat (math-format-number (nth 1 a))
(if (math-negp (nth 2 a)) " - " " + ")
(math-format-number
(list 'cplx 0 (math-abs (nth 2 a))))))))))
((eq (car a) 'polar)
(concat "(" (math-format-number (nth 1 a))
"; " (math-format-number (nth 2 a)) ")"))
((eq (car a) 'hms)
(if (math-negp a)
(concat "-" (math-format-number (math-neg a)))
(let ((calc-number-radix 10)
(calc-twos-complement-mode nil)
(calc-leading-zeros nil)
(calc-group-digits nil))
(format calc-hms-format
(let ((calc-frac-format '(":" nil)))
(math-format-number (nth 1 a)))
(let ((calc-frac-format '(":" nil)))
(math-format-number (nth 2 a)))
(math-format-number (nth 3 a))))))
((eq (car a) 'intv)
(concat (if (memq (nth 1 a) '(0 1)) "(" "[")
(math-format-number (nth 2 a))
" .. "
(math-format-number (nth 3 a))
(if (memq (nth 1 a) '(0 2)) ")" "]")))
((eq (car a) 'sdev)
(concat (math-format-number (nth 1 a))
" +/- "
(math-format-number (nth 2 a))))
((eq (car a) 'vec)
(math-format-flat-expr a 0))
(t (format "%s" a))))