fixnums(7scm)
π fixnums(7scm) β the girl's guide to fixnum arithmetic π
Okay bestie, so this one is from the Scheme Programmer's Manual, and it's literally all about fixnums. Let's get into it β¨
πΈ NAME πΈ
fixnums β Fixnum arithmetic. That's it, that's the vibe. π
π LIBRARY π
Import it like this, exactly like this, no cap:
(import (rnrs arithmetic fixnums))
β¨ DESCRIPTION β¨
So here's the tea. Every implementation must define its fixnum range as a closed interval:
[β2^(wβ1), 2^(wβ1)β1]
where w is a (mathematical) integer and w β₯ 24. Yes, twenty-four. Minimum. No exceptions, periodt. π
Every mathematical integer that lives inside an implementation's fixnum range must correspond to an exact integer object that's representable within that implementation. And a fixnum? It's an exact integer object whose value lies within this fixnum range. Simple as that. π¦
Now, the important bit β fixnum operations do integer arithmetic on their fixnum arguments, but they raise an exception with condition type &implementation-restriction if the result is not a fixnum. So likeβ¦ if your math escapes the range, it's not going quietly. It's gonna throw hands. π
π§ IMPLEMENTATION NOTES π§
π€ GNU Guile
Guile runs generic arithmetic faster than fixnums. Iconic, honestly. So if your numbers are of a certain width (e.g. 32-bit), they should be truncated with bitwise-and. That's the move. π
π©· IronScheme
IronScheme stores fixnums on the heap. So remember: do not use eq?, assq or memq on fixnums. π (And ngl, this applies to Scheme as such, not just IronScheme β so it's a whole-language thing, bestie.)
π STANDARDS π
R6RS. That's the one. β
π SEE ALSO π
fixnum-width(3scm)β go read it, 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/. β¨
This page is dated2020-04-18and comes from thefixnums(7scm)entry in the Scheme Programmer's Manual, bestie β slay, go write some arithmetic ππΈπ¦
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2020 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms