fixnums(7scm)

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

πŸ’… 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 πŸ‘€


🫢 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 dated 2020-04-18 and comes from the fixnums(7scm) entry in the Scheme Programmer's Manual, bestie β€” slay, go write some arithmetic πŸ’–πŸŒΈπŸ¦‹
πŸ“¦ where this page comes from