exact(3scm)
π exact, inexact β converting between exact and inexact numbers π
okay so bestie, welcome to the exact(3scm) page β straight out of the Scheme Programmer's Manual, and honestly? it's giving "tiny page, huge feelings." we're talking about the two little procedures that flip your numbers between exact and inexact, and they're iconic for it. π¦
β¨ LIBRARY β¨
here's where you import these cuties from. multiple vibes, same energy:
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme base)) ;R7RS
and the R5RS legacy names (yes, they still get an invite to the party):
; R5RS legacy names
(import (rnrs r5rs)) ;R6RS
(import (scheme r5rs)) ;R7RS
πΈ SYNOPSIS πΈ
the whole menu, short and sweet:
(exact z)
(inexact z)
; R5RS legacy names
(inexact->exact z)
(exact->inexact z)
π DESCRIPTION π
okay so let's actually talk about what these do, because it's literally so straightforward and yet so useful.
exact hands you back an exact representation of z. the value it returns is the exact number object that's numerically closest to the argument β and in most cases, the result should be numerically equal to its argument. no cap. π«Ά
inexact does the opposite dance: it returns an inexact representation of z. and here's the nuance β if inexact number objects of the appropriate type have bounded precision, then the value you get back is the inexact number object that's nearest to the argument. closest fit wins, basically. π
π₯ Large numbers π₯
for a real number object whose magnitude is finite but so large that it has no reasonable finite approximation as an inexact number β yeah, that's a big one β a reasonably close inexact equivalent may be +inf.0 or -inf.0. literally infinity because nothing else fits, iykyk. similarly, the inexact representation of a complex number object whose components are finite may end up with infinite components. the vibes get infinite too. π
π Idempotency π
inexact and exact are idempotent. meaning: if you call them with a number that already has the exactness you're asking for, they just return that number right back at you. no drama, no conversion, no problem. it's giving "already perfect, thanks." π
π¦ Complex numbers (R7RS) π¦
for complex numbers that don't already have the desired exactness, the result is a complex number whose real and imaginary parts are the result of applying the procedure to the real and imaginary parts of the argument, respectively. so each half gets its own little glow-up, separately. cute. π
β RETURN VALUES β
returns a single exact or inexact number object, respectively. one value, no surprises. π
π EXAMPLES π
watch it work its magic:
(exact 0.5)
=> 1/2
(inexact 3/4)
=> 0.75
ate. no crumbs. π₯
π APPLICATION USAGE π
these procedures are used to manage the exactness used in computations. that's the whole job description, and they do it beautifully. β¨
πΈ COMPATIBILITY πΈ
R7RS implementations are not required to support the full numeric tower. just so you know what you're walking into, bestie. π
π ERRORS π
okay, here's where things can get spicy. these procedures can raise exceptions with the following condition types:
&assertion(R6RS) β the wrong number of arguments was passed, or an argument was outside its domain. rude, but fair.&implementation-restriction(R6RS) β may be raised if an inexact argument has no reasonably close exact equivalent, or an exact argument has no reasonably close inexact equivalent, respectively.
R7RS β okay so the assertions described above are errors, and implementations may do one of three things: signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically. yes, catastrophic. dramatic but accurate. π
also for R7RS: an implementation restriction may be reported under the circumstances described above for &implementation-restriction, indicating that the implementation is unable to continue execution of a correct program. it may also be reported by the exact procedure when its argument is an inexact non-integral real. so like, watch out for that one specifically. π«Ά
π§ SEE ALSO π§
fixnum->flonum(3scm) β go give it a visit, it's in the friend group. π
π STANDARDS π
R4RS, IEEE Scheme, R5RS, R6RS, R7RS β certified across many eras. vintage AND current, a true timeless icon. β
π HISTORY π
back in the day β R5RS and earlier reports β these procedures were called exact->inexact and inexact->exact. glow-up complete. π
π AUTHORS π
this page is part of the scheme-manpages project, and it includes materials from the RnRS documents. more information can be found at https://github.com/schemedoc/manpages/. slay, documentation maintainers, we love you. π«Ά
π that's the whole page bestie β remember: exactness is a vibe, idempotency is a lifestyle, and +inf.0 is always there for you when the numbers get too big.
scheme-manpages, dated 2021-06-25 β exact(3scm), signing off. mwah. πβ¨
π¦ where this page comes from
- nixpkgs unstable: scheme-manpages 0-unstable-2024-02-11
- π the page's license: MIT
- Copyright (c) 2021 Gwen Weinholt
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms