bytevector-u16-set!(3scm)
β¨ NAME β¨
Hey bestie π welcome to the bytevector-u16-set!(3scm) page from the Scheme Programmer's Manual. This is the whole iconic fam β 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!, and bytevector-ieee-single-native-set! β and they all do one thing: store a number in a bytevector. Slay.
π 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 π
Okay so what these do is store the integer n β or the real x β into bytevector, starting from the index k. The actual bytes get made according to a data type and an endianness. The data type is one of these cuties:
s16β signed 16-bit integers32β signed 32-bit integers64β signed 64-bit integeru16β unsigned 16-bit integeru32β unsigned 32-bit integeru64β unsigned 64-bit integerieee-doubleβ IEEE-754 double-precision float (binary64)ieee-singleβ IEEE-754 single-precision float (binary32)
The signed variants use the two's complement representation, periodt.
The endianness is normally one of these two 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 they also 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 it's either two, four or eight (corresponding to 16, 32 or 64 bits). The bytevector must be at least k+m bytes in length, no cap.
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.
And listen β unlike the equivalent operation in e.g. C, the index is not multiplied by the element size. Iykyk. π«Ά
π RETURN VALUES π
Returns unspecified values. Yes bestie, unspecified values. That's the whole vibe.
πΈ 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).
π That's the tea, bestie: bytevector-u16-set!(3scm), dated 2021-02-28. Bye and slay! π
π«Ά
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2021 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms