bytevector-u16-set!(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

✨ 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 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, 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