emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r103470: * calc/calc-math.el (calcFun


From: Jay Belanger
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r103470: * calc/calc-math.el (calcFunc-log10): Check for symbolic mode
Date: Tue, 01 Mar 2011 21:07:34 -0600
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 103470
committer: Jay Belanger <address@hidden>
branch nick: trunk
timestamp: Tue 2011-03-01 21:07:34 -0600
message:
  * calc/calc-math.el (calcFunc-log10): Check for symbolic mode
    when evaluating.
  
  * calc/calc-units.el (math-conditional-apply, math-conditional-pow): 
    New function.
    (math-logunits-add, math-logunits-mul, math-logunits-divide):
    (math-logunits-quant, math-logunits-level): Use
    `math-conditional-apply' and `math-conditional-pow' to evaluate 
    functions.
    (math-logunits-level): Extract units from ratio.
modified:
  lisp/ChangeLog
  lisp/calc/calc-math.el
  lisp/calc/calc-units.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-03-01 15:18:53 +0000
+++ b/lisp/ChangeLog    2011-03-02 03:07:34 +0000
@@ -1,3 +1,16 @@
+2011-03-02  Jay Belanger  <address@hidden>
+
+       * calc/calc-math.el (calcFunc-log10): Check for symbolic mode
+       when evaluating.
+
+       * calc/calc-units.el (math-conditional-apply, math-conditional-pow):
+       New function.
+       (math-logunits-add, math-logunits-mul, math-logunits-divide):
+       (math-logunits-quant, math-logunits-level):
+       Use `math-conditional-apply' and `math-conditional-pow' to evaluate
+       functions.
+       (math-logunits-level): Extract units from ratio.
+
 2011-03-01  Juanma Barranquero  <address@hidden>
 
        * emacs-lisp/cl-macs.el (lexical-let*): Fix argument name in docstring.

=== modified file 'lisp/calc/calc-math.el'
--- a/lisp/calc/calc-math.el    2011-02-27 01:33:37 +0000
+++ b/lisp/calc/calc-math.el    2011-03-02 03:07:34 +0000
@@ -1574,7 +1574,7 @@
         (if calc-infinite-mode
             '(neg (var inf var-inf))
           (math-reject-arg x "*Logarithm of zero")))
-        ;;(calc-symbolic-mode (signal 'inexact-result nil))
+        (calc-symbolic-mode (signal 'inexact-result nil))
        ((Math-numberp x)
         (math-with-extra-prec 2
           (let ((xf (math-float x)))

=== modified file 'lisp/calc/calc-units.el'
--- a/lisp/calc/calc-units.el   2011-02-07 22:25:31 +0000
+++ b/lisp/calc/calc-units.el   2011-03-02 03:07:34 +0000
@@ -1559,6 +1559,20 @@
 (defvar math-logunits '((var dB var-dB)
                         (var Np var-Np)))
 
+(defun math-conditional-apply (fn &rest args)
+  "Evaluate f(args) unless in symbolic mode.
+In symbolic mode, return the list (fn args)."
+  (if calc-symbolic-mode
+      (cons fn args)
+    (apply fn args)))
+
+(defun math-conditional-pow (a b)
+  "Evaluate a^b unless in symbolic mode.
+In symbolic mode, return the list (^ a b)."
+  (if calc-symbolic-mode
+      (list '^ a b)
+    (math-pow a b)))
+
 (defun math-extract-logunits (expr)
   (if (memq (car-safe expr) '(* /))
       (cons (car expr)
@@ -1585,24 +1599,24 @@
              (if (equal aunit '(var dB var-dB))
                  (let ((coef (if power 10 20)))
                    (math-mul coef
-                             (calcFunc-log10
+                             (math-conditional-apply 'calcFunc-log10
                               (if neg
                                   (math-sub
-                                   (math-pow 10 (math-div acoeff coef))
-                                   (math-pow 10 (math-div bcoeff coef)))
+                                   (math-conditional-pow 10 (math-div acoeff 
coef))
+                                   (math-conditional-pow 10 (math-div bcoeff 
coef)))
                                 (math-add
-                                 (math-pow 10 (math-div acoeff coef))
-                                 (math-pow 10 (math-div bcoeff coef)))))))
+                                 (math-conditional-pow 10 (math-div acoeff 
coef))
+                                 (math-conditional-pow 10 (math-div bcoeff 
coef)))))))
                (let ((coef (if power 2 1)))
                  (math-div
-                  (calcFunc-ln
+                  (math-conditional-apply 'calcFunc-ln
                    (if neg
                        (math-sub
-                        (calcFunc-exp (math-mul coef acoeff))
-                        (calcFunc-exp (math-mul coef bcoeff)))
+                        (math-conditional-apply 'calcFunc-exp (math-mul coef 
acoeff))
+                        (math-conditional-apply 'calcFunc-exp (math-mul coef 
bcoeff)))
                      (math-add
-                      (calcFunc-exp (math-mul coef acoeff))
-                      (calcFunc-exp (math-mul coef bcoeff)))))
+                      (math-conditional-apply 'calcFunc-exp (math-mul coef 
acoeff))
+                      (math-conditional-apply 'calcFunc-exp (math-mul coef 
bcoeff)))))
                   coef)))
              units)))))))
 
@@ -1666,14 +1680,14 @@
             (math-add
              coef 
              (math-mul (if power 10 20)
-                       (calcFunc-log10 number)))
+                       (math-conditional-apply 'calcFunc-log10 number)))
             units)))
          (t
           (math-simplify
            (math-mul
             (math-add
              coef 
-             (math-div (calcFunc-ln number) (if power 2 1)))
+             (math-div (math-conditional-apply 'calcFunc-ln number) (if power 
2 1)))
             units))))
       (calc-record-why "*Improper units" nil))))
 
@@ -1692,14 +1706,14 @@
               (math-sub
                coef 
                (math-mul (if power 10 20)
-                         (calcFunc-log10 b)))
+                         (math-conditional-apply 'calcFunc-log10 b)))
               units)))
          (t
           (math-simplify
            (math-mul
             (math-sub
              coef 
-             (math-div (calcFunc-ln b) (if power 2 1)))
+             (math-div (math-conditional-apply 'calcFunc-ln b) (if power 2 1)))
             units)))))))))
 
 (defun calcFunc-lufieldtimes (a b)
@@ -1747,14 +1761,14 @@
          (if (equal lunit '(var dB var-dB))
              (math-mul 
               ref
-              (math-pow 
+              (math-conditional-pow 
                10
                (math-div
                 coeff
                 (if power 10 20))))
            (math-mul 
             ref
-            (calcFunc-exp
+            (math-conditional-apply 'calcFunc-exp
              (if power 
                  (math-mul 2 coeff)
                coeff))))
@@ -1787,15 +1801,16 @@
 (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)))
+             (ratiou (math-simplify-units (math-remove-units ratio)))
              (units (math-simplify (math-extract-units ratio))))
         (math-mul
          (if db
              (math-mul
               (math-mul (if power 10 20)
-                        (calcFunc-log10 ratio))
+                        (math-conditional-apply 'calcFunc-log10 ratiou))
               '(var dB var-dB))
            (math-mul
-            (math-div (calcFunc-ln ratio) (if power 2 1))
+            (math-div (math-conditional-apply 'calcFunc-ln ratiou) (if power 2 
1))
             '(var Np var-Np)))
          units)))
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]