(require 'byte-number)
The multi-byte sequences produced and used by numeric conversion
routines are always big-endian. Endianness can be changed during
reading and writing bytes using read-bytes and
write-bytes See read-bytes.
The sign of the length argument to bytes/integer conversion procedures determines the signedness of the number.
Converts the first
(absn)bytes of big-endian bytes array to an integer. If n is negative then the integer coded by the bytes are treated as two's-complement (can be negative).(bytes->integer (bytes 0 0 0 15) -4) ⇒ 15 (bytes->integer (bytes 0 0 0 15) 4) ⇒ 15 (bytes->integer (bytes 255 255 255 255) -4) ⇒ -1 (bytes->integer (bytes 255 255 255 255) 4) ⇒ 4294967295 (bytes->integer (bytes 128 0 0 0) -4) ⇒ -2147483648 (bytes->integer (bytes 128 0 0 0) 4) ⇒ 2147483648
Converts the integer n to a byte-array of
(absn)bytes. If n and len are both negative, then the bytes in the returned array are coded two's-complement.(bytes->list (integer->bytes 15 -4)) ⇒ (0 0 0 15) (bytes->list (integer->bytes 15 4)) ⇒ (0 0 0 15) (bytes->list (integer->bytes -1 -4)) ⇒ (255 255 255 255) (bytes->list (integer->bytes 4294967295 4)) ⇒ (255 255 255 255) (bytes->list (integer->bytes -2147483648 -4)) ⇒ (128 0 0 0) (bytes->list (integer->bytes 2147483648 4)) ⇒ (128 0 0 0)
bytes must be a 4-element byte-array.
bytes->ieee-floatcalculates and returns the value of bytes interpreted as a big-endian IEEE 4-byte (32-bit) number.
(bytes->ieee-float (bytes 0 0 0 0)) ⇒ 0.0
(bytes->ieee-float (bytes #x80 0 0 0)) ⇒ -0.0
(bytes->ieee-float (bytes #x40 0 0 0)) ⇒ 2.0
(bytes->ieee-float (bytes #x40 #xd0 0 0)) ⇒ 6.5
(bytes->ieee-float (bytes #xc0 #xd0 0 0)) ⇒ -6.5
(bytes->ieee-float (bytes 0 #x80 0 0)) ⇒ 11.754943508222875e-39
(bytes->ieee-float (bytes 0 #x40 0 0)) ⇒ 5.877471754111437e-39
(bytes->ieee-float (bytes 0 0 0 1)) ⇒ 1.401298464324817e-45
(bytes->ieee-float (bytes #xff #x80 0 0)) ⇒ -inf.0
(bytes->ieee-float (bytes #x7f #x80 0 0)) ⇒ +inf.0
(bytes->ieee-float (bytes #x7f #x80 0 1)) ⇒ 0/0
(bytes->ieee-float (bytes #x7f #xc0 0 0)) ⇒ 0/0
bytes must be a 8-element byte-array.
bytes->ieee-doublecalculates and returns the value of bytes interpreted as a big-endian IEEE 8-byte (64-bit) number.
(bytes->ieee-double (bytes 0 0 0 0 0 0 0 0)) ⇒ 0.0
(bytes->ieee-double (bytes #x80 0 0 0 0 0 0 0)) ⇒ -0.0
(bytes->ieee-double (bytes #x40 0 0 0 0 0 0 0)) ⇒ 2.0
(bytes->ieee-double (bytes #x40 #x1A 0 0 0 0 0 0)) ⇒ 6.5
(bytes->ieee-double (bytes #xC0 #x1A 0 0 0 0 0 0)) ⇒ -6.5
(bytes->ieee-double (bytes 0 8 0 0 0 0 0 0)) ⇒ 11.125369292536006e-309
(bytes->ieee-double (bytes 0 4 0 0 0 0 0 0)) ⇒ 5.562684646268003e-309
(bytes->ieee-double (bytes 0 0 0 0 0 0 0 1)) ⇒ 4.0e-324
(bytes->ieee-double (bytes #xFF #xF0 0 0 0 0 0 0)) ⇒ -inf.0
(bytes->ieee-double (bytes #x7F #xF0 0 0 0 0 0 0)) ⇒ +inf.0
(bytes->ieee-double (bytes #x7F #xF8 0 0 0 0 0 0)) ⇒ 0/0
Returns a 4-element byte-array encoding the IEEE single-precision floating-point of x.
(bytes->list (ieee-float->bytes 0.0)) ⇒ (0 0 0 0)
(bytes->list (ieee-float->bytes -0.0)) ⇒ (128 0 0 0)
(bytes->list (ieee-float->bytes 2.0)) ⇒ (64 0 0 0)
(bytes->list (ieee-float->bytes 6.5)) ⇒ (64 208 0 0)
(bytes->list (ieee-float->bytes -6.5)) ⇒ (192 208 0 0)
(bytes->list (ieee-float->bytes 11.754943508222875e-39)) ⇒ ( 0 128 0 0)
(bytes->list (ieee-float->bytes 5.877471754111438e-39)) ⇒ ( 0 64 0 0)
(bytes->list (ieee-float->bytes 1.401298464324817e-45)) ⇒ ( 0 0 0 1)
(bytes->list (ieee-float->bytes -inf.0)) ⇒ (255 128 0 0)
(bytes->list (ieee-float->bytes +inf.0)) ⇒ (127 128 0 0)
(bytes->list (ieee-float->bytes 0/0)) ⇒ (127 192 0 0)
Returns a 8-element byte-array encoding the IEEE double-precision floating-point of x.
(bytes->list (ieee-double->bytes 0.0)) ⇒ (0 0 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes -0.0)) ⇒ (128 0 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 2.0)) ⇒ (64 0 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 6.5)) ⇒ (64 26 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes -6.5)) ⇒ (192 26 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 11.125369292536006e-309))
⇒ ( 0 8 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 5.562684646268003e-309))
⇒ ( 0 4 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 4.0e-324))
⇒ ( 0 0 0 0 0 0 0 1)
(bytes->list (ieee-double->bytes -inf.0)) ⇒ (255 240 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes +inf.0)) ⇒ (127 240 0 0 0 0 0 0)
(bytes->list (ieee-double->bytes 0/0)) ⇒ (127 248 0 0 0 0 0 0)
The string<? ordering of big-endian byte-array
representations of fixed and IEEE floating-point numbers agrees with
the numerical ordering only when those numbers are non-negative.
Straighforward modification of these formats can extend the byte-collating order to work for their entire ranges. This agreement enables the full range of numbers as keys in indexed-sequential-access-method databases.
Modifies sign bit of byte-vector so that
string<?ordering of two's-complement byte-vectors matches numerical order.integer-byte-collate!returns byte-vector and is its own functional inverse.
Returns copy of byte-vector with sign bit modified so that
string<?ordering of two's-complement byte-vectors matches numerical order.integer-byte-collateis its own functional inverse.
Modifies byte-vector so that
string<?ordering of IEEE floating-point byte-vectors matches numerical order.ieee-byte-collate!returns byte-vector.
Given byte-vector modified by
ieee-byte-collate!, reverses the byte-vector modifications.