~williewillus/racket-rfc8949

e35d8c99279e7b8f4dfa5be6eaa634aeb7678ca4 — Vincent Lee 3 years ago 52da156
Implement bignums and enable the disabled tests
1 files changed, 7 insertions(+), 3 deletions(-)

M decode.rkt
M decode.rkt => decode.rkt +7 -3
@@ 187,7 187,11 @@
(define (deserialize-bignum _tag data)
  (unless (bytes? data)
    (error "Bignum payload must be bytes"))
  (integer-bytes->integer data #f #t))
  (for/fold ([acc 0])
            ([(chunk idx) (in-indexed data)])
    (define shift (* 8 (- (sub1 (bytes-length data))
                          idx)))
    (bitwise-ior acc (arithmetic-shift chunk shift))))

(define (deserialize-bigneg tag data)
  (- -1 (deserialize-bignum tag data)))


@@ 256,9 260,9 @@
    (check-eqv? (try "1a000f4240") 1000000)
    (check-eqv? (try "1b000000e8d4a51000") 1000000000000)
    (check-eqv? (try "1bffffffffffffffff") 18446744073709551615)
    ;TODO bignums (check-eqv? (try "c249010000000000000000") 18446744073709551616)
    (check-eqv? (try "c249010000000000000000") 18446744073709551616)
    (check-eqv? (try "3bffffffffffffffff") -18446744073709551616)
    ;TODO bignums (check-eqv? (try "c349010000000000000000") -18446744073709551617)
    (check-eqv? (try "c349010000000000000000") -18446744073709551617)
    (check-eqv? (try "20") -1)
    (check-eqv? (try "29") -10)
    (check-eqv? (try "3863") -100)