1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-22 18:35:09 +00:00

calc/calc.el (calc-logunits-field-reference) Renamed from

`calc-default-field-reference-level'.
(calc-logunits-power-reference): Renamed from `calc-default-power-reference-level' 

calc/calc-units.el (math-logunits-quant):  Renamed from `math-logunits-level'
(math-logunits-plus):  Renamed from math-logcombine.
(calcFunc-luplus, calcFunc-luminus calc-luplus, calc-luminus): Remove functions.
(calcFunc-lufieldplus, calcFunc-lupowerplus, calcFunc-lufieldminus)
(calcFunc-lufieldminus,calc-logunits-plus calc-logunits-minus): New functions.
(calcFunc-fieldquant): Renamed from `calcFunc-fieldlevel'.
(calcFunc-powerquant): Renamed from `calcFunc-powerlevel'.
(calc-logunits-quantity): Renamed from `calc-level'.
(calcFunc-dbfieldlevel, calcFunc-dbpowerlevel, calcFunc-npfieldlevel)
(calcFunc-nppowerlevel,calc-logunits-dblevel, calc-logunits-nplevel)
(math-logunits-times, calcFunc-lufieldtimes, calcFunc-lupowertimes)
(calc-logunits-times, math-logunits-divide, calcFunc-lufielddiv)
(calcFunc-lupowerdiv,calc-logunits-divide,math-logunits-level):
New functions.

