bigints icon indicating copy to clipboard operation
bigints copied to clipboard

Add signum function

Open rotu opened this issue 3 years ago • 5 comments

rotu avatar Jul 25 '22 23:07 rotu

Should this really allocate a new BigInt? I feel like this should just return an int, so that the user can choose if they want that extra allocation, by manually calling initBigInt. Do you have a concrete use casein mind for this, where it's more useful to have this return a BigInt?

konsumlamm avatar Jul 26 '22 06:07 konsumlamm

Should this really allocate a new BigInt? I feel like this should just return an int, so that the user can choose if they want that extra allocation, by manually calling initBigInt. Do you have a concrete use casein mind for this, where it's more useful to have this return a BigInt?

The reason it returns a BigInt is for the invariant x == abs(x) * sgn(x). I'd be okay with returning an int if BigInt arithmetic allowed implicit widening (like other numeric types do).

rotu avatar Jul 26 '22 06:07 rotu

I think we should support arithmetic where one of the arguments is an int sooner or later.

konsumlamm avatar Jul 26 '22 08:07 konsumlamm

I think we should support arithmetic where one of the arguments is an int sooner or later.

Any reason why initBigInt(SomeSignedInt): BigInt isn't an implicit conversion? That seems like the easy solution

rotu avatar Jul 26 '22 16:07 rotu

NVM - opened https://github.com/nim-lang/bigints/pull/109 Feel free to tell me there why this is a bad idea :-p

rotu avatar Jul 26 '22 17:07 rotu