cmpute / dashu

A library set of arbitrary precision numbers implemented in Rust.
Apache License 2.0
74 stars 9 forks source link

Gcd for IBig returns UBig #32

Closed joseluis closed 1 year ago

joseluis commented 1 year ago

Would it be possible to make it a closed operation, like the rest, that returns the same operand type?

cmpute commented 1 year ago

Is there any necessary use case for this change? You can convert the UBig result into IBig by a single .into() expression.

joseluis commented 1 year ago

Right, I guess can use the Into impl without performance loss I assume.

I was just porting some code that used the ibig crate to dashu-int and it felt weird that the function returned a different type, and was wondering if there was a good reason for that. The only benefit in anycase may be API-wise.

cmpute commented 1 year ago

It's kind of my personal favor. I think it's better to use the most concise type for the output to reduce ambiguity. For example, if the GCD of IBigs returns an IBig, then I can't immediately know what is the sign of the output without looking at the docs.

I will close this issue for now, as I don't plan to change that. Sorry for the confusion.

joseluis commented 1 year ago

I understand. I like that it's a consistent choice, I can see the euclidean remainder for IBig is also a UBig. That's good. And since the From for IBig impl avoids cloning, it's no issue for me. Thanks for taking the time to explain.