Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading information in section "Rational types" #467

Open
phoe opened this issue Nov 19, 2022 · 0 comments
Open

Misleading information in section "Rational types" #467

phoe opened this issue Nov 19, 2022 · 0 comments

Comments

@phoe
Copy link

phoe commented Nov 19, 2022

cl-cookbook/numbers.md

Lines 71 to 82 in fd22cd8

### Rational types
Rational numbers of type [`ratio`][ratio] consist of two `bignum`s, the
numerator and denominator. Both can therefore be arbitrarily large:
~~~lisp
* (/ (1+ (expt 2 100)) (expt 2 100))
1267650600228229401496703205377/1267650600228229401496703205376
~~~
It is a subtype of the [`rational`][rational] class, along with
[`integer`][integer].

The type bignum is specified to be exactly (and integer (not fixnum)), which, along with the first line of this paragraph, would then mean that 1/2 is not a valid ratio because neither 1 and 2 are bignums.

I'd rather say something similar to the specification: that numerator and denominator are both integers, their GCD is 1, and numerator must be greater than 1.

I'd also mention that the conversion between ratio and integer is automatic so the programmer doesn't need to worry about overflows or underflows or imprecise computation, but also means that it's easily possible to reach bignum arithmetic and therefore get computation that is slower and consing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant