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

Rational numbers #124

Open
bobbbob98 opened this issue Feb 11, 2023 · 4 comments
Open

Rational numbers #124

bobbbob98 opened this issue Feb 11, 2023 · 4 comments

Comments

@bobbbob98
Copy link

BigInt objects don't work with the rationals module, because initRational expects SomeInteger which BigInt isn't. Looking through the code for rationals, it looks like the only function it needs that bigints doesn't have is lcd. What would be the best way to go about using bigints with rational numbers? Could BigInt be marked as SomeInteger with some tweaking?

@konsumlamm
Copy link
Contributor

SomeInteger only encompasses the builtin integers, there is no way to extend that. It could be changed to a concept, but afaik concepts aren't desired in the stdlib rn. Another option would be to change std/rationals to accept any type that implements a specific interface, without actually checking that the types satisfy that interface (i.e. removing the SomeInteger constraint.

However, I think the most realistic option for now is to duplicate std/rationals to a submodule of bigints, that way we might also optimize some things for BigInts.

It might make sense to also open an issue on the Nim repo or an RFC on this.

@bobbbob98
Copy link
Author

Could initRational be changed to
func initRational*[T: SomeInteger|BigInt](num, den: T): Rational[T] = ?
I'll test some things out later.

@konsumlamm
Copy link
Contributor

Could initRational be changed to func initRational*[T: SomeInteger|BigInt](num, den: T): Rational[T] = ? I'll test some things out later.

It could if the stdlib would depend on bigints, but it doesn't.

@bobbbob98
Copy link
Author

Maybe it should be in stdlib 😉. But yeah maybe a submodule would be good, I'll try working on that.

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

2 participants