Function: calculator-eng-display

calculator-eng-display is a byte-compiled function defined in calculator.el.gz.

Signature

(calculator-eng-display NUM)

Documentation

Display NUM in engineering notation.

The number of decimal digits used is controlled by calculator-number-digits, so to change it at runtime you have to use the left or right when one of the standard modes is used.

Source Code

;; Defined in /usr/src/emacs/lisp/calculator.el.gz
(defun calculator-eng-display (num)
  "Display NUM in engineering notation.
The number of decimal digits used is controlled by
`calculator-number-digits', so to change it at runtime you have to use
the `left' or `right' when one of the standard modes is used."
  (if (symbolp num)
    (cond ((eq num 'left)
           (setq calculator-eng-extra
                 (if calculator-eng-extra (1+ calculator-eng-extra) 1))
           (let ((calculator-eng-tmp-show t)) (calculator-enter)))
          ((eq num 'right)
           (setq calculator-eng-extra
                 (if calculator-eng-extra (1- calculator-eng-extra) -1))
           (let ((calculator-eng-tmp-show t)) (calculator-enter))))
    (let ((exp 0))
      (unless (= 0 num)
        (while (< (abs num) 1.0)
          (setq num (* num 1000.0)) (setq exp (- exp 3)))
        (while (> (abs num) 999.0)
          (setq num (/ num 1000.0)) (setq exp (+ exp 3)))
        (when (and calculator-eng-tmp-show
                   (not (= 0 calculator-eng-extra)))
          (let ((i calculator-eng-extra))
            (while (> i 0)
              (setq num (* num 1000.0)) (setq exp (- exp 3))
              (setq i (1- i)))
            (while (< i 0)
              (setq num (/ num 1000.0)) (setq exp (+ exp 3))
              (setq i (1+ i))))))
      (unless calculator-eng-tmp-show (setq calculator-eng-extra nil))
      (let ((str (format (format "%%.%sf" calculator-number-digits)
                         num)))
        (concat (let ((calculator-remove-zeros
                       ;; make sure we don't leave integers
                       (and calculator-remove-zeros 'x)))
                  (calculator-remove-zeros str))
                "e" (number-to-string exp))))))