numerator(3scm)
π 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,qmust be a rational number andflmust 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:
rationalize(3scm)real-part(3scm)gcd(3scm)div-and-mod(3scm)
π 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
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2023 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms