Skip to content

Add signum function - #108

Open
rotu wants to merge 1 commit into
nim-lang:masterfrom
rotu:patch-1
Open

Add signum function#108
rotu wants to merge 1 commit into
nim-lang:masterfrom
rotu:patch-1

Conversation

@rotu

@rotu rotu commented Jul 25, 2022

Copy link
Copy Markdown
Contributor

No description provided.

@konsumlamm

Copy link
Copy Markdown
Contributor

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?

@rotu

rotu commented Jul 26, 2022

Copy link
Copy Markdown
Contributor Author

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).

@konsumlamm

Copy link
Copy Markdown
Contributor

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

@rotu

rotu commented Jul 26, 2022

Copy link
Copy Markdown
Contributor Author

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

rotu commented Jul 26, 2022

Copy link
Copy Markdown
Contributor Author

NVM - opened #109
Feel free to tell me there why this is a bad idea :-p

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

Successfully merging this pull request may close these issues.

2 participants