comparison lisp/calc/calc-ext.el @ 90159:08185296b491

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-44 Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 272-288) - src/xdisp.c (dump_glyph_row): Don't display overlay_arrow_p field. - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 67) - Update from CVS
author Miles Bader <miles@gnu.org>
date Thu, 05 May 2005 00:04:55 +0000
parents 7e3f621f1dd4 b00f3dbbb0b5
children 62afea0771d8
comparison
equal deleted inserted replaced
90158:bf4846baba9a 90159:08185296b491
1 ;;; calc-ext.el --- various extension functions for Calc 1 ;;; calc-ext.el --- various extension functions for Calc
2 2
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2004 Free Software Foundation, Inc. 3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
4 4
5 ;; Author: David Gillespie <daveg@synaptics.com> 5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Jay Belanger <belanger@truman.edu> 6 ;; Maintainer: Jay Belanger <belanger@truman.edu>
7 7
8 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
2813 (Math-lessp seconds 60) 2813 (Math-lessp seconds 60)
2814 (list 'hms 0 0 seconds)))) 2814 (list 'hms 0 0 seconds))))
2815 2815
2816 ;; Integer+fraction with explicit radix 2816 ;; Integer+fraction with explicit radix
2817 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]\\)$" s) 2817 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]\\)$" s)
2818 (let ((radix (string-to-int (math-match-substring s 1))) 2818 (let ((radix (string-to-number (math-match-substring s 1)))
2819 (int (math-match-substring s 3)) 2819 (int (math-match-substring s 3))
2820 (num (math-match-substring s 4)) 2820 (num (math-match-substring s 4))
2821 (den (math-match-substring s 5))) 2821 (den (math-match-substring s 5)))
2822 (let ((int (if (> (length int) 0) (math-read-radix int radix) 0)) 2822 (let ((int (if (> (length int) 0) (math-read-radix int radix) 0))
2823 (num (if (> (length num) 0) (math-read-radix num radix) 1)) 2823 (num (if (> (length num) 0) (math-read-radix num radix) 1))
2827 (math-add num (math-mul int den)) 2827 (math-add num (math-mul int den))
2828 den))))) 2828 den)))))
2829 2829
2830 ;; Fraction with explicit radix 2830 ;; Fraction with explicit radix
2831 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]*\\)$" s) 2831 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)[:/]\\([0-9a-zA-Z]*\\)$" s)
2832 (let ((radix (string-to-int (math-match-substring s 1))) 2832 (let ((radix (string-to-number (math-match-substring s 1)))
2833 (num (math-match-substring s 3)) 2833 (num (math-match-substring s 3))
2834 (den (math-match-substring s 4))) 2834 (den (math-match-substring s 4)))
2835 (let ((num (if (> (length num) 0) (math-read-radix num radix) 1)) 2835 (let ((num (if (> (length num) 0) (math-read-radix num radix) 1))
2836 (den (if (> (length den) 0) (math-read-radix den radix) 1))) 2836 (den (if (> (length den) 0) (math-read-radix den radix) 1)))
2837 (and num den (not (math-zerop den)) (list 'frac num den))))) 2837 (and num den (not (math-zerop den)) (list 'frac num den)))))
2838 2838
2839 ;; Float with explicit radix and exponent 2839 ;; Float with explicit radix and exponent
2840 ((or (string-match "^0*\\(\\([2-9]\\|1[0-4]\\)\\(#\\|\\^\\^\\)[0-9a-dA-D.]+\\)[eE]\\([-+]?[0-9]+\\)$" s) 2840 ((or (string-match "^0*\\(\\([2-9]\\|1[0-4]\\)\\(#\\|\\^\\^\\)[0-9a-dA-D.]+\\)[eE]\\([-+]?[0-9]+\\)$" s)
2841 (string-match "^\\(\\([0-9]+\\)\\(#\\|\\^\\^\\)[0-9a-zA-Z.]+\\) *\\* *\\2\\.? *\\^ *\\([-+]?[0-9]+\\)$" s)) 2841 (string-match "^\\(\\([0-9]+\\)\\(#\\|\\^\\^\\)[0-9a-zA-Z.]+\\) *\\* *\\2\\.? *\\^ *\\([-+]?[0-9]+\\)$" s))
2842 (let ((radix (string-to-int (math-match-substring s 2))) 2842 (let ((radix (string-to-number (math-match-substring s 2)))
2843 (mant (math-match-substring s 1)) 2843 (mant (math-match-substring s 1))
2844 (exp (math-match-substring s 4))) 2844 (exp (math-match-substring s 4)))
2845 (let ((mant (math-read-number mant)) 2845 (let ((mant (math-read-number mant))
2846 (exp (math-read-number exp))) 2846 (exp (math-read-number exp)))
2847 (and mant exp 2847 (and mant exp
2848 (math-mul mant (math-pow (math-float radix) exp)))))) 2848 (math-mul mant (math-pow (math-float radix) exp))))))
2849 2849
2850 ;; Float with explicit radix, no exponent 2850 ;; Float with explicit radix, no exponent
2851 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)\\.\\([0-9a-zA-Z]*\\)$" s) 2851 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]*\\)\\.\\([0-9a-zA-Z]*\\)$" s)
2852 (let ((radix (string-to-int (math-match-substring s 1))) 2852 (let ((radix (string-to-number (math-match-substring s 1)))
2853 (int (math-match-substring s 3)) 2853 (int (math-match-substring s 3))
2854 (fracs (math-match-substring s 4))) 2854 (fracs (math-match-substring s 4)))
2855 (let ((int (if (> (length int) 0) (math-read-radix int radix) 0)) 2855 (let ((int (if (> (length int) 0) (math-read-radix int radix) 0))
2856 (frac (if (> (length fracs) 0) (math-read-radix fracs radix) 0)) 2856 (frac (if (> (length fracs) 0) (math-read-radix fracs radix) 0))
2857 (calc-prefer-frac nil)) 2857 (calc-prefer-frac nil))
2859 (math-add int (math-div frac (math-pow radix (length fracs)))))))) 2859 (math-add int (math-div frac (math-pow radix (length fracs))))))))
2860 2860
2861 ;; Integer with explicit radix 2861 ;; Integer with explicit radix
2862 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]+\\)$" s) 2862 ((string-match "^\\([0-9]+\\)\\(#\\|\\^\\^\\)\\([0-9a-zA-Z]+\\)$" s)
2863 (math-read-radix (math-match-substring s 3) 2863 (math-read-radix (math-match-substring s 3)
2864 (string-to-int (math-match-substring s 1)))) 2864 (string-to-number (math-match-substring s 1))))
2865 2865
2866 ;; C language hexadecimal notation 2866 ;; C language hexadecimal notation
2867 ((and (eq calc-language 'c) 2867 ((and (eq calc-language 'c)
2868 (string-match "^0[xX]\\([0-9a-fA-F]+\\)$" s)) 2868 (string-match "^0[xX]\\([0-9a-fA-F]+\\)$" s))
2869 (let ((digs (math-match-substring s 1))) 2869 (let ((digs (math-match-substring s 1)))