bytevector-s16-set!, bytevector-s32-set!, bytevector-s64-set!, bytevector-u16-set!, bytevector-u32-set!, bytevector-u64-set!, bytevector-ieee-double-set!, bytevector-ieee-single-set!, bytevector-s16-native-set!, bytevector-s32-native-set!, bytevector-s64-native-set!, bytevector-u16-native-set!, bytevector-u32-native-set!, bytevector-u64-native-set!, bytevector-ieee-double-native-set!, bytevector-ieee-single-native-set! - store a number in a bytevector

LIBRARY

(import (rnrs))                     ;R6RS
(import (rnrs bytevectors))         ;R6RS

SYNOPSIS

(bytevector-s16-set! bytevector k n endianness)
(bytevector-s32-set! bytevector k n endianness)
(bytevector-s64-set! bytevector k n endianness)

(bytevector-u16-set! bytevector k n endianness)
(bytevector-u32-set! bytevector k n endianness)
(bytevector-u64-set! bytevector k n endianness)

(bytevector-ieee-double-set! bytevector k x endianness)
(bytevector-ieee-single-set! bytevector k x endianness)

(bytevector-s16-native-set! bytevector k n)
(bytevector-s32-native-set! bytevector k n)
(bytevector-s64-native-set! bytevector k n)

(bytevector-u16-native-set! bytevector k n)
(bytevector-u32-native-set! bytevector k n)
(bytevector-u64-native-set! bytevector k n)

(bytevector-ieee-double-native-set! bytevector k x)
(bytevector-ieee-single-native-set! bytevector k x)

DESCRIPTION

Store the integer n or the real x in bytevector, starting from the index k. The byte representation is created according to a data type and endianness. The data type is one of the following:
s16
signed 16-bit integer
s32
signed 32-bit integer
s64
signed 64-bit integer
u16
unsigned 16-bit integer
u32
unsigned 32-bit integer
u64
unsigned 64-bit integer
ieee-double
IEEE-754 double-precision float (binary64)
ieee-single
IEEE-754 single-precision float (binary32)

The signed variants use the two's complement representation.

The endianness is normally one of the following symbols:

big
Big endian. The more significant bytes come before the less significant bytes.
little
Little endian. The less significant bytes come before the more significant bytes.

The -native variants use the machine's native endianness and furthermore impose an alignment requirement: the index k must be evenly divisible by the data type size (2, 4 or 8). Such an access is said to be aligned, as opposed to an unaligned access.

The number of bytes m used depends on the data type and is either two, four or eight (corresponding to 16, 32 or 64 bits). The bytevector must be at least k+m bytes in length.

The integer n must be in the range [0, (2^w)-1] for the unsigned operations and in the range [-(2^(w-1)), (2^(w-1))-1] for the signed operations, where w is the size of the data type in bits. For the floating point operations, x must be a real number object.

Unlike the equivalent operation in e.g. C, the index is not multiplied by the element size.

RETURN VALUES

Returns unspecified values.

EXAMPLES

(define b
  (u8-list->bytevector
    '(255 255 255 255 255 255 255 255
      255 255 255 255 255 255 255 253)))

(bytevector-u16-set! b 0 12345 (endianness little))
(bytevector-u16-ref b 0 (endianness little))
          => 12345

(bytevector-u16-native-set! b 0 12345)
(bytevector-u16-native-ref b 0)
          => 12345
(bytevector-u16-ref b 0 (endianness little))
          => unspecified

COMPATIBILITY

See the notes in bytevector-u16-ref(3scm).

ERRORS

This procedure can raise exceptions with the following condition types:
&assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
R7RS
The assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

SEE ALSO

bytevector-u8-set!(3scm)

STANDARDS

R6RS

AUTHORS

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.

BUGS

See the notes in bytevector-u16-ref(3scm).


Markup created by unroff 1.0sc,    March 04, 2023.