commit f14af80b8986d7171e2fc6333a973b4c93c7665b
parent 7461c6755c5c15083be5aa902caa09bd0019ee74
Author: Tomas Hlavaty <tom@logand.com>
Date: Sat, 25 Apr 2015 19:36:21 +0200
use integer-length instead of log
allegro doesn't do exact log of bignums: integer too big for double in
log
also integer-length seems more appropriate
Diffstat:
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/der.lisp b/der.lisp
@@ -172,7 +172,7 @@
(assert (<= 0 n))
(if (< n #x80)
(rw:write-u8 writer n)
- (let ((nn (ceiling (log n 256))))
+ (let ((nn (ceiling (integer-length n) 8)))
(assert (<= 1 nn #x7f))
(rw:write-u8 writer (logior #x80 nn))
(loop
@@ -204,17 +204,8 @@
((zerop x)
(rw:write-u8 writer 1)
(rw:write-u8 writer 0))
- ((plusp x)
- (let* ((nbits (floor (+ 2 (log x 2))))
- (nbytes (ceiling nbits 8)))
- (len nbytes)
- (loop
- for i from (1- nbytes) downto 0
- do (rw:write-u8 writer (ldb (byte 8 (* 8 i)) x)))))
- (t ;; minusp
- (let* ((y (- x))
- (nbits (ceiling (+ 1 (log y 2))))
- (nbytes (ceiling nbits 8)))
+ (t
+ (let ((nbytes (ceiling (1+ (integer-length x)) 8)))
(len nbytes)
(loop
for i from (1- nbytes) downto 0
@@ -235,7 +226,7 @@
(rw:write-u8 writer 3)
(let* ((m (cadr x))
(x (ash (caddr x) m))
- (nbytes (ceiling (log x 256))))
+ (nbytes (ceiling (integer-length x) 8)))
(len (+ 1 nbytes))
(rw:write-u8 writer m)
(loop
@@ -334,7 +325,6 @@
(49 16 48 14 2 1 #x80 6 9 #x2b 6 1 4 1 #x82 #x37 #x15 #x14))
((bit-string 7 #x12345)
(3 4 7 145 162 128))
- #-allegro ;; TODO integer too big for double in log
((bit-string 0 2698675166254423367516254728464483749335066557673396396108386839514779489334034500324580997831747386071008453389756292324108345979589057920899409611221513386337727594567671688384339497590058060942411175326729608798043193698773547875145474433044091370658538092792546412868245105307028798977746453087673869761039285801616342559358044930049)
(3 129 141 0
48 129 137 2 129 129 0 190 108 252 172 88 61 44 244 2 196 54 234 121 210
@@ -344,7 +334,6 @@
42 90 233 119 5 180 145 138 55 114 178 56 28 117 191 40 208 75 167 181
49 36 201 14 178 137 153 55 95 175 220 201 180 9 124 38 129 234 159 152
83 53 138 75 187 159 227 220 197 148 150 3 101 147 2 3 1 0 1))
- #-allegro ;; TODO integer too big for double in log
((bit-string 0 118034060124092381042289152588939068226888691459037221227696280629223206095830260576779540892200452501272518674360944045140270719338674600852168851119591300542021466662967353378826595297215969104790405581663753704791058639429297119582166792869070820194273847407288579294634063908956456813605370210920536000302)
(3 129 129 0
168 22 9 103 226 192 63 113 163 84 253 199 177 202 0 36 253 22 43 188