fixnum-width(3scm)

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

πŸ’… fixnum-width β€” the Scheme Programmer's Manual (3scm) πŸŽ€

okay so bestie, welcome to fixnum-width(3scm) ✨ this one lives in the Scheme Programmer's Manual and it's literally all about finding out how big your fixnums can get. short page, iconic energy, let's go πŸ’–


🌸 NAME 🌸

fixnum-width, least-fixnum, greatest-fixnum β€” query the fixnum range πŸ”πŸ‘‘

πŸ“š LIBRARY πŸ“š

(import (rnrs))                     ;R6RS
(import (rnrs arithmetic fixnums))  ;R6RS

✨ SYNOPSIS ✨

(fixnum-width)
(least-fixnum)
(greatest-fixnum)

πŸ’– DESCRIPTION πŸ’–

So the fixnum range is defined as the closed interval [βˆ’2^(wβˆ’1), 2^(wβˆ’1)βˆ’1] where w is an implementation-defined integer with w β‰₯ 24. That's the vibe πŸ’«

  • fixnum-width returns the implementation's w. yep, just hands you the number 🫢
  • least-fixnum returns βˆ’2^(wβˆ’1). the smallest guy 😭
  • greatest-fixnum returns 2^(wβˆ’1)βˆ’1. the biggest guy πŸ‘‘

The fixnum range is super important to keep in mind when you're using the fixnum procedures, because those procedures require that their arguments and results are fixnums. if a result can't be represented as a fixnum, they raise an exception. no cap, they will absolutely throw πŸ’€

🧚 IMPLEMENTATION NOTES 🧚

The fixnum width depends very much on implementation details and the machine. here are some known fixnum widths, bestie πŸŽ€

Chez Scheme

The fixnum width is 61 or 30. If the machine's register width is m then the fixnum width is m - log2(m/8).

GNU Guile

The fixnum width is 62 or 30. This is the machine's register width minus two.

IronScheme

The fixnum width is 32.

Loko Scheme

The fixnum width is 61.

🌈 RETURN VALUES 🌈

These procedures each return a single value; a fixnum as per the description above. one value, one vibe, periodt πŸ’…

πŸ“ EXAMPLES πŸ“

; The results are different for different implementations.
(fixnum-width)     =>  61
(least-fixnum)     => -1152921504606846976
(greatest-fixnum)  =>  1152921504606846975

πŸ¦‹ APPLICATION USAGE πŸ¦‹

This procedure is sometimes used in libraries that provide optimized variants of code for implementations where the fixnum width is large enough. and like, if the fixnum width is 32 (or greater) then fixnums can represent all signed 32-bit integers. slay πŸ”₯

⭐ COMPATIBILITY ⭐

This procedure is only present in R6RS. an alternative to (fixnum-width) is (+ 1 (bitwise-length (greatest-fixnum))). But normally there's no need to use fixnum procedures if they aren't available β€” generic arithmetic can be used instead and will give the same results 🫢

πŸ’€ ERRORS πŸ’€

This procedure can raise exceptions with the following condition types:

  • &assertion (R6RS) β€” the wrong number of arguments was passed. (not you calling it wrong πŸ™ˆ)

πŸ‘‘ SEE ALSO πŸ‘‘

bitwise-length(3scm)

πŸŽ€ STANDARDS πŸŽ€

R6RS

🧡 HISTORY 🧡

These procedures are new to the fixnum library in R6RS. Implementations have always had some kind of fixnum type but it was normally not seen by the user. iykyk 🌸

πŸ’œ 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/.


and that's the whole page, bestie!! 🌈 shoutout to the 2023-01-06 date and the fixnum-width(3scm) source/version, mwah πŸ’‹ go forth and know your fixnum range πŸ’–βœ¨

πŸ“¦ where this page comes from