annotate lisp/tl/tl-num.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents
children 4b173ad71786
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2 ;;; $Id: tl-num.el,v 1.1.1.1 1996/12/18 03:55:31 steve Exp $
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
3 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
4 ;;; by MORIOKA Tomohiko <morioka@jaist.ac.jp>, 1993/10/4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
5 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
6
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
7 (require 'emu)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8 (require 'tl-seq)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11 ;;; @ n base
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
12 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14 (defun char-to-int (chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15 "Convert n base character CHR to integer (n <= 36). [tl-num]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16 (cond ((and (<= ?0 chr)(<= chr ?9)) (- chr ?0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ((and (<= ?A chr)(<= chr ?Z)) (+ (- chr ?A) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ((and (<= ?a chr)(<= chr ?z)) (+ (- chr ?a) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21 (defun int-to-char (n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 "Convert integer N to n base character (n <= 36). [tl-num]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 (if (< n 10)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24 (+ ?0 n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25 (+ ?A (- n 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28 (defun base-seq-to-int (base seq)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 "Convert n base number sequence SEQ to number. [tl-num]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30 (foldl (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31 (lambda (n m)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 (+ (* n base) m)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34 0 seq))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
36 (defun base-char-seq-to-int (base seq)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 "Convert n base char sequence SEQ to number. [tl-num]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
38 (foldl (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
39 (lambda (n chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40 (+ (* n base)(char-to-int chr))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42 0 seq))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
45 ;;; @ Hex
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48 (defun hex-char-to-number (chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49 "Convert hex character CHR to number. [tl-num]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50 (cond ((and (<= ?0 chr)(<= chr ?9)) (- chr ?0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 ((and (<= ?A chr)(<= chr ?F)) (+ (- chr ?A) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52 ((and (<= ?a chr)(<= chr ?f)) (+ (- chr ?a) 10))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 (defalias 'number-to-hex-char 'int-to-char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57 (defun hex-seq-to-int (seq)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58 "Convert hex number sequence SEQ to integer. [tl-num]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59 (base-seq-to-int 16 seq)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 (defun hex-char-seq-to-int (seq)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63 "Convert hex char sequence SEQ to integer. [tl-num]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 (base-char-seq-to-int 16 seq)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68 ;;; @ end
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 (provide 'tl-num)