R6RS:翻訳:Standard Libraries:2.4 Operations on integers of arbitrary size

R6RS:翻訳:Standard Libraries:2.4 Operations on integers of arbitrary size

2.4 任意の大きさの整数に対する操作

[procedure] (bytevector-uint-ref bytevector k endianness size)

[procedure] (bytevector-sint-ref bytevector k endianness size)

[procedure] (bytevector-uint-set! bytevector k n endianness size)

[procedure] (bytevector-sint-set! bytevector k n endianness size)

size は正確な正の整数オブジェクトであり、 k, ..., k + size - 1 は bytevector の有効な添え字でなければならない。

bytevector-uint-ref 手続きは、大きさ size で、 endianness で指定される添え字 k, ..., k + 1 番目の正確な整数オブジェクトに対応する符号なし表現を返す。

bytevector-uint-ref 手続きは、大きさ size で、 endianness で指定される添え字 k, ..., k + 1 番目の正確な整数オブジェクトに対応する 2 の補数表現を返す。

bytevector-uint-set! では n は正確な整数で、 {0, ..., 256^{size}} の範囲になければならない。

bytevector-uint-set! は bytevectork, ..., k + size - 1 番目に endianess で指定された、大きさ size の符号なし表現を格納する。

bytevector-sint-set! では、 n は正確な整数で {-256^{size}/2, ..., 256^{size}/2 - 1} の範囲になければならない。 bytevector-sint-set! は bytevectork, ..., k + size - 1 番目に endianness で指定された、大きさ size の 2 の補数表現を格納する。

...-set! 手続きは未規定値を返す。

(define b (make-bytevector 16 -127))

(bytevector-uint-set! b 0 (- (expt 2 128) 3)
                     (endianness little) 16)

(bytevector-uint-ref b 0 (endianness little) 16)
                ⇒
    #xfffffffffffffffffffffffffffffffd

(bytevector-sint-ref b 0 (endianness little) 16)
                ⇒ -3

(bytevector->u8-list b)
                ⇒ (253 255 255 255 255 255 255 255
               255 255 255 255 255 255 255 255)

(bytevector-uint-set! b 0 (- (expt 2 128) 3)
                 (endianness big) 16)
(bytevector-uint-ref b 0 (endianness big) 16) 
                ⇒
    #xfffffffffffffffffffffffffffffffd

(bytevector-sint-ref b 0 (endianness big) 16) 
                ⇒ -3

(bytevector->u8-list b) 
                ⇒ (255 255 255 255 255 255 255 255
               255 255 255 255 255 255 255 253))

[procedure] (bytevector->uint-list bytevector endianness size)

[procedure] (bytevector->sint-list bytevector endianness size)

[procedure] (uint-list->bytevector list endianness size)

[procedure] (sint-list->bytevector list endianness size)

size は正確な正の整数オブジェクトであり、 uint-list->bytevector では list は {0, ..., 256^{size} - 1} の範囲の正確な整数のリストでなければならない。 sint-list->bytevector では list は {-256^{size}/2, ..., 256^{size}/2 - 1} の範囲の正確な整数オブジェクトのリストでなければならない。 bytevector の長さは size で割り切れなければならない。

これらの手続きは bytevector->u8-list と u8-list->bytevector がするのと同じ方法で 1 バイトの表現を sizeendianness に従って bytevector オブジェクトを、整数オブジェクトのリストとその連続した表現を相互変換する。

(let ((b (u8-list->bytevector ’(1 2 3 255 1 2 1 2))))
  (bytevector->sint-list b (endianness little) 2)) 
                ⇒ (513 -253 513 513)

(let ((b (u8-list->bytevector ’(1 2 3 255 1 2 1 2))))
  (bytevector->uint-list b (endianness little) 2)) 
                ⇒ (513 65283 513 513)

Last modified : 2009/02/10 04:34:18 UTC