numerator(3scm)

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

πŸ’… numerator(3scm) β€” the Scheme Programmer's Manual, but make it cute

okay so bestie, this is numerator(3scm) from the Scheme Programmer's Manual, and it's literally the page about splitting a fraction into its top half and bottom half. no cap, it's simpler than it sounds. let's go 🫢


✨ NAME ✨

numerator, denominator, flnumerator, fldenominator β€” compute numerator and denominator

like, the whole squad: the exact ones and the flonum ones. all four. πŸŽ€

πŸ“š LIBRARY πŸ“š

which library you gotta import, depending on your vibe:

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS
(import (rnrs arithmetic flonums))  ;R6RS

not me giving you five whole import lines πŸ’€ pick according to your standard, iykyk.

πŸ¦‹ SYNOPSIS πŸ¦‹

(denominator q)
(numerator q)
(fldenominator fl)
(flnumerator fl)

that's the whole shape of it. four procedures, four little calls. slay.

🌸 DESCRIPTION 🌸

so these procedures return the numerator or the denominator of whatever you hand them. that's it. that's the job. πŸ’…

but here's the important bit: the result is computed as if the argument was represented as a fraction in lowest terms. the denominator is always positive β€” always, no exceptions, periodt. and the denominator of 0 is defined to be 1. yes really. iconic behaviour honestly.

⭐ RETURN VALUES ⭐

returns a single value β€” an integer with the same exactness as the argument. so if you gave it something exact, you get something exact back. same energy in, same energy out. πŸ”₯

πŸ“ EXAMPLES πŸ“

these are adorable, look:

(numerator (/ 6 4))    =>  3
(denominator (/ 6 4))  =>  2
(denominator
  (inexact (/ 6 4)))   =>  2.0
(numerator 5)          =>  5
(denominator 5)        =>  1

see how the inexact one gives you 2.0 instead of 2? that's the exactness thing doing its thing. and 5 is just 5/1, so numerator 5, denominator 1. math ate. 🧚

πŸ‘‘ RATIONALE πŸ‘‘

why do these even exist as user-facing procedures? because they, or their equivalents, are used internally in many arithmetic procedures. and since they must exist somewhere in the implementation anyway, it makes sense to just... give them to you. so thoughtful. main character energy from the implementers honestly. πŸ’–

🌈 COMPATIBILITY 🌈

these procedures work the same everywhere β€” with one little caveat: R7RS implementations are allowed to not support all types of numbers. so it's consistent, but your implementation might have opinions about which numbers it even acknowledges. vibe check your implementation first, bestie. πŸ™ˆ

πŸ’€ 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. in particular, q must be a rational number and fl must be a flonum object. like, don't pass it a string and act surprised. 😭
  • 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. yeah. catastrophically. that's the actual word. so maybe don't. πŸ”₯

πŸ”— SEE ALSO πŸ”—

go read these next, bestie, they're all connected:

πŸŽ€ STANDARDS πŸŽ€

R4RS, IEEE Scheme, R5RS, R6RS, R7RS β€” all of them. certified everywhere. πŸ‘‘

🧚 HISTORY 🧚

these procedures first appeared in R3RS. and the flonum variants? they're new to R6RS's flonum library. so the fl-prefixed girlies are the babies of the family. 🍼

πŸ’œ 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, you understood it perfectly, i'm so proud 🫢✨

sign-off: this page was dated 2023-02-09, and it's numerator(3scm) all the way through β€” go forth and split fractions responsibly πŸ’…

πŸ“¦ where this page comes from