Open bobbbob98 opened 1 year ago
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 BigInt
s.
It might make sense to also open an issue on the Nim repo or an RFC on this.
Could initRational be changed to
func initRational*[T: SomeInteger|BigInt](num, den: T): Rational[T] =
?
I'll test some things out later.
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.
Maybe it should be in stdlib 😉. But yeah maybe a submodule would be good, I'll try working on that.
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?