diff options
| author | Jay Belanger | 2011-03-01 21:07:34 -0600 |
|---|---|---|
| committer | Jay Belanger | 2011-03-01 21:07:34 -0600 |
| commit | 771fc75ee915ce4cbf6f257a82e22ea49462df72 (patch) | |
| tree | 41a6f99b7ec0ec91e3ad6adac304c439d811876a /lisp | |
| parent | 0dc3e4109e0c41bbf5fdcae0ff1156162719693e (diff) | |
| download | emacs-771fc75ee915ce4cbf6f257a82e22ea49462df72.tar.gz emacs-771fc75ee915ce4cbf6f257a82e22ea49462df72.zip | |
* 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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 13 | ||||
| -rw-r--r-- | lisp/calc/calc-math.el | 2 | ||||
| -rw-r--r-- | lisp/calc/calc-units.el | 51 |
3 files changed, 47 insertions, 19 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8d891b22fd0..be17986ddf8 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2011-03-02 Jay Belanger <jay.p.belanger@gmail.com> | ||
| 2 | |||
| 3 | * calc/calc-math.el (calcFunc-log10): Check for symbolic mode | ||
| 4 | when evaluating. | ||
| 5 | |||
| 6 | * calc/calc-units.el (math-conditional-apply, math-conditional-pow): | ||
| 7 | New function. | ||
| 8 | (math-logunits-add, math-logunits-mul, math-logunits-divide): | ||
| 9 | (math-logunits-quant, math-logunits-level): | ||
| 10 | Use `math-conditional-apply' and `math-conditional-pow' to evaluate | ||
| 11 | functions. | ||
| 12 | (math-logunits-level): Extract units from ratio. | ||
| 13 | |||
| 1 | 2011-03-01 Juanma Barranquero <lekktu@gmail.com> | 14 | 2011-03-01 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 15 | ||
| 3 | * emacs-lisp/cl-macs.el (lexical-let*): Fix argument name in docstring. | 16 | * emacs-lisp/cl-macs.el (lexical-let*): Fix argument name in docstring. |
diff --git a/lisp/calc/calc-math.el b/lisp/calc/calc-math.el index 92af9263b28..076dab31fd9 100644 --- a/lisp/calc/calc-math.el +++ b/lisp/calc/calc-math.el | |||
| @@ -1574,7 +1574,7 @@ If this can't be done, return NIL." | |||
| 1574 | (if calc-infinite-mode | 1574 | (if calc-infinite-mode |
| 1575 | '(neg (var inf var-inf)) | 1575 | '(neg (var inf var-inf)) |
| 1576 | (math-reject-arg x "*Logarithm of zero"))) | 1576 | (math-reject-arg x "*Logarithm of zero"))) |
| 1577 | ;;(calc-symbolic-mode (signal 'inexact-result nil)) | 1577 | (calc-symbolic-mode (signal 'inexact-result nil)) |
| 1578 | ((Math-numberp x) | 1578 | ((Math-numberp x) |
| 1579 | (math-with-extra-prec 2 | 1579 | (math-with-extra-prec 2 |
| 1580 | (let ((xf (math-float x))) | 1580 | (let ((xf (math-float x))) |
diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el index 569d5d3dc35..e6a6fb01132 100644 --- a/lisp/calc/calc-units.el +++ b/lisp/calc/calc-units.el | |||
| @@ -1559,6 +1559,20 @@ If EXPR is nil, return nil." | |||
| 1559 | (defvar math-logunits '((var dB var-dB) | 1559 | (defvar math-logunits '((var dB var-dB) |
| 1560 | (var Np var-Np))) | 1560 | (var Np var-Np))) |
| 1561 | 1561 | ||
| 1562 | (defun math-conditional-apply (fn &rest args) | ||
| 1563 | "Evaluate f(args) unless in symbolic mode. | ||
| 1564 | In symbolic mode, return the list (fn args)." | ||
| 1565 | (if calc-symbolic-mode | ||
| 1566 | (cons fn args) | ||
| 1567 | (apply fn args))) | ||
| 1568 | |||
| 1569 | (defun math-conditional-pow (a b) | ||
| 1570 | "Evaluate a^b unless in symbolic mode. | ||
| 1571 | In symbolic mode, return the list (^ a b)." | ||
| 1572 | (if calc-symbolic-mode | ||
| 1573 | (list '^ a b) | ||
| 1574 | (math-pow a b))) | ||
| 1575 | |||
| 1562 | (defun math-extract-logunits (expr) | 1576 | (defun math-extract-logunits (expr) |
| 1563 | (if (memq (car-safe expr) '(* /)) | 1577 | (if (memq (car-safe expr) '(* /)) |
| 1564 | (cons (car expr) | 1578 | (cons (car expr) |
| @@ -1585,24 +1599,24 @@ If EXPR is nil, return nil." | |||
| 1585 | (if (equal aunit '(var dB var-dB)) | 1599 | (if (equal aunit '(var dB var-dB)) |
| 1586 | (let ((coef (if power 10 20))) | 1600 | (let ((coef (if power 10 20))) |
| 1587 | (math-mul coef | 1601 | (math-mul coef |
| 1588 | (calcFunc-log10 | 1602 | (math-conditional-apply 'calcFunc-log10 |
| 1589 | (if neg | 1603 | (if neg |
| 1590 | (math-sub | 1604 | (math-sub |
| 1591 | (math-pow 10 (math-div acoeff coef)) | 1605 | (math-conditional-pow 10 (math-div acoeff coef)) |
| 1592 | (math-pow 10 (math-div bcoeff coef))) | 1606 | (math-conditional-pow 10 (math-div bcoeff coef))) |
| 1593 | (math-add | 1607 | (math-add |
| 1594 | (math-pow 10 (math-div acoeff coef)) | 1608 | (math-conditional-pow 10 (math-div acoeff coef)) |
| 1595 | (math-pow 10 (math-div bcoeff coef))))))) | 1609 | (math-conditional-pow 10 (math-div bcoeff coef))))))) |
| 1596 | (let ((coef (if power 2 1))) | 1610 | (let ((coef (if power 2 1))) |
| 1597 | (math-div | 1611 | (math-div |
| 1598 | (calcFunc-ln | 1612 | (math-conditional-apply 'calcFunc-ln |
| 1599 | (if neg | 1613 | (if neg |
| 1600 | (math-sub | 1614 | (math-sub |
| 1601 | (calcFunc-exp (math-mul coef acoeff)) | 1615 | (math-conditional-apply 'calcFunc-exp (math-mul coef acoeff)) |
| 1602 | (calcFunc-exp (math-mul coef bcoeff))) | 1616 | (math-conditional-apply 'calcFunc-exp (math-mul coef bcoeff))) |
| 1603 | (math-add | 1617 | (math-add |
| 1604 | (calcFunc-exp (math-mul coef acoeff)) | 1618 | (math-conditional-apply 'calcFunc-exp (math-mul coef acoeff)) |
| 1605 | (calcFunc-exp (math-mul coef bcoeff))))) | 1619 | (math-conditional-apply 'calcFunc-exp (math-mul coef bcoeff))))) |
| 1606 | coef))) | 1620 | coef))) |
| 1607 | units))))))) | 1621 | units))))))) |
| 1608 | 1622 | ||
| @@ -1666,14 +1680,14 @@ If EXPR is nil, return nil." | |||
| 1666 | (math-add | 1680 | (math-add |
| 1667 | coef | 1681 | coef |
| 1668 | (math-mul (if power 10 20) | 1682 | (math-mul (if power 10 20) |
| 1669 | (calcFunc-log10 number))) | 1683 | (math-conditional-apply 'calcFunc-log10 number))) |
| 1670 | units))) | 1684 | units))) |
| 1671 | (t | 1685 | (t |
| 1672 | (math-simplify | 1686 | (math-simplify |
| 1673 | (math-mul | 1687 | (math-mul |
| 1674 | (math-add | 1688 | (math-add |
| 1675 | coef | 1689 | coef |
| 1676 | (math-div (calcFunc-ln number) (if power 2 1))) | 1690 | (math-div (math-conditional-apply 'calcFunc-ln number) (if power 2 1))) |
| 1677 | units)))) | 1691 | units)))) |
| 1678 | (calc-record-why "*Improper units" nil)))) | 1692 | (calc-record-why "*Improper units" nil)))) |
| 1679 | 1693 | ||
| @@ -1692,14 +1706,14 @@ If EXPR is nil, return nil." | |||
| 1692 | (math-sub | 1706 | (math-sub |
| 1693 | coef | 1707 | coef |
| 1694 | (math-mul (if power 10 20) | 1708 | (math-mul (if power 10 20) |
| 1695 | (calcFunc-log10 b))) | 1709 | (math-conditional-apply 'calcFunc-log10 b))) |
| 1696 | units))) | 1710 | units))) |
| 1697 | (t | 1711 | (t |
| 1698 | (math-simplify | 1712 | (math-simplify |
| 1699 | (math-mul | 1713 | (math-mul |
| 1700 | (math-sub | 1714 | (math-sub |
| 1701 | coef | 1715 | coef |
| 1702 | (math-div (calcFunc-ln b) (if power 2 1))) | 1716 | (math-div (math-conditional-apply 'calcFunc-ln b) (if power 2 1))) |
| 1703 | units))))))))) | 1717 | units))))))))) |
| 1704 | 1718 | ||
| 1705 | (defun calcFunc-lufieldtimes (a b) | 1719 | (defun calcFunc-lufieldtimes (a b) |
| @@ -1747,14 +1761,14 @@ If EXPR is nil, return nil." | |||
| 1747 | (if (equal lunit '(var dB var-dB)) | 1761 | (if (equal lunit '(var dB var-dB)) |
| 1748 | (math-mul | 1762 | (math-mul |
| 1749 | ref | 1763 | ref |
| 1750 | (math-pow | 1764 | (math-conditional-pow |
| 1751 | 10 | 1765 | 10 |
| 1752 | (math-div | 1766 | (math-div |
| 1753 | coeff | 1767 | coeff |
| 1754 | (if power 10 20)))) | 1768 | (if power 10 20)))) |
| 1755 | (math-mul | 1769 | (math-mul |
| 1756 | ref | 1770 | ref |
| 1757 | (calcFunc-exp | 1771 | (math-conditional-apply 'calcFunc-exp |
| 1758 | (if power | 1772 | (if power |
| 1759 | (math-mul 2 coeff) | 1773 | (math-mul 2 coeff) |
| 1760 | coeff)))) | 1774 | coeff)))) |
| @@ -1787,15 +1801,16 @@ If EXPR is nil, return nil." | |||
| 1787 | (defun math-logunits-level (val ref db power) | 1801 | (defun math-logunits-level (val ref db power) |
| 1788 | "Compute the value of VAL in decibels or nepers." | 1802 | "Compute the value of VAL in decibels or nepers." |
| 1789 | (let* ((ratio (math-simplify-units (math-div val ref))) | 1803 | (let* ((ratio (math-simplify-units (math-div val ref))) |
| 1804 | (ratiou (math-simplify-units (math-remove-units ratio))) | ||
| 1790 | (units (math-simplify (math-extract-units ratio)))) | 1805 | (units (math-simplify (math-extract-units ratio)))) |
| 1791 | (math-mul | 1806 | (math-mul |
| 1792 | (if db | 1807 | (if db |
| 1793 | (math-mul | 1808 | (math-mul |
| 1794 | (math-mul (if power 10 20) | 1809 | (math-mul (if power 10 20) |
| 1795 | (calcFunc-log10 ratio)) | 1810 | (math-conditional-apply 'calcFunc-log10 ratiou)) |
| 1796 | '(var dB var-dB)) | 1811 | '(var dB var-dB)) |
| 1797 | (math-mul | 1812 | (math-mul |
| 1798 | (math-div (calcFunc-ln ratio) (if power 2 1)) | 1813 | (math-div (math-conditional-apply 'calcFunc-ln ratiou) (if power 2 1)) |
| 1799 | '(var Np var-Np))) | 1814 | '(var Np var-Np))) |
| 1800 | units))) | 1815 | units))) |
| 1801 | 1816 | ||