• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/emacs-93/emacs/lisp/calc/

Lines Matching +defs:calc +defs:float +defs:format

0 ;;; calc.el --- the GNU Emacs calculator
32 ;; facilities. The more advanced features are based in calc-ext, which
45 ;; report-calc-bug to send them).
48 ;; of the prefixes "math", "Math", or "calc", with the exceptions of
49 ;; "full-calc", "full-calc-keypad", "another-calc", "quick-calc",
50 ;; "report-calc-bug", and "defmath". User-accessible variables begin
61 ;; Consider reimplementing calc-delete-selection using rewrites.
68 ;; Have defmath generate calls to calc-binary-op or calc-unary-op.
71 ;; Allow calc-word-size=0 => Common Lisp-style signed bitwise arithmetic.
89 ;; Change calc-grab-region to use math-read-big-expr.
93 ;; Make a calc-graph-histogram function.
146 ;; Subject: Re: fix for `Cannot open load file: calc-alg-3'
207 (require 'calc-macs)
209 (defgroup calc nil
211 :prefix "calc-"
216 (defcustom calc-settings-file
217 (convert-standard-filename "~/.calc.el")
219 :group 'calc
222 (defcustom calc-language-alist
234 :group 'calc
238 (defcustom calc-embedded-announce-formula
240 "*A regular expression which is sure to be followed by a calc-embedded formula."
241 :group 'calc
244 (defcustom calc-embedded-announce-formula-alist
256 "*Alist of major modes with appropriate values for `calc-embedded-announce-formula'."
257 :group 'calc
261 (defcustom calc-embedded-open-formula
263 "*A regular expression for the opening delimiter of a formula used by calc-embedded."
264 :group 'calc
267 (defcustom calc-embedded-close-formula
269 "*A regular expression for the closing delimiter of a formula used by calc-embedded."
270 :group 'calc
273 (defcustom calc-embedded-open-close-formula-alist
275 "*Alist of major modes with pairs of formula delimiters used by calc-embedded."
276 :group 'calc
281 (defcustom calc-embedded-open-word
283 "*A regular expression for the opening delimiter of a formula used by calc-embedded-word."
284 :group 'calc
287 (defcustom calc-embedded-close-word
289 "*A regular expression for the closing delimiter of a formula used by calc-embedded-word."
290 :group 'calc
293 (defcustom calc-embedded-open-close-word-alist
295 "*Alist of major modes with pairs of word delimiters used by calc-embedded."
296 :group 'calc
301 (defcustom calc-embedded-open-plain
304 If calc-show-plain mode is enabled, this is inserted at the front of
306 :group 'calc
309 (defcustom calc-embedded-close-plain
312 See calc-embedded-open-plain."
313 :group 'calc
316 (defcustom calc-embedded-open-close-plain-alist
329 :group 'calc
334 (defcustom calc-embedded-open-new-formula
336 "*A string which is inserted at front of formula by calc-embedded-new-formula."
337 :group 'calc
340 (defcustom calc-embedded-close-new-formula
342 "*A string which is inserted at end of formula by calc-embedded-new-formula."
343 :group 'calc
346 (defcustom calc-embedded-open-close-new-formula-alist
348 "*Alist of major modes with pairs of new formula delimiters used by calc-embedded."
349 :group 'calc
354 (defcustom calc-embedded-open-mode
356 "*A string which should precede calc-embedded mode annotations.
358 :group 'calc
361 (defcustom calc-embedded-close-mode
363 "*A string which should follow calc-embedded mode annotations.
365 :group 'calc
368 (defcustom calc-embedded-open-close-mode-alist
381 :group 'calc
386 (defcustom calc-gnuplot-name
388 "*Name of GNUPLOT program, for calc-graph features."
389 :group 'calc
392 (defcustom calc-gnuplot-plot-command
395 :group 'calc
398 (defcustom calc-gnuplot-print-command
401 :group 'calc
404 (defvar calc-bug-address "jay.p.belanger@gmail.com"
405 "Address of the maintainer of Calc, for use by `report-calc-bug'.")
407 (defvar calc-scan-for-dels t
409 if nil, only DEL itself is mapped to calc-pop.")
411 (defvar calc-stack '((top-of-stack 1 nil))
415 (defvar calc-stack-top 1
416 "Index into `calc-stack' of \"top\" of stack.
417 This is 1 unless `calc-truncate-stack' has been used.")
419 (defvar calc-display-sci-high 0
421 current precision are displayed in scientific notation in calc-mode.")
423 (defvar calc-display-sci-low -3
425 scientific notation in calc-mode.")
427 (defvar calc-other-modes nil
430 (defvar calc-Y-help-msgs nil
433 (defvar calc-loaded-settings-file nil
434 "t if `calc-settings-file' has been loaded yet.")
437 (defvar calc-mode-var-list '()
443 (add-to-list 'calc-mode-var-list (list (quote ,var) ,defval))))
445 (defun calc-mode-var-list-restore-default-values ()
447 calc-mode-var-list))
449 (defun calc-mode-var-list-restore-saved-values ()
453 (file (substitute-in-file-name calc-settings-file)))
464 (calc-mode-var-list-restore-default-values)
466 (let ((varlist calc-mode-var-list))
476 (calc-mode-var-list-restore-default-values))))
478 (defcalcmodevar calc-always-load-extensions nil
479 "If non-nil, load the calc-ext module automatically when calc is loaded.")
481 (defcalcmodevar calc-line-numbering t
484 (defcalcmodevar calc-line-breaking t
487 (defcalcmodevar calc-display-just nil
492 (defcalcmodevar calc-display-origin nil
498 (defcalcmodevar calc-number-radix 10
499 "Radix for entry and display of numbers in calc-mode, 2-36.")
501 (defcalcmodevar calc-leading-zeros nil
502 "If non-nil, leading zeros are provided to pad integers to calc-word-size.")
504 (defcalcmodevar calc-group-digits nil
509 (defcalcmodevar calc-group-char ","
511 This is used only when calc-group-digits mode is on.")
513 (defcalcmodevar calc-point-char "."
516 (defcalcmodevar calc-frac-format '(":" nil)
519 (defcalcmodevar calc-prefer-frac nil
522 (defcalcmodevar calc-hms-format "%s@ %s' %s\""
523 "Format of displayed hours-minutes-seconds angles, a format string.
526 (defcalcmodevar calc-date-format '((H ":" mm C SS pp " ")
530 (defcalcmodevar calc-float-format '(float 0)
531 "Format to use for display of floating-point numbers in calc-mode.
533 (float 0) Floating point format, display full precision.
534 (float N) N > 0: Floating point format, at most N significant figures.
535 (float -N) -N < 0: Floating point format, calc-internal-prec - N figs.
536 (fix N) N >= 0: Fixed point format, N places after decimal point.
539 (sci -N) -N < 0: Scientific notation, calc-internal-prec - N figs.
542 (eng -N) -N < 0: Engineering notation, calc-internal-prec - N figs.")
544 (defcalcmodevar calc-full-float-format '(float 0)
547 (defcalcmodevar calc-complex-format nil
548 "Format to use for display of complex numbers in calc-mode. Must be one of:
553 (defcalcmodevar calc-complex-mode 'cplx
556 (defcalcmodevar calc-infinite-mode nil
561 (defcalcmodevar calc-display-strings nil
564 (defcalcmodevar calc-matrix-just 'center
569 (defcalcmodevar calc-break-vectors nil
572 (defcalcmodevar calc-full-vectors t
575 (defcalcmodevar calc-full-trail-vectors t
578 (defcalcmodevar calc-vector-commas ","
581 (defcalcmodevar calc-vector-brackets "[]"
584 (defcalcmodevar calc-matrix-brackets '(R O)
590 (defcalcmodevar calc-language nil
591 "Language or format for entry and display of stack values. Must be one of:
593 flat Use standard Calc notation, one-line format.
605 (defcalcmodevar calc-language-option nil
606 "Numeric prefix argument for the command that set `calc-language'.")
608 (defcalcmodevar calc-left-label ""
611 (defcalcmodevar calc-right-label ""
614 (defcalcmodevar calc-word-size 32
615 "Minimum number of bits per word, if any, for binary operations in calc-mode.")
617 (defcalcmodevar calc-previous-modulo nil
620 (defcalcmodevar calc-simplify-mode nil
630 (defcalcmodevar calc-auto-recompute t
633 (defcalcmodevar calc-display-raw nil
636 (defcalcmodevar calc-internal-prec 12
637 "Number of digits of internal precision for calc-mode calculations.")
639 (defcalcmodevar calc-angle-mode 'deg
643 (defcalcmodevar calc-algebraic-mode nil
647 (defcalcmodevar calc-incomplete-algebraic-mode nil
648 "Like calc-algebraic-mode except only affects ( and [ keys.")
650 (defcalcmodevar calc-symbolic-mode nil
654 (defcalcmodevar calc-matrix-mode nil
661 (defcalcmodevar calc-shift-prefix nil
664 (defcalcmodevar calc-window-height 7
667 (defcalcmodevar calc-display-trail t
668 "If non-nil, M-x calc creates a window to display Calculator trail.")
670 (defcalcmodevar calc-show-selections t
674 (defcalcmodevar calc-use-selections t
678 (defcalcmodevar calc-assoc-selections t
681 (defcalcmodevar calc-display-working-message 'lots
684 (defcalcmodevar calc-auto-why 'maybe
687 (defcalcmodevar calc-timing nil
690 (defcalcmodevar calc-mode-save-mode 'local)
692 (defcalcmodevar calc-standard-date-formats
704 (defcalcmodevar calc-autorange-units nil)
706 (defcalcmodevar calc-was-keypad-mode nil)
708 (defcalcmodevar calc-full-mode nil)
710 (defcalcmodevar calc-user-parse-tables nil)
712 (defcalcmodevar calc-gnuplot-default-device "default")
714 (defcalcmodevar calc-gnuplot-default-output "STDOUT")
716 (defcalcmodevar calc-gnuplot-print-device "postscript")
718 (defcalcmodevar calc-gnuplot-print-output "auto")
720 (defcalcmodevar calc-gnuplot-geometry nil)
722 (defcalcmodevar calc-graph-default-resolution 15)
724 (defcalcmodevar calc-graph-default-resolution-3d 5)
726 (defcalcmodevar calc-invocation-macro nil)
728 (defcalcmodevar calc-show-banner t
731 (defconst calc-local-var-list '(calc-stack
732 calc-stack-top
733 calc-undo-list
734 calc-redo-list
735 calc-always-load-extensions
736 calc-mode-save-mode
737 calc-display-raw
738 calc-line-numbering
739 calc-line-breaking
740 calc-display-just
741 calc-display-origin
742 calc-left-label
743 calc-right-label
744 calc-auto-why
745 calc-algebraic-mode
746 calc-incomplete-algebraic-mode
747 calc-symbolic-mode
748 calc-matrix-mode
749 calc-inverse-flag
750 calc-hyperbolic-flag
751 calc-keep-args-flag
752 calc-angle-mode
753 calc-number-radix
754 calc-leading-zeros
755 calc-group-digits
756 calc-group-char
757 calc-point-char
758 calc-frac-format
759 calc-prefer-frac
760 calc-hms-format
761 calc-date-format
762 calc-standard-date-formats
763 calc-float-format
764 calc-full-float-format
765 calc-complex-format
766 calc-matrix-just
767 calc-full-vectors
768 calc-full-trail-vectors
769 calc-break-vectors
770 calc-vector-commas
771 calc-vector-brackets
772 calc-matrix-brackets
773 calc-complex-mode
774 calc-infinite-mode
775 calc-display-strings
776 calc-simplify-mode
777 calc-auto-recompute
778 calc-autorange-units
779 calc-show-plain
780 calc-show-selections
781 calc-use-selections
782 calc-assoc-selections
783 calc-word-size
784 calc-internal-prec))
786 (defvar calc-mode-hook nil
787 "Hook run when entering calc-mode.")
789 (defvar calc-trail-mode-hook nil
790 "Hook run when entering calc-trail-mode.")
792 (defvar calc-start-hook nil
793 "Hook run when calc is started.")
795 (defvar calc-end-hook nil
796 "Hook run when calc is quit.")
798 (defvar calc-load-hook nil
799 "Hook run when calc.el is loaded.")
801 (defvar calc-window-hook nil
804 (defvar calc-trail-window-hook nil
807 (defvar calc-embedded-new-buffer-hook nil
810 (defvar calc-embedded-new-formula-hook nil
813 (defvar calc-embedded-mode-hook nil
817 (defvar calc-emacs-type-lucid (not (not (string-match "Lucid" emacs-version))))
820 (let ((name (and (fboundp 'calc-dispatch)
821 (eq (car-safe (symbol-function 'calc-dispatch)) 'autoload)
822 (nth 1 (symbol-function 'calc-dispatch))))
827 (expand-file-name "calc-misc.elc" (car p)))))
832 ;; This works for both relative ("calc/calc.elc") and absolute paths.
836 "calc-misc.elc")))
849 (put 'calc-mode 'mode-class 'special)
850 (put 'calc-trail-mode 'mode-class 'special)
853 (put 'inexact-result 'error-conditions '(error inexact-result calc-error))
857 (put 'math-overflow 'error-conditions '(error math-overflow calc-error))
859 (put 'math-underflow 'error-conditions '(error math-underflow calc-error))
862 (defconst calc-version "2.1")
863 (defvar calc-trail-pointer nil) ; "Current" entry in trail buffer.
864 (defvar calc-trail-overlay nil) ; Value of overlay-arrow-string.
865 (defvar calc-undo-list nil) ; List of previous operations for undo.
866 (defvar calc-redo-list nil) ; List of recent undo operations.
867 (defvar calc-main-buffer nil) ; Pointer to Calculator buffer.
868 (defvar calc-trail-buffer nil) ; Pointer to Calc Trail buffer.
869 (defvar calc-why nil) ; Explanations of most recent errors.
870 (defvar calc-next-why nil)
871 (defvar calc-inverse-flag nil
873 (defvar calc-hyperbolic-flag nil
875 (defvar calc-keep-args-flag nil
877 (defvar calc-function-open "("
879 (defvar calc-function-close ")"
881 (defvar calc-language-output-filter nil
883 (defvar calc-language-input-filter nil
885 (defvar calc-radix-formatter nil
888 (defvar calc-last-kill nil) ; Last number killed in calc-mode.
889 (defvar calc-dollar-values nil) ; Values to be used for '$'.
890 (defvar calc-dollar-used nil) ; Highest order of '$' that occurred.
891 (defvar calc-hashes-used nil) ; Highest order of '#' that occurred.
892 (defvar calc-quick-prev-results nil) ; Previous results from Quick Calc.
893 (defvar calc-said-hello nil) ; Has welcome message been said yet?
894 (defvar calc-executing-macro nil) ; Kbd macro executing from "K" key.
895 (defvar calc-any-selections nil) ; Nil means no selections present.
896 (defvar calc-help-phase 0) ; Count of consecutive "?" keystrokes.
897 (defvar calc-full-help-flag nil) ; Executing calc-full-help?
898 (defvar calc-refresh-count 0) ; Count of calc-refresh calls.
899 (defvar calc-display-dirty nil)
900 (defvar calc-prepared-composition nil)
901 (defvar calc-selection-cache-default-entry nil)
902 (defvar calc-embedded-info nil)
903 (defvar calc-embedded-active nil)
904 (defvar calc-standalone-flag nil)
907 (defvar math-radix-explicit-format t)
922 calc-local-var-list)
924 (defvar calc-mode-map
927 (define-key map "+" 'calc-plus)
928 (define-key map "-" 'calc-minus)
929 (define-key map "*" 'calc-times)
930 (define-key map "/" 'calc-divide)
931 (define-key map "%" 'calc-mod)
932 (define-key map "&" 'calc-inv)
933 (define-key map "^" 'calc-power)
934 (define-key map "\M-%" 'calc-percent)
936 (define-key map "i" 'calc-info)
937 (define-key map "n" 'calc-change-sign)
938 (define-key map "q" 'calc-quit)
940 (define-key map "Y?" 'calc-shift-Y-prefix-help)
941 (define-key map "?" 'calc-help)
942 (define-key map " " 'calc-enter)
943 (define-key map "'" 'calc-algebraic-entry)
944 (define-key map "$" 'calc-auto-algebraic-entry)
945 (define-key map "\"" 'calc-auto-algebraic-entry)
946 (define-key map "\t" 'calc-roll-down)
947 (define-key map "\M-\t" 'calc-roll-up)
948 (define-key map "\C-m" 'calc-enter)
949 (define-key map "\M-\C-m" 'calc-last-args-stub)
950 (define-key map "\C-j" 'calc-over)
954 (mapc (lambda (x) (define-key map (char-to-string x) 'calc-missing-key))
961 (defvar calc-digit-map
963 (if calc-emacs-type-lucid
969 calc-mode-map)
970 (let ((cmap (nth 1 calc-mode-map))
990 (define-key calc-digit-map x 'calcDigit-backspace)
991 (define-key calc-mode-map x 'calc-pop)
992 (define-key calc-mode-map
994 (if calc-emacs-type-lucid
1002 'calc-pop-above))
1004 (if calc-scan-for-dels
1010 (defvar calc-dispatch-map
1017 (define-key map (format "\e%c" (car x)) (cdr x)))
1018 '( ( ?a . calc-embedded-activate )
1019 ( ?b . calc-big-or-small )
1020 ( ?c . calc )
1021 ( ?d . calc-embedded-duplicate )
1022 ( ?e . calc-embedded )
1023 ( ?f . calc-embedded-new-formula )
1024 ( ?g . calc-grab-region )
1025 ( ?h . calc-dispatch-help )
1026 ( ?i . calc-info )
1027 ( ?j . calc-embedded-select )
1028 ( ?k . calc-keypad )
1029 ( ?l . calc-load-everything )
1031 ( ?n . calc-embedded-next )
1032 ( ?o . calc-other-window )
1033 ( ?p . calc-embedded-previous )
1034 ( ?q . quick-calc )
1035 ( ?r . calc-grab-rectangle )
1036 ( ?s . calc-info-summary )
1037 ( ?t . calc-tutorial )
1038 ( ?u . calc-embedded-update-formula )
1039 ( ?w . calc-embedded-word )
1040 ( ?x . calc-quit )
1041 ( ?y . calc-copy-to-buffer )
1042 ( ?z . calc-user-invocation )
1043 ( ?\' . calc-embedded-new-formula )
1044 ( ?\` . calc-embedded-edit )
1045 ( ?: . calc-grab-sum-down )
1046 ( ?_ . calc-grab-sum-across )
1047 ( ?0 . calc-reset )
1048 ( ?? . calc-dispatch-help )
1049 ( ?# . calc-same-interface )
1050 ( ?& . calc-same-interface )
1051 ( ?\\ . calc-same-interface )
1052 ( ?= . calc-same-interface )
1053 ( ?* . calc-same-interface )
1054 ( ?/ . calc-same-interface )
1055 ( ?+ . calc-same-interface )
1056 ( ?- . calc-same-interface ) ))
1064 ("calc-aent" calc-alg-digit-entry calc-alg-entry
1065 calc-check-user-syntax calc-do-alg-entry calc-do-calc-eval
1066 calc-do-quick-calc calc-match-user-syntax math-build-parse-table
1070 ("calc-embed" calc-do-embedded-activate)
1072 ("calc-misc"
1073 calc-do-handle-whys calc-do-refresh calc-num-prefix-name
1074 calc-record-list calc-record-why calc-report-bug calc-roll-down-stack
1075 calc-roll-up-stack calc-temp-minibuffer-message calcFunc-floor
1086 ("calc-aent" calc-algebraic-entry calc-auto-algebraic-entry
1089 ("calc-misc" another-calc calc-big-or-small calc-dispatch-help
1090 calc-help calc-info calc-info-goto-node calc-info-summary calc-inv
1091 calc-last-args-stub
1092 calc-missing-key calc-mod calc-other-window calc-over calc-percent
1093 calc-pop-above calc-power calc-roll-down calc-roll-up
1094 calc-shift-Y-prefix-help calc-tutorial calcDigit-letter
1095 report-calc-bug)))
1098 ;;;###autoload (define-key ctl-x-map "*" 'calc-dispatch)
1101 (defun calc-dispatch (&optional arg)
1102 "Invoke the GNU Emacs Calculator. See `calc-dispatch-help' for details."
1105 (condition-case err ; look for other keys bound to calc-dispatch
1109 (eq (lookup-key calc-dispatch-map keys) 'calc-same-interface))
1112 (lookup-key calc-dispatch-map (substring keys 0 1))))
1113 (define-key calc-dispatch-map (substring keys 0 1) nil))
1114 (define-key calc-dispatch-map keys 'calc-same-interface)))
1116 (calc-do-dispatch arg))
1118 (defvar calc-dispatch-help nil)
1119 (defun calc-do-dispatch (arg)
1120 (let ((key (calc-read-key-sequence
1121 (if calc-dispatch-help
1123 (format "%s (Type ? for a list of Calc options)"
1125 calc-dispatch-map)))
1126 (setq key (lookup-key calc-dispatch-map key))
1130 (or (commandp key) (require 'calc-ext))
1134 (defun calc-read-key-sequence (prompt map)
1135 (let ((prompt2 (format "%s " (key-description (this-command-keys))))
1139 (let ((key (calc-read-key t)))
1140 (calc-unread-command (cdr key))
1149 (defvar calc-alg-map) ; Defined in calc-ext.el
1151 (defun calc-version ()
1154 (message (concat "Calc version " calc-version)))
1156 (defun calc-mode ()
1185 \\{calc-mode-map}
1189 (lambda (v) (set-default v (symbol-value v)))) calc-local-var-list)
1191 (use-local-map (if (eq calc-algebraic-mode 'total)
1192 (progn (require 'calc-ext) calc-alg-map) calc-mode-map))
1193 (mapcar (function (lambda (v) (make-local-variable v))) calc-local-var-list)
1199 (setq major-mode 'calc-mode)
1201 (setq calc-stack-top (length (or (memq (assq 'top-of-stack calc-stack)
1202 calc-stack)
1203 (setq calc-stack (list (list 'top-of-stack
1205 (setq calc-stack-top (- (length calc-stack) calc-stack-top -1))
1206 (or calc-loaded-settings-file
1207 (null calc-settings-file)
1208 (equal calc-settings-file user-init-file)
1210 (setq calc-loaded-settings-file t)
1211 (load (file-name-sans-extension calc-settings-file) t))) ; t = missing-ok
1215 (string-match "calc" (nth 1 p))
1217 (setq calc-standalone-flag t))
1219 (run-mode-hooks 'calc-mode-hook)
1220 (calc-refresh t)
1221 (calc-set-mode-line)
1222 (calc-check-defines))
1224 (defvar calc-check-defines 'calc-check-defines) ; suitable for run-hooks
1225 (defun calc-check-defines ()
1226 (if (symbol-plist 'calc-define)
1227 (let ((plist (copy-sequence (symbol-plist 'calc-define))))
1232 (require 'calc-ext)
1233 (require 'calc-macs)
1236 (put 'calc-define (car plist) nil)
1239 ;; See if this has added any more calc-define properties.
1240 (calc-check-defines))
1241 (setplist 'calc-define nil)))))
1243 (defun calc-trail-mode (&optional buf)
1255 (use-local-map calc-mode-map)
1256 (setq major-mode 'calc-trail-mode)
1263 (set (make-local-variable 'calc-main-buffer) buf))
1268 (run-mode-hooks 'calc-trail-mode-hook))
1270 (defun calc-create-buffer ()
1272 (or (eq major-mode 'calc-mode)
1273 (calc-mode))
1275 (when calc-always-load-extensions
1276 (require 'calc-ext))
1277 (when calc-language
1278 (require 'calc-ext)
1279 (calc-set-language calc-language calc-language-option t)))
1282 (defun calc (&optional arg full-display interactive)
1283 "The Emacs Calculator. Full documentation is listed under \"calc-mode\"."
1287 (require 'calc-ext)
1289 (calc-grab-region (region-beginning) (region-end) nil)
1291 (calc-keypad))))
1293 (calc-keypad)
1295 (if (eq major-mode 'calc-mode)
1296 (calc-quit)
1298 (calc-create-buffer)
1299 (setq calc-was-keypad-mode nil)
1301 (and (null full-display) calc-full-mode))
1305 (if calc-window-hook
1306 (run-hooks 'calc-window-hook)
1310 (+ window-min-height calc-window-height 2)))
1314 calc-window-height 2)
1320 (set-buffer (calc-trail-buffer))
1321 (and calc-display-trail
1323 (calc-trail-display 1 t)))
1325 (run-hooks 'calc-start-hook)
1329 (calc-check-defines)
1330 (when (and calc-said-hello interactive)
1333 (setq calc-said-hello t)))))
1336 (defun full-calc (&optional interactive)
1339 (calc nil t interactive))
1341 (defun calc-same-interface (arg)
1342 "Invoke the Calculator using the most recent interface (calc or calc-keypad)."
1347 (if (eq major-mode 'calc-edit-mode)
1348 (calc-edit-finish arg)
1349 (if calc-was-keypad-mode
1350 (calc-keypad)
1351 (calc arg calc-full-mode t)))))
1353 (defun calc-quit (&optional non-fatal interactive)
1355 (and calc-standalone-flag (not non-fatal)
1360 (if (eq major-mode 'calc-edit-mode)
1361 (calc-edit-cancel)
1363 calc-embedded-info
1364 (eq (current-buffer) (aref calc-embedded-info 0)))
1365 (calc-embedded nil)
1366 (unless (eq major-mode 'calc-mode)
1367 (calc-create-buffer))
1368 (run-hooks 'calc-end-hook)
1369 (setq calc-undo-list nil calc-redo-list nil)
1371 calc-local-var-list)
1375 (delete-windows-on (calc-trail-buffer))
1378 (= (window-width win) (frame-width)) ; avoid calc-keypad
1380 (setq calc-window-height (- (window-height win) 2)))
1385 (bury-buffer calc-trail-buffer)
1389 (defun quick-calc ()
1392 (calc-do-quick-calc))
1395 (defun calc-eval (str &optional separator &rest args)
1399 (calc-do-calc-eval str separator args))
1402 (defun calc-keypad (&optional interactive)
1406 Or, position the cursor manually and do M-x calc-keypad-press."
1408 (require 'calc-ext)
1409 (calc-do-keypad calc-full-mode interactive))
1412 (defun full-calc-keypad (&optional interactive)
1414 See calc-keypad for details."
1416 (require 'calc-ext)
1417 (calc-do-keypad t interactive))
1420 (defvar calc-aborted-prefix nil)
1421 (defvar calc-start-time nil)
1422 (defvar calc-command-flags)
1423 (defvar calc-final-point-line)
1424 (defvar calc-final-point-column)
1425 ;;; Note that modifications to this function may break calc-pass-errors.
1426 (defun calc-do (do-body &optional do-slow)
1427 (calc-check-defines)
1428 (let* ((calc-command-flags nil)
1429 (calc-start-time (and calc-timing (not calc-start-time)
1430 (require 'calc-ext)
1433 (if calc-timing 2000000 100000)))
1434 calc-final-point-line calc-final-point-column)
1435 (setq calc-aborted-prefix "")
1439 (if calc-embedded-info
1440 (calc-embedded-select-buffer)
1441 (calc-select-buffer))
1442 (and (eq calc-algebraic-mode 'total)
1443 (require 'calc-ext)
1444 (use-local-map calc-alg-map))
1445 (when (and do-slow calc-display-working-message)
1447 (calc-set-command-flag 'clear-message))
1449 (setq calc-aborted-prefix nil)
1450 (when (memq 'renum-stack calc-command-flags)
1451 (calc-renumber-stack))
1452 (when (memq 'clear-message calc-command-flags)
1460 (setq calc-aborted-prefix nil)
1462 (when calc-aborted-prefix
1463 (calc-record "<Aborted>" calc-aborted-prefix))
1464 (and calc-start-time
1465 (let* ((calc-internal-prec 12)
1466 (calc-date-format nil)
1468 (time (if (equal calc-start-time end-time)
1472 (calcFunc-unixtime (math-parse-date calc-start-time)
1475 (calc-record time "(t)"))))
1476 (or (memq 'no-align calc-command-flags)
1477 (eq major-mode 'calc-trail-mode)
1478 (calc-align-stack-window))
1479 (and (memq 'position-point calc-command-flags)
1480 (if (eq major-mode 'calc-mode)
1482 (goto-line calc-final-point-line)
1483 (move-to-column calc-final-point-column))
1485 (calc-select-buffer)
1486 (goto-line calc-final-point-line)
1487 (move-to-column calc-final-point-column))))
1488 (unless (memq 'keep-flags calc-command-flags)
1490 (calc-select-buffer)
1491 (setq calc-inverse-flag nil
1492 calc-hyperbolic-flag nil
1493 calc-keep-args-flag nil)))
1494 (when (memq 'do-edit calc-command-flags)
1496 (calc-set-mode-line)
1497 (when calc-embedded-info
1498 (calc-embedded-finish-command))))
1502 (defun calc-set-command-flag (f)
1503 (unless (memq f calc-command-flags)
1504 (setq calc-command-flags (cons f calc-command-flags))))
1506 (defun calc-select-buffer ()
1507 (or (eq major-mode 'calc-mode)
1508 (if calc-main-buffer
1509 (set-buffer calc-main-buffer)
1515 (defun calc-cursor-stack-index (&optional index)
1517 (forward-line (- (calc-substack-height (or index 1)))))
1519 (defun calc-stack-size ()
1520 (- (length calc-stack) calc-stack-top))
1522 (defun calc-substack-height (n)
1524 (stack calc-stack))
1525 (setq n (+ n calc-stack-top))
1532 (defun calc-set-mode-line ()
1534 (calc-select-buffer)
1535 (let* ((fmt (car calc-float-format))
1536 (figs (nth 1 calc-float-format))
1538 (format "Calc%s%s: %d %s %-14s"
1539 (if calc-embedded-info "Embed" "")
1545 calc-internal-prec
1546 (capitalize (symbol-name calc-angle-mode))
1550 (if (eq calc-algebraic-mode 'total) "Alg* "
1551 (if calc-algebraic-mode "Alg "
1552 (if calc-incomplete-algebraic-mode "Alg[( " "")))
1555 (if calc-symbolic-mode "Symb " "")
1556 (cond ((eq calc-matrix-mode 'matrix) "Matrix ")
1557 ((integerp calc-matrix-mode)
1558 (format "Matrix%d " calc-matrix-mode))
1559 ((eq calc-matrix-mode 'sqmatrix) "SqMatrix ")
1560 ((eq calc-matrix-mode 'scalar) "Scalar ")
1562 (if (eq calc-complex-mode 'polar) "Polar " "")
1563 (if calc-prefer-frac "Frac " "")
1564 (cond ((null calc-infinite-mode) "")
1565 ((eq calc-infinite-mode 1) "+Inf ")
1567 (cond ((eq calc-simplify-mode 'none) "NoSimp ")
1568 ((eq calc-simplify-mode 'num) "NumSimp ")
1569 ((eq calc-simplify-mode 'binary)
1570 (format "BinSimp%d " calc-word-size))
1571 ((eq calc-simplify-mode 'alg) "AlgSimp ")
1572 ((eq calc-simplify-mode 'ext) "ExtSimp ")
1573 ((eq calc-simplify-mode 'units) "UnitSimp ")
1577 (cond ((= calc-number-radix 10) "")
1578 ((= calc-number-radix 2) "Bin ")
1579 ((= calc-number-radix 8) "Oct ")
1580 ((= calc-number-radix 16) "Hex ")
1581 (t (format "Radix%d " calc-number-radix)))
1582 (if calc-leading-zeros "Zero " "")
1583 (cond ((null calc-language) "")
1584 ((eq calc-language 'tex) "TeX ")
1585 ((eq calc-language 'latex) "LaTeX ")
1587 (capitalize (symbol-name calc-language))
1589 (cond ((eq fmt 'float)
1590 (if (zerop figs) "" (format "Norm%d " figs)))
1591 ((eq fmt 'fix) (format "Fix%d " figs))
1593 (if (zerop figs) "Sci " (format "Sci%d " figs)))
1595 (if (zerop figs) "Eng " (format "Eng%d " figs))))
1596 (cond ((not calc-display-just)
1597 (if calc-display-origin
1598 (format "Left%d " calc-display-origin) ""))
1599 ((eq calc-display-just 'right)
1600 (if calc-display-origin
1601 (format "Right%d " calc-display-origin)
1604 (if calc-display-origin
1605 (format "Center%d " calc-display-origin)
1607 (cond ((integerp calc-line-breaking)
1608 (format "Wid%d " calc-line-breaking))
1609 (calc-line-breaking "")
1613 (if calc-assoc-selections "" "Break ")
1614 (cond ((eq calc-mode-save-mode 'save) "Save ")
1615 ((not calc-embedded-info) "")
1616 ((eq calc-mode-save-mode 'local) "Local ")
1617 ((eq calc-mode-save-mode 'edit) "LocEdit ")
1618 ((eq calc-mode-save-mode 'perm) "LocPerm ")
1619 ((eq calc-mode-save-mode 'global) "Global ")
1621 (if calc-auto-recompute "" "Manual ")
1622 (if (and (fboundp 'calc-gnuplot-alive)
1623 (calc-gnuplot-alive)) "Graph " "")
1624 (if (and calc-embedded-info
1625 (> (calc-stack-size) 0)
1626 (calc-top 1 'sel)) "Sel " "")
1627 (if calc-display-dirty "Dirty " "")
1628 (if calc-inverse-flag "Inv " "")
1629 (if calc-hyperbolic-flag "Hyp " "")
1630 (if calc-keep-args-flag "Keep " "")
1631 (if (/= calc-stack-top 1) "Narrow " "")
1632 (apply 'concat calc-other-modes)))))
1637 (and calc-embedded-info (calc-embedded-mode-line-change))))))
1639 (defun calc-align-stack-window ()
1640 (if (eq major-mode 'calc-mode)
1645 (calc-cursor-stack-index 0)
1648 (calc-cursor-stack-index 0)
1652 (calc-select-buffer)
1653 (calc-align-stack-window))))
1655 (defun calc-check-stack (n)
1656 (if (> n (calc-stack-size))
1661 (defun calc-push-list (vals &optional m sels)
1663 (if calc-executing-macro
1664 (calc-push-list-in-macro vals m sels)
1666 (calc-select-buffer)
1669 (mm (+ (or m 1) calc-stack-top)))
1670 (calc-cursor-stack-index (1- (or m 1)))
1672 (setcdr (nthcdr (- mm 2) calc-stack)
1673 (cons entry (nthcdr (1- mm) calc-stack)))
1674 (setq calc-stack (cons entry calc-stack)))
1676 (insert (math-format-stack-value entry) "\n"))
1677 (calc-record-undo (list 'push mm))
1678 (calc-set-command-flag 'renum-stack))))
1682 (defun calc-pop-push-list (n vals &optional m sels)
1683 (if (and calc-any-selections (null sels))
1684 (calc-replace-selections n vals m)
1685 (calc-pop-stack n m sels)
1686 (calc-push-list vals m sels)))
1688 (defun calc-pop-push-record-list (n prefix vals &optional m sels)
1694 (calc-check-stack (+ n (or m 1) -1))
1697 (calc-record-list vals prefix)
1698 (calc-record (car vals) prefix)))
1699 (calc-pop-push-list n vals m sels))
1701 (defun calc-enter-result (n prefix vals &optional m)
1702 (setq calc-aborted-prefix prefix)
1706 (setq vals (mapcar 'calc-normalize vals))
1707 (setq vals (calc-normalize vals)))
1714 (calc-pop-push-record-list n prefix vals m)
1715 (calc-handle-whys))
1717 (defun calc-normalize (val)
1718 (if (memq calc-simplify-mode '(nil none num))
1720 (require 'calc-ext)
1721 (calc-normalize-fancy val)))
1723 (defun calc-handle-whys ()
1724 (if calc-next-why
1725 (calc-do-handle-whys)))
1728 (defun calc-pop-stack (&optional n m sel-ok) ; pop N objs at level M of stack.
1731 (or calc-keep-args-flag
1732 (let ((mm (+ m calc-stack-top)))
1733 (if (and calc-any-selections (not sel-ok)
1734 (calc-top-selected n m))
1735 (calc-sel-error))
1736 (if calc-executing-macro
1737 (calc-pop-stack-in-macro n mm)
1738 (calc-record-undo (list 'pop mm (calc-top-list n m 'full)))
1740 (calc-select-buffer)
1744 (calc-cursor-stack-index (1- m))
1746 (calc-cursor-stack-index (+ n m -1))
1748 (setcdr (nthcdr (- mm 2) calc-stack)
1749 (nthcdr (+ n mm -1) calc-stack)))
1750 (calc-cursor-stack-index n)
1751 (setq calc-stack (nthcdr n calc-stack))
1753 (calc-set-command-flag 'renum-stack))))))
1756 (defun calc-get-stack-element (x)
1763 (not calc-use-selections))
1766 (calc-sel-error))
1770 (defun calc-top (&optional n sel-mode)
1772 (calc-check-stack n)
1773 (calc-get-stack-element (nth (+ n calc-stack-top -1) calc-stack)))
1775 (defun calc-top-n (&optional n sel-mode) ; in case precision has changed
1776 (math-check-complete (calc-normalize (calc-top n sel-mode))))
1778 (defun calc-top-list (&optional n m sel-mode)
1781 (calc-check-stack (+ n m -1))
1783 (let ((top (copy-sequence (nthcdr (+ m calc-stack-top -1)
1784 calc-stack))))
1786 (nreverse (mapcar 'calc-get-stack-element top)))))
1788 (defun calc-top-list-n (&optional n m sel-mode)
1790 (mapcar 'calc-normalize (calc-top-list n m sel-mode))))
1793 (defun calc-renumber-stack ()
1794 (if calc-line-numbering
1796 (calc-cursor-stack-index 0)
1799 (stack (nthcdr calc-stack-top calc-stack)))
1808 (calc-cursor-stack-index 0)))
1812 (insert (format "%03d%s" (% lnum 1000)
1814 calc-use-selections) "*" ":")))
1817 calc-use-selections) "*" ":")
1822 (and calc-embedded-info (calc-embedded-stack-change)))
1824 (defvar calc-any-evaltos nil)
1825 (defun calc-refresh (&optional align)
1827 (and (eq major-mode 'calc-mode)
1828 (not calc-executing-macro)
1833 (thing calc-stack)
1834 (calc-any-evaltos nil))
1835 (setq calc-any-selections nil)
1837 (when calc-show-banner
1842 (when calc-show-banner
1844 (insert (math-format-stack-value (car thing)) "\n")
1846 (calc-renumber-stack)
1847 (if calc-display-dirty
1848 (calc-wrapper (setq calc-display-dirty nil)))
1849 (and calc-any-evaltos calc-auto-recompute
1850 (calc-wrapper (calc-refresh-evaltos)))
1852 (calc-align-stack-window)
1855 (and calc-embedded-info (not (eq major-mode 'calc-mode))
1857 (set-buffer (aref calc-embedded-info 1))
1858 (calc-refresh align)))
1859 (setq calc-refresh-count (1+ calc-refresh-count)))
1863 (defun calc-check-trail-aligned ()
1869 (defun calc-trail-buffer ()
1870 (and (or (null calc-trail-buffer)
1871 (null (buffer-name calc-trail-buffer)))
1873 (setq calc-trail-buffer (get-buffer-create "*Calc Trail*"))
1874 (let ((buf (or (and (not (eq major-mode 'calc-mode))
1877 (set-buffer calc-trail-buffer)
1878 (or (eq major-mode 'calc-trail-mode)
1879 (calc-trail-mode buf)))))
1880 (or (and calc-trail-pointer
1881 (eq (marker-buffer calc-trail-pointer) calc-trail-buffer))
1883 (set-buffer calc-trail-buffer)
1885 (setq calc-trail-pointer (point-marker))))
1886 calc-trail-buffer)
1888 (defun calc-record (val &optional prefix)
1889 (setq calc-aborted-prefix nil)
1890 (or calc-executing-macro
1892 (buf (calc-trail-buffer))
1893 (calc-display-raw nil)
1894 (calc-can-abbrev-vectors t)
1899 (math-format-flat-expr val 0)))
1903 (let ((aligned (calc-check-trail-aligned))
1910 (t (insert (format "%4s " prefix))))
1913 (if (and aligned win (not (memq 'hold-trail calc-command-flags)))
1914 (calc-trail-here))
1919 (defun calc-trail-display (flag &optional no-refresh interactive)
1921 (let ((win (get-buffer-window (calc-trail-buffer))))
1922 (if (setq calc-display-trail
1926 (if calc-trail-window-hook
1927 (run-hooks 'calc-trail-window-hook)
1929 (set-window-buffer w calc-trail-buffer)))
1930 (calc-wrapper
1931 (setq overlay-arrow-string calc-trail-overlay
1932 overlay-arrow-position calc-trail-pointer)
1935 (calc-do-refresh)
1936 (calc-refresh))))))
1940 (calc-wrapper
1943 (calc-do-refresh)
1944 (calc-refresh))))))))
1945 calc-trail-buffer)
1947 (defun calc-trail-here ()
1949 (if (eq major-mode 'calc-trail-mode)
1958 (set-marker calc-trail-pointer (point) (current-buffer))
1959 (setq calc-trail-overlay (concat (buffer-substring (point)
1962 overlay-arrow-string calc-trail-overlay
1963 overlay-arrow-position calc-trail-pointer)
1971 (set-window-point win (+ calc-trail-pointer 4))
1972 (set-buffer calc-main-buffer)
1973 (setq overlay-arrow-string calc-trail-overlay
1974 overlay-arrow-position calc-trail-pointer))))))
1982 (defun calc-record-undo (rec)
1983 (or calc-executing-macro
1984 (if (memq 'undo calc-command-flags)
1985 (setq calc-undo-list (cons (cons rec (car calc-undo-list))
1986 (cdr calc-undo-list)))
1987 (setq calc-undo-list (cons (list rec) calc-undo-list)
1988 calc-redo-list nil)
1989 (calc-set-command-flag 'undo))))
1996 (defun calc-binary-op (name func arg &optional ident unary func2)
1997 (setq calc-aborted-prefix name)
1999 (calc-enter-result 2 name (cons (or func2 func)
2001 (calc-top-list 2))))
2002 (require 'calc-ext)
2003 (calc-binary-op-fancy name func arg ident unary)))
2005 (defun calc-unary-op (name func arg &optional func2)
2006 (setq calc-aborted-prefix name)
2008 (calc-enter-result 1 name (list (or func2 func)
2009 (math-check-complete (calc-top 1))))
2010 (require 'calc-ext)
2011 (calc-unary-op-fancy name func arg)))
2014 (defun calc-plus (arg)
2016 (calc-slow-wrapper
2017 (calc-binary-op "+" 'calcFunc-add arg 0 nil '+)))
2019 (defun calc-minus (arg)
2021 (calc-slow-wrapper
2022 (calc-binary-op "-" 'calcFunc-sub arg 0 'neg '-)))
2024 (defun calc-times (arg)
2026 (calc-slow-wrapper
2027 (calc-binary-op "*" 'calcFunc-mul arg 1 nil '*)))
2029 (defun calc-divide (arg)
2031 (calc-slow-wrapper
2032 (calc-binary-op "/" 'calcFunc-div arg 0 'calcFunc-inv '/)))
2034 (defun calc-left-divide (arg)
2036 (calc-slow-wrapper
2037 (calc-binary-op "ldiv" 'calcFunc-ldiv arg 0 nil nil)))
2039 (defun calc-change-sign (arg)
2041 (calc-wrapper
2042 (calc-unary-op "chs" 'neg arg)))
2048 (defun calc-enter (n)
2050 (calc-wrapper
2052 (calc-push-list (calc-top-list 1 (- n))))
2054 (calc-push-list (calc-top-list (calc-stack-size))))
2056 (calc-push-list (calc-top-list n))))))
2059 (defun calc-pop (n)
2061 (calc-wrapper
2063 (top (and (null n) (calc-top 1))))
2067 (calc-pop-push-list 1 (let ((tt (copy-sequence top)))
2071 (if (and calc-any-selections
2072 (calc-top-selected 1 (- nn)))
2073 (calc-delete-selection (- nn))
2074 (calc-pop-stack 1 (- nn) t)))
2076 (calc-pop-stack (calc-stack-size) 1 t))
2078 (if (and calc-any-selections
2080 (calc-top-selected 1 1))
2081 (calc-delete-selection 1)
2082 (calc-pop-stack nn)))))))
2088 (defvar calc-buffer)
2089 (defvar calc-prev-char)
2090 (defvar calc-prev-prev-char)
2091 (defvar calc-digit-value)
2094 (calc-wrapper
2095 (if (or calc-algebraic-mode
2096 (and (> calc-number-radix 14) (eq last-command-char ?e)))
2097 (calc-alg-digit-entry)
2098 (calc-unread-command)
2099 (setq calc-aborted-prefix nil)
2100 (let* ((calc-digit-value nil)
2101 (calc-prev-char nil)
2102 (calc-prev-prev-char nil)
2103 (calc-buffer (current-buffer))
2104 (buf (if calc-emacs-type-lucid
2105 (catch 'calc-foo
2107 (throw 'calc-foo
2109 "Calc: " "" calc-digit-map)))
2116 (read-from-minibuffer "Calc: " "" calc-digit-map))
2118 (or calc-digit-value (setq calc-digit-value (math-read-number buf)))
2119 (if (stringp calc-digit-value)
2120 (calc-alg-entry calc-digit-value)
2121 (if calc-digit-value
2122 (calc-push-list (list (calc-record (calc-normalize
2123 calc-digit-value))))))
2124 (if (eq calc-prev-char 'dots)
2126 (require 'calc-ext)
2127 (calc-dots)))))))
2129 (defsubst calc-minibuffer-size ()
2135 (or (boundp 'calc-buffer)
2138 (setq calc-digit-value (save-excursion
2139 (set-buffer calc-buffer)
2141 (if (and (null calc-digit-value) (> (calc-minibuffer-size) 0))
2144 (calc-temp-minibuffer-message " [Bad format]"))
2147 (calc-unread-command (if (and (eq last-command-char 27)
2154 (defun calc-minibuffer-contains (rex)
2166 (not (calc-minibuffer-contains "[-+]?[0-9]+\\.?0*[@oh].*"))
2167 (not (calc-minibuffer-contains "[-+]?\\(1[1-9]\\|[2-9][0-9]\\)#.*"))))
2169 (if (calc-minibuffer-contains "\\([-+]?\\|.* \\)\\'")
2172 (not (calc-minibuffer-contains ".*#.*"))) (insert "0"))
2175 (insert (int-to-string calc-number-radix)))))
2176 (if (and (calc-minibuffer-contains "\\([-+]?[0-9]+#\\|[^:]*:\\)\\'")
2179 (if (and (calc-minibuffer-contains "[-+]?[0-9]+#\\'")
2182 (if (and (calc-minibuffer-contains "[-+]?0*\\([2-9]\\|1[0-4]\\)#\\'")
2186 (calc-minibuffer-contains ".*#.*"))
2188 (calc-minibuffer-contains "[-+]?\\(1[5-9]\\|[2-9][0-9]\\)#.*"))
2190 (calc-minibuffer-contains "[-+]?\\(2[4-9]\\|[3-9][0-9]\\)#.*")))
2198 (and (not (calc-minibuffer-contains "[-+]?\\(1[5-9]\\|[2-9][0-9]\\)#.*"))
2207 (if (or (calc-minibuffer-contains ".*\\+/-.*")
2208 (calc-minibuffer-contains ".*mod.*")
2209 (calc-minibuffer-contains ".*#.*")
2210 (calc-minibuffer-contains ".*[-+e:]\\'"))
2212 (if (not (calc-minibuffer-contains ".* \\'"))
2216 (not (calc-minibuffer-contains
2218 (if (or (calc-minibuffer-contains ".*\\+/-.*")
2219 (calc-minibuffer-contains ".*mod *[^ ]+")
2220 (calc-minibuffer-contains ".*[-+e:]\\'"))
2222 (if (calc-minibuffer-contains ".*mod \\'")
2223 (if calc-previous-modulo
2224 (insert (math-format-flat-expr calc-previous-modulo 0))
2226 (if (not (calc-minibuffer-contains ".* \\'"))
2231 (if (or (and (calc-minibuffer-contains "[-+]?\\(.*\\+/- *\\|.*mod *\\)?\\([0-9][0-9]?\\)#[0-9a-zA-Z]*\\(:[0-9a-zA-Z]*\\(:[0-9a-zA-Z]*\\)?\\|.[0-9a-zA-Z]*\\(e[-+]?[0-9]*\\)?\\)?\\'")
2242 (calc-minibuffer-contains
2245 (string-match " " calc-hms-format))
2250 (require 'calc-ext)
2251 (calc-digit-dots))
2254 (calc-temp-minibuffer-message " [Bad format]"))))))
2255 (setq calc-prev-prev-char calc-prev-char
2256 calc-prev-char last-command-char))
2262 (cond ((calc-minibuffer-contains ".* \\+/- \\'")
2264 ((calc-minibuffer-contains ".* mod \\'")
2266 ((calc-minibuffer-contains ".* \\'")
2271 (if (= (calc-minibuffer-size) 0)
2287 ;;; integer An integer. For normalized numbers, this format
2299 ;;; (float NUM EXP) A floating-point number, NUM * 10^EXP;
2302 ;;; abs(NUM) < 10^calc-internal-prec.
2303 ;;; Normalized zero is stored as (float 0 0).
2320 ;;; store a date only, or a fraction or float to
2345 ;;; a rational result, but if either argument is a float, result is a float.
2354 ;;; R Normalized real number (float or rational)
2414 ((eq (car math-normalize-a) 'float)
2415 (math-make-float (math-normalize (nth 1 math-normalize-a))
2425 (require 'calc-ext)
2428 (or (and calc-simplify-mode
2429 (require 'calc-ext)
2446 (require 'calc-ext)
2459 (and (not (featurep 'calc-ext))
2460 (require 'calc-ext)
2464 (calc-record-why "*Wrong number of arguments"
2468 (or calc-next-why
2469 (calc-record-why "Wrong type of argument"
2473 (calc-record-why "*Argument out of range"
2477 (calc-record-why "No exact representation for result"
2481 (calc-record-why "*Floating-point overflow occurred"
2485 (calc-record-why "*Floating-point underflow occurred"
2493 (calc-record-why "*Variable is void" (nth 1 err)))))
2502 (cond ((eq (car-safe a) 'float) t)
2516 (calc-incomplete-error a))
2535 (defun math-make-float (mant exp)
2537 '(float 0 0)
2538 (let* ((ldiff (- calc-internal-prec (math-numdigs mant))))
2562 (list 'float mant exp)))))
2570 ;;; Coerce A to be a float. [F N; V V] [Public]
2571 (defun math-float (a)
2572 (cond ((Math-integerp a) (math-make-float a 0))
2573 ((eq (car a) 'frac) (math-div (math-float (nth 1 a)) (nth 2 a)))
2574 ((eq (car a) 'float) a)
2576 (cons (car a) (mapcar 'math-float (cdr a))))
2577 (t (math-float-fancy a))))
2584 ((memq (car a) '(frac float))
2703 (if (and (math-floatp a) (Math-ratp b)) (math-float b) b))
2705 (if (and (math-floatp b) (Math-ratp a)) (math-float a) a))
2728 (require 'calc-ext)
2729 (calc-add-fractions a b))
2732 (or (and (consp a) (eq (car a) 'float))
2733 (setq a (math-float a)))
2734 (or (and (consp b) (eq (car b) 'float))
2735 (setq b (math-float b)))
2736 (math-add-float a b)))
2737 (and (require 'calc-ext)
2739 (and (require 'calc-ext)
2814 (defun math-add-float (a b) ; [F F F]
2817 (if (>= ediff (+ calc-internal-prec calc-internal-prec))
2819 (math-make-float (math-add (nth 1 b)
2825 (+ calc-internal-prec calc-internal-prec))
2827 (math-make-float (math-add (nth 1 a)
2840 (defun math-sub-float (a b) ; [F F F]
2843 (if (>= ediff (+ calc-internal-prec calc-internal-prec))
2845 (math-make-float (math-add (Math-integer-neg (nth 1 b))
2851 (+ calc-internal-prec calc-internal-prec))
2853 (math-make-float (math-add (nth 1 a)
2867 (if (and (math-floatp b) (Math-ratp a)) (math-float a) a)
2868 (require 'calc-ext)
2872 (if (and (math-floatp a) (Math-ratp b)) (math-float b) b)
2873 (require 'calc-ext)
2889 (require 'calc-ext)
2890 (calc-mul-fractions a b))
2893 (or (and (consp a) (eq (car a) 'float))
2894 (setq a (math-float a)))
2895 (or (and (consp b) (eq (car b) 'float))
2896 (setq b (math-float b)))
2897 (math-make-float (math-mul (nth 1 a) (nth 1 b))
2899 (and (require 'calc-ext)
2901 (and (require 'calc-ext)
3057 (require 'calc-ext)
3061 (if (and (math-floatp b) (Math-ratp a)) (math-float a) a)
3062 (require 'calc-ext)
3070 (if calc-prefer-frac
3072 (require 'calc-ext)
3074 (math-div-float (math-make-float a 0)
3075 (math-make-float b 0))))))
3077 (require 'calc-ext)
3078 (calc-div-fractions a b))
3081 (or (and (consp a) (eq (car a) 'float))
3082 (setq a (math-float a)))
3083 (or (and (consp b) (eq (car b) 'float))
3084 (setq b (math-float b)))
3085 (math-div-float a b)))
3086 (and (require 'calc-ext)
3088 (and (require 'calc-ext)
3091 (defun math-div-float (a b) ; [F F F]
3092 (let ((ldiff (max (- (1+ calc-internal-prec)
3095 (math-make-float (math-quotient (math-scale-int (nth 1 a) ldiff) (nth 1 b))
3101 (defvar calc-selection-cache-entry)
3103 (defun math-format-stack-value (entry)
3104 (setq calc-selection-cache-entry calc-selection-cache-default-entry)
3108 ((eq calc-display-raw t) (format "%s" a))
3111 (calc-prepared-composition
3112 calc-prepared-composition)
3114 (memq calc-language '(nil flat unform))
3116 (math-format-number a))
3117 (t (require 'calc-ext)
3121 (and math-comp-selected (setq calc-any-selections t))
3126 (or (equal calc-left-label "")
3128 (make-string (length calc-left-label) ?\s)
3129 calc-left-label)
3131 (when calc-line-numbering
3132 (setq c (math-comp-concat (if (eq calc-language 'big)
3138 (unless (or (equal calc-right-label "")
3140 (require 'calc-ext)
3143 (length calc-right-label)) 0) ?\s)
3145 calc-right-label)))
3147 (if calc-display-raw
3151 (when calc-language-output-filter
3152 (setq s (funcall calc-language-output-filter s)))
3153 (if (eq calc-language 'big)
3155 (when calc-line-numbering
3157 (setcar (cdr entry) (calc-count-lines s))
3165 (let* ((num (if calc-line-numbering 4 0))
3166 (math-svo-wid (calc-window-width))
3168 (if calc-display-just
3170 (require 'calc-ext)
3172 (setq math-svo-off (or calc-display-origin 0))
3173 (when (integerp calc-line-breaking)
3174 (setq math-svo-wid calc-line-breaking)))
3175 (cons (max (- math-svo-off (length calc-left-label)) 0)
3178 (defun calc-count-lines (s)
3186 (defun math-format-value (a &optional w)
3188 (memq calc-language '(nil flat unform)))
3189 (math-format-number a)
3190 (require 'calc-ext)
3191 (let ((calc-line-breaking nil))
3194 (defun calc-window-width ()
3195 (if calc-embedded-info
3196 (let ((win (get-buffer-window (aref calc-embedded-info 0))))
3199 (if calc-line-numbering 5 1))))
3210 (defun math-format-flat-expr (a prec)
3213 (eq calc-display-raw t))
3217 (let ((calc-group-digits nil)
3218 (calc-point-char ".")
3219 (calc-frac-format (if (> (length (car calc-frac-format)) 1)
3221 (calc-complex-format nil)
3222 (calc-hms-format "%s@ %s' %s\"")
3223 (calc-language nil))
3224 (math-format-number a)))
3226 (require 'calc-ext)
3227 (math-format-flat-expr-fancy a prec))))
3232 (defun math-format-number (a &optional prec) ; [X N] [Public]
3234 ((eq calc-display-raw t) (format "%s" a))
3235 ((and (nth 1 calc-frac-format) (Math-integerp a))
3236 (require 'calc-ext)
3237 (math-format-number (math-adjust-fraction a)))
3239 (if (not (or calc-group-digits calc-leading-zeros))
3240 (if (= calc-number-radix 10)
3243 (concat "-" (math-format-number (- a)))
3244 (require 'calc-ext)
3245 (if math-radix-explicit-format
3246 (if calc-radix-formatter
3247 (funcall calc-radix-formatter
3248 calc-number-radix
3249 (if (= calc-number-radix 2)
3250 (math-format-binary a)
3251 (math-format-radix a)))
3252 (format "%d#%s" calc-number-radix
3253 (if (= calc-number-radix 2)
3254 (math-format-binary a)
3255 (math-format-radix a))))
3256 (math-format-radix a))))
3257 (math-format-number (math-bignum a))))
3260 ((eq (car a) 'bigpos) (math-format-bignum (cdr a)))
3261 ((eq (car a) 'bigneg) (concat "-" (math-format-bignum (cdr a))))
3262 ((and (eq (car a) 'float) (= calc-number-radix 10))
3264 (concat "-" (math-format-number (math-neg a)))
3267 (fmt (car calc-float-format))
3268 (figs (nth 1 calc-float-format))
3269 (point calc-point-char)
3278 (math-format-bignum-decimal (cdr mant))))
3286 (when calc-group-digits
3287 (require 'calc-ext)
3288 (setq str (math-group-float str))))
3290 (setq figs (+ calc-internal-prec figs)))
3298 (math-format-bignum-decimal (cdr mant))))
3301 (if (and (eq fmt 'float)
3302 (<= dpos (+ calc-internal-prec calc-display-sci-high))
3303 (>= dpos (+ calc-display-sci-low 2)))
3316 (when calc-group-digits
3317 (require 'calc-ext)
3318 (setq str (math-group-float str))))
3329 (when calc-group-digits
3330 (require 'calc-ext)
3331 (setq str (math-group-float str)))
3332 (setq str (format (if (memq calc-language '(math maple))
3339 (require 'calc-ext)
3340 (math-format-number-fancy a prec))))
3342 (defun math-format-bignum (a) ; [X L]
3343 (if (and (= calc-number-radix 10)
3344 (not calc-leading-zeros)
3345 (not calc-group-digits))
3346 (math-format-bignum-decimal a)
3347 (require 'calc-ext)
3348 (math-format-bignum-fancy a)))
3350 (defun math-format-bignum-decimal (a) ; [X L]
3354 (setq s (concat (format "%06d" (+ (* (nth 1 a) 1000) (car a))) s)
3369 (if (and (eq calc-language 'c)
3389 (require 'calc-ext)
3401 (list 'float
3413 (let ((mant (math-float mant)))
3414 (list 'float (nth 1 mant) (+ (nth 2 mant) exp)))))))
3498 (defun calc-grab-region (top bot arg)
3501 (require 'calc-ext)
3502 (calc-do-grab-region top bot arg))
3505 (defun calc-grab-rectangle (top bot arg)
3508 (require 'calc-ext)
3509 (calc-do-grab-rectangle top bot arg))
3511 (defun calc-grab-sum-down (top bot arg)
3514 (require 'calc-ext)
3515 (calc-do-grab-rectangle top bot arg 'calcFunc-reduced))
3517 (defun calc-grab-sum-across (top bot arg)
3520 (require 'calc-ext)
3521 (calc-do-grab-rectangle top bot arg 'calcFunc-reducea))
3525 (defun calc-embedded (arg &optional end obeg oend)
3528 (require 'calc-ext)
3529 (calc-do-embedded arg end obeg oend))
3532 (defun calc-embedded-activate (&optional arg cbuf)
3536 (calc-do-embedded-activate arg cbuf))
3538 (defun calc-user-invocation ()
3540 (unless calc-invocation-macro
3542 (execute-kbd-macro calc-invocation-macro nil))
3548 (require 'calc-ext)
3553 (defun calc-read-key (&optional optkey)
3554 (cond (calc-emacs-type-lucid
3563 (defun calc-unread-command (&optional input)
3570 (defun calc-clear-unread-commands ()
3572 (calc-emacs-type-lucid (setq unread-command-event nil))
3575 (when calc-always-load-extensions
3576 (require 'calc-ext)
3577 (calc-load-everything))
3580 (run-hooks 'calc-load-hook)
3582 (provide 'calc)
3585 ;;; calc.el ends here