calc-help.el (calc-u-prefix-help): Removed "L" reference.
(calc-ul-prefix-help): Remove.
(calc-l-prefix-help): New function.
(calc-full-help): Add reference to `calc-l-prefix-help'.

calc-ext.el (calc-init-extensions): Update autoloads.
This commit is contained in:
Jay Belanger 2011-02-06 16:42:14 -06:00
parent 76b8d9dd0e
commit 6f16beccf4
4 changed files with 239 additions and 59 deletions

View File

@ -421,6 +421,16 @@
(define-key calc-mode-map "kP" 'calc-utpp)
(define-key calc-mode-map "kT" 'calc-utpt)
(define-key calc-mode-map "l" nil)
(define-key calc-mode-map "lq" 'calc-logunits-quantity)
(define-key calc-mode-map "ld" 'calc-logunits-dblevel)
(define-key calc-mode-map "ln" 'calc-logunits-nplevel)
(define-key calc-mode-map "l+" 'calc-logunits-plus)
(define-key calc-mode-map "l-" 'calc-logunits-minus)
(define-key calc-mode-map "l*" 'calc-logunits-times)
(define-key calc-mode-map "l/" 'calc-logunits-divide)
(define-key calc-mode-map "l?" 'calc-l-prefix-help)
(define-key calc-mode-map "m" nil)
(define-key calc-mode-map "m?" 'calc-m-prefix-help)
(define-key calc-mode-map "ma" 'calc-algebraic-mode)
@ -546,10 +556,6 @@
(define-key calc-mode-map "ud" 'calc-define-unit)
(define-key calc-mode-map "ue" 'calc-explain-units)
(define-key calc-mode-map "ug" 'calc-get-unit-definition)
(define-key calc-mode-map "ul+" 'calc-luplus)
(define-key calc-mode-map "ul-" 'calc-luminus)
(define-key calc-mode-map "ull" 'calc-level)
(define-key calc-mode-map "ul?" 'calc-ul-prefix-help)
(define-key calc-mode-map "up" 'calc-permanent-units)
(define-key calc-mode-map "ur" 'calc-remove-units)
(define-key calc-mode-map "us" 'calc-simplify-units)
@ -933,8 +939,12 @@ calc-store-value calc-var-name)
("calc-stuff" calc-explain-why calcFunc-clean
calcFunc-pclean calcFunc-pfloat calcFunc-pfrac)
("calc-units" calcFunc-usimplify calcFunc-luplus
calcFunc-luminus calcFunc-fieldlevel calcFunc-powerlevel
("calc-units" calcFunc-usimplify calcFunc-lufieldplus
calcFunc-lupowerplus calcFunc-lufieldminus calcFunc-lupowerminus
calcFunc-lufieldtimes calcFunc-lupowertimes calcFunc-lufielddiv
calcFunc-lupowerdiv calcFunc-fieldquant calcFunc-powerquant
calcFunc-dbfieldlevel calcFunc-dbpowerlevel calcFunc-npfieldlevel
calcFunc-nppowerlevel
math-build-units-table math-build-units-table-buffer
math-check-unit-name math-convert-temperature math-convert-units
math-extract-units math-remove-units math-simplify-units
@ -1166,7 +1176,9 @@ calc-convert-temperature calc-convert-units calc-define-unit
calc-enter-units-table calc-explain-units calc-extract-units
calc-get-unit-definition calc-permanent-units calc-quick-units
calc-remove-units calc-simplify-units calc-undefine-unit
calc-view-units-table calc-luplus calc-luminus calc-level)
calc-view-units-table calc-logunits-quantity calc-logunits-dblevel
calc-logunits-nplevel calc-logunits-plus calc-logunits-minus
calc-logunits-times calc-logunits-divide)
("calc-vec" calc-arrange-vector calc-build-vector calc-cnorm
calc-conj-transpose calc-cons calc-cross calc-kron calc-diag

View File

@ -455,6 +455,7 @@ C-w Describe how there is no warranty for Calc."
calc-h-prefix-help
calc-j-prefix-help
calc-k-prefix-help
calc-l-prefix-help
calc-m-prefix-help
calc-r-prefix-help
calc-s-prefix-help
@ -662,19 +663,18 @@ C-w Describe how there is no warranty for Calc."
(calc-do-prefix-help
'("Simplify, Convert, Temperature-convert, Base-units"
"Autorange; Remove, eXtract; Explain; View-table; 0-9"
"Define, Undefine, Get-defn, Permanent, Logarithmic"
"Define, Undefine, Get-defn, Permanent"
"SHIFT + View-table-other-window"
"SHIFT + stat: Mean, G-mean, Std-dev, Covar, maX, miN"
"SHIFT + stat: + (sum), - (asum), * (prod), # (count)")
"units/stat" ?u))
(defun calc-ul-prefix-help ()
(defun calc-l-prefix-help ()
(interactive)
(if (eq this-command last-command)
(message "ul-")
(message "logarithmic-units: + (logarithmic), - (logarithmic), Level: ul-"))
(push ?l unread-command-events)
(push ?u unread-command-events))
(calc-do-prefix-help
'("Quantity, DB level, Np level"
"+, -, *, /")
"log units" ?l))
(defun calc-v-prefix-help ()
(interactive)

View File

@ -1567,7 +1567,7 @@ If EXPR is nil, return nil."
(list '^ (math-extract-logunits (nth 1 expr)) (nth 2 expr))
(if (member expr math-logunits) expr 1))))
(defun math-logcombine (a b neg)
(defun math-logunits-plus (a b neg power)
(let ((aunit (math-simplify (math-extract-logunits a))))
(if (not (eq (car-safe aunit) 'var))
(calc-record-why "*Improper logarithmic unit" aunit)
@ -1583,49 +1583,160 @@ If EXPR is nil, return nil."
(calc-record-why "*Improper coefficients" nil)
(math-mul
(if (equal aunit '(var dB var-dB))
(math-mul 10
(calcFunc-log10
(if neg
(math-sub
(math-pow 10 (math-div acoeff 10))
(math-pow 10 (math-div bcoeff 10)))
(math-add
(math-pow 10 (math-div acoeff 10))
(math-pow 10 (math-div bcoeff 10))))))
(calcFunc-ln
(if neg
(math-sub
(calcFunc-exp acoeff)
(calcFunc-exp bcoeff))
(math-add
(calcFunc-exp acoeff)
(calcFunc-exp bcoeff)))))
(let ((coef (if power 10 20)))
(math-mul coef
(calcFunc-log10
(if neg
(math-sub
(math-pow 10 (math-div acoeff coef))
(math-pow 10 (math-div bcoeff coef)))
(math-add
(math-pow 10 (math-div acoeff coef))
(math-pow 10 (math-div bcoeff coef)))))))
(let ((coef (if power 2 1)))
(math-div
(calcFunc-ln
(if neg
(math-sub
(calcFunc-exp (math-mul coef acoeff))
(calcFunc-exp (math-mul coef bcoeff)))
(math-add
(calcFunc-exp (math-mul coef acoeff))
(calcFunc-exp (math-mul coef bcoeff)))))
coef)))
units)))))))
(defun calcFunc-luplus (a b)
(math-logcombine a b nil))
(defun calcFunc-lufieldplus (a b)
(math-logunits-plus a b nil nil))
(defun calcFunc-luminus (a b)
(math-logcombine a b t))
(defun calcFunc-lupowerplus (a b)
(math-logunits-plus a b nil t))
(defun calc-luplus (arg)
(defun calcFunc-lufieldminus (a b)
(math-logunits-plus a b t nil))
(defun calcFunc-lupowerminus (a b)
(math-logunits-plus a b t t))
(defun calc-logunits-plus (arg)
(interactive "P")
(calc-slow-wrapper
(if (calc-is-inverse)
(calc-binary-op "lu-" 'calcFunc-luminus arg)
(calc-binary-op "lu+" 'calcFunc-luplus arg))))
(if (calc-is-hyperbolic)
(calc-binary-op "lu-" 'calcFunc-lufieldminus arg)
(calc-binary-op "lu-" 'calcFunc-lupowerminus arg))
(if (calc-is-hyperbolic)
(calc-binary-op "lu+" 'calcFunc-lufieldplus arg)
(calc-binary-op "lu+" 'calcFunc-lupowerplus arg)))))
(defun calc-luminus (arg)
(defun calc-logunits-minus (arg)
(interactive "P")
(calc-slow-wrapper
(if (calc-is-inverse)
(calc-binary-op "lu+" 'calcFunc-luplus arg)
(calc-binary-op "lu-" 'calcFunc-luminus arg))))
(if (calc-is-hyperbolic)
(calc-binary-op "lu+" 'calcFunc-lufieldplus arg)
(calc-binary-op "lu+" 'calcFunc-lupowerplus arg))
(if (calc-is-hyperbolic)
(calc-binary-op "lu-" 'calcFunc-lufieldminus arg)
(calc-binary-op "lu-" 'calcFunc-lupowerminus arg)))))
;(defun calcFunc-lmul (a b)
(defun math-logunits-times (a b power)
(let (logunit coef units number)
(cond
((and
(setq logunit (math-simplify (math-extract-logunits a)))
(eq (car-safe logunit) 'var)
(eq (math-simplify (math-extract-units b)) 1))
(setq coef (math-simplify (math-remove-units a))
units (math-extract-units a)
number b))
((and
(setq logunit (math-simplify (math-extract-logunits b)))
(eq (car-safe logunit) 'var)
(eq (math-simplify (math-extract-units a)) 1))
(setq coef (math-simplify (math-remove-units b))
units (math-extract-units b)
number a))
(t (setq logunit nil)))
(if logunit
(cond
((equal logunit '(var dB var-dB))
(math-simplify
(math-mul
(math-add
coef
(math-mul (if power 10 20)
(calcFunc-log10 number)))
units)))
(t
(math-simplify
(math-mul
(math-add
coef
(math-div (calcFunc-ln number) (if power 2 1)))
units))))
(calc-record-why "*Improper units" nil))))
(defun math-logunits-divide (a b power)
(let ((logunit (math-simplify (math-extract-logunits a))))
(if (not (eq (car-safe logunit) 'var))
(calc-record-why "*Improper logarithmic unit" logunit)
(if (math-units-in-expr-p b nil)
(calc-record-why "*Improper units quantity" b)
(let* ((units (math-extract-units a))
(coef (math-simplify (math-remove-units a))))
(cond
((equal logunit '(var dB var-dB))
(math-simplify
(math-mul
(math-sub
coef
(math-mul (if power 10 20)
(calcFunc-log10 b)))
units)))
(t
(math-simplify
(math-mul
(math-sub
coef
(math-div (calcFunc-ln b) (if power 2 1)))
units)))))))))
(defun math-logunit-level (val ref power)
(defun calcFunc-lufieldtimes (a b)
(math-logunits-times a b nil))
(defun calcFunc-lupowertimes (a b)
(math-logunits-times a b t))
(defun calc-logunits-times (arg)
(interactive "P")
(calc-slow-wrapper
(if (calc-is-inverse)
(if (calc-is-hyperbolic)
(calc-binary-op "lu/" 'calcFunc-lufielddiv arg)
(calc-binary-op "lu/" 'calcFunc-lupowerdiv arg))
(if (calc-is-hyperbolic)
(calc-binary-op "lu*" 'calcFunc-lufieldtimes arg)
(calc-binary-op "lu*" 'calcFunc-lupowertimes arg)))))
(defun calcFunc-lufielddiv (a b)
(math-logunits-divide a b nil))
(defun calcFunc-lupowerdiv (a b)
(math-logunits-divide a b t))
(defun calc-logunits-divide (arg)
(interactive "P")
(calc-slow-wrapper
(if (calc-is-inverse)
(if (calc-is-hyperbolic)
(calc-binary-op "lu*" 'calcFunc-lufieldtimes arg)
(calc-binary-op "lu*" 'calcFunc-lupowertimes arg))
(if (calc-is-hyperbolic)
(calc-binary-op "lu/" 'calcFunc-lufielddiv arg)
(calc-binary-op "lu/" 'calcFunc-lupowerdiv arg)))))
(defun math-logunits-quant (val ref power)
(let ((lunit (math-simplify (math-extract-logunits val))))
(if (not (eq (car-safe lunit) 'var))
(calc-record-why "*Improper logarithmic unit" lunit)
@ -1647,29 +1758,86 @@ If EXPR is nil, return nil."
(math-mul 2 coeff)
coeff)))))))))
(defvar calc-default-field-reference-level)
(defvar calc-default-power-reference-level)
(defvar calc-logunits-field-reference)
(defvar calc-logunits-power-reference)
(defun calcFunc-fieldlevel (val &optional ref)
(defun calcFunc-fieldquant (val &optional ref)
(unless ref
(setq ref (math-read-expr calc-default-field-reference-level)))
(math-logunit-level val ref nil))
(setq ref (math-read-expr calc-logunits-field-reference)))
(math-logunits-quant val ref nil))
(defun calcFunc-powerlevel (val &optional ref)
(defun calcFunc-powerquant (val &optional ref)
(unless ref
(setq ref (math-read-expr calc-default-power-reference-level)))
(math-logunit-level val ref t))
(setq ref (math-read-expr calc-logunits-power-reference)))
(math-logunits-quant val ref t))
(defun calc-level (arg)
(defun calc-logunits-quantity (arg)
(interactive "P")
(calc-slow-wrapper
(if (calc-is-hyperbolic)
(if (calc-is-option)
(calc-binary-op "plvl" 'calcFunc-powerlevel arg)
(calc-unary-op "plvl" 'calcFunc-powerlevel arg))
(calc-binary-op "lupq" 'calcFunc-fieldquant arg)
(calc-unary-op "lupq" 'calcFunc-fieldquant arg))
(if (calc-is-option)
(calc-binary-op "flvl" 'calcFunc-fieldlevel arg)
(calc-unary-op "flvl" 'calcFunc-fieldlevel arg)))))
(calc-binary-op "lufq" 'calcFunc-powerquant arg)
(calc-unary-op "lufq" 'calcFunc-powerquant arg)))))
(defun math-logunits-level (val ref db power)
"Compute the value of VAL in decibels or nepers."
(let* ((ratio (math-simplify-units (math-div val ref)))
(units (math-simplify (math-extract-units ratio))))
(math-mul
(if db
(math-mul
(math-mul (if power 10 20)
(calcFunc-log10 ratio))
'(var dB var-dB))
(math-mul
(math-div (calcFunc-ln ratio) (if power 2 1))
'(var Np var-Np)))
units)))
(defun calcFunc-dbfieldlevel (val &optional ref)
(unless ref
(setq ref (math-read-expr calc-logunits-field-reference)))
(math-logunits-level val ref t nil))
(defun calcFunc-dbpowerlevel (val &optional ref)
(unless ref
(setq ref (math-read-expr calc-logunits-power-reference)))
(math-logunits-level val ref t t))
(defun calcFunc-npfieldlevel (val &optional ref)
(unless ref
(setq ref (math-read-expr calc-logunits-field-reference)))
(math-logunits-level val ref nil nil))
(defun calcFunc-nppowerlevel (val &optional ref)
(unless ref
(setq ref (math-read-expr calc-logunits-power-reference)))
(math-logunits-level val ref nil t))
(defun calc-logunits-dblevel (arg)
(interactive "P")
(calc-slow-wrapper
(if (calc-is-hyperbolic)
(if (calc-is-option)
(calc-binary-op "ludb" 'calcFunc-dbfieldlevel arg)
(calc-unary-op "ludb" 'calcFunc-dbfieldlevel arg))
(if (calc-is-option)
(calc-binary-op "ludb" 'calcFunc-dbpowerlevel arg)
(calc-unary-op "ludb" 'calcFunc-dbpowerlevel arg)))))
(defun calc-logunits-nplevel (arg)
(interactive "P")
(calc-slow-wrapper
(if (calc-is-hyperbolic)
(if (calc-is-option)
(calc-binary-op "lunp" 'calcFunc-npfieldlevel arg)
(calc-unary-op "lunp" 'calcFunc-npfieldlevel arg))
(if (calc-is-option)
(calc-binary-op "lunp" 'calcFunc-nppowerlevel arg)
(calc-unary-op "lunp" 'calcFunc-nppowerlevel arg)))))
(provide 'calc-units)

View File

@ -434,13 +434,13 @@ by displaying the sub-formula in `calc-selected-face'."
:group 'calc
:type 'boolean)
(defcustom calc-default-field-reference-level
(defcustom calc-logunits-field-reference
"20 uPa"
"The default reference level for logarithmic units (field)."
:group 'calc
:type '(string))
(defcustom calc-default-power-reference-level
(defcustom calc-logunits-power-reference
"mW"
"The default reference level for logarithmic units (power)."
:group 'calc