-;; Calculator for GNU Emacs, part II [calc-math.el]
+;;; calc-math.el --- mathematical functions for Calc
+
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
-;; Written by Dave Gillespie, daveg@synaptics.com.
+
+;; Author: David Gillespie <daveg@synaptics.com>
+;; Maintainer: Jay Belanger <belanger@truman.edu>
;; This file is part of GNU Emacs.
;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies.
+;;; Commentary:
+;;; Code:
;; This file is autoloaded from calc-ext.el.
-(require 'calc-ext)
+(require 'calc-ext)
(require 'calc-macs)
-(defun calc-Need-calc-math () nil)
-
-
(defun calc-sqrt (arg)
(interactive "P")
(calc-slow-wrapper
(cond ((= arg 1)
(calc-wrapper
(calc-change-mode 'calc-angle-mode 'deg)
- (message "Angles measured in degrees.")))
+ (message "Angles measured in degrees")))
((= arg 2) (calc-radians-mode))
((= arg 3) (calc-hms-mode))
(t (error "Prefix argument out of range"))))
(interactive)
(calc-wrapper
(calc-change-mode 'calc-angle-mode 'rad)
- (message "Angles measured in radians.")))
+ (message "Angles measured in radians")))
;;; Compute the integer square-root floor(sqrt(A)). A > 0. [I I] [Public]
(math-floor (math-sqrt a))))
-;;; This returns (flag . result) where the flag is T if A is a perfect square.
+;;; This returns (flag . result) where the flag is t if A is a perfect square.
(defun math-isqrt-bignum (a) ; [P.l L]
(let ((len (length a)))
(if (= (% len 2) 0)
(progn
(calc-record-why 'numberp a)
(list 'calcFunc-sqrt a))))
-(defalias calcFunc-sqrt 'math-sqrt)
+(defalias 'calcFunc-sqrt 'math-sqrt)
(defun math-infinite-dir (a &optional inf)
(or inf (setq inf (math-infinitep a)))
((eq (car-safe b) 'hms)
(math-to-hms (math-hypot a (math-from-hms b 'deg))))
(t nil)))
-(defalias calcFunc-hypot 'math-hypot)
+(defalias 'calcFunc-hypot 'math-hypot)
(defun calcFunc-sqr (x)
(math-pow x 2))
(and root (list 'polar root (math-div (nth 2 a) n)))))
(t nil)))
-(defun math-nth-root-float (a n &optional guess)
+;; The variables math-nrf-n, math-nrf-nf and math-nrf-nfm1 are local
+;; to math-nth-root-float, but are used by math-nth-root-float-iter,
+;; which is called by math-nth-root-float.
+(defvar math-nrf-n)
+(defvar math-nrf-nf)
+(defvar math-nrf-nfm1)
+
+(defun math-nth-root-float (a math-nrf-n &optional guess)
(math-inexact-result)
(math-with-extra-prec 1
- (let ((nf (math-float n))
- (nfm1 (math-float (1- n))))
+ (let ((math-nrf-nf (math-float math-nrf-n))
+ (math-nrf-nfm1 (math-float (1- math-nrf-n))))
(math-nth-root-float-iter a (or guess
(math-make-float
1 (/ (+ (math-numdigs (nth 1 a))
(nth 2 a)
- (/ n 2))
- n)))))))
+ (/ math-nrf-n 2))
+ math-nrf-n)))))))
-(defun math-nth-root-float-iter (a guess) ; uses "n", "nf", "nfm1"
+(defun math-nth-root-float-iter (a guess)
(math-working "root" guess)
- (let ((g2 (math-div-float (math-add-float (math-mul nfm1 guess)
+ (let ((g2 (math-div-float (math-add-float (math-mul math-nrf-nfm1 guess)
(math-div-float
- a (math-ipow guess (1- n))))
- nf)))
+ a (math-ipow guess (1- math-nrf-n))))
+ math-nrf-nf)))
(if (math-nearly-equal-float g2 guess)
g2
(math-nth-root-float-iter a g2))))
-(defun math-nth-root-integer (a n &optional guess) ; [I I S]
+;; The variable math-nri-n is local to math-nth-root-integer, but
+;; is used by math-nth-root-int-iter, which is called by
+;; math-nth-root-int.
+(defvar math-nri-n)
+
+(defun math-nth-root-integer (a math-nri-n &optional guess) ; [I I S]
(math-nth-root-int-iter a (or guess
(math-scale-int 1 (/ (+ (math-numdigs a)
- (1- n))
- n)))))
+ (1- math-nri-n))
+ math-nri-n)))))
-(defun math-nth-root-int-iter (a guess) ; uses "n"
+(defun math-nth-root-int-iter (a guess)
(math-working "root" guess)
- (let* ((q (math-idivmod a (math-ipow guess (1- n))))
- (s (math-add (car q) (math-mul (1- n) guess)))
- (g2 (math-idivmod s n)))
+ (let* ((q (math-idivmod a (math-ipow guess (1- math-nri-n))))
+ (s (math-add (car q) (math-mul (1- math-nri-n) guess)))
+ (g2 (math-idivmod s math-nri-n)))
(if (Math-natnum-lessp (car g2) guess)
(math-nth-root-int-iter a (car g2))
(cons (and (equal (car g2) guess)
(math-div (calcFunc-ln x) 0)
(math-reject-arg b "*Logarithm base one")))
((math-equal-int x 1)
- (if (or (math-floatp a) (math-floatp b)) '(float 0 0) 0))
+ (if (math-floatp b) '(float 0 0) 0))
((and (Math-ratp x) (Math-ratp b)
(math-posp x) (math-posp b)
(let* ((sign 1) (inv nil)
(cons (equal pow x) sum)))
+(defvar math-log-base-cache nil)
(defun math-log-base-raw (b) ; [N N]
(if (not (and (equal (car math-log-base-cache) b)
(eq (nth 1 math-log-base-cache) calc-internal-prec)))
(setq math-log-base-cache (list b calc-internal-prec
(math-ln-raw (math-float b)))))
(nth 2 math-log-base-cache))
-(setq math-log-base-cache nil)
(defun calcFunc-lnp1 (x) ; [N N] [Public]
(cond ((Math-equal-int x -1)
(t (list 'calcFunc-deg a))))
(put 'calcFunc-deg 'math-expandable t)
-;;; calc-math.el ends here
-
+(provide 'calc-math)
+;;; arch-tag: c7367e8e-d0b8-4f70-8577-2fb3f31dbb4c
+;;; calc-math.el ends here