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

implement big int module #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

CrowdHailer
Copy link
Contributor

No description provided.

pub fn from_int(a: Int) -> BigInt

@external(javascript, "../../ffi.mjs", "from")
pub fn from_string(a: String) -> BigInt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work? What happens when it's not a valid string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it errors. updated from_string to return result but from_int can still return just a value


big_int.add(a, b)
|> should.equal(big_int.from_string("18446744073709551617"))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have tests for all the functions please 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added for remaining functions

Comment on lines +24 to +27
/// Zero division returns an error, this is different to core gleam number type
/// and is chosen because this library aims to be smallest wrapper for ffi and
/// where possible should emulate platform behaviour
@external(javascript, "../../ffi.mjs", "divide")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Gleam dividing by zero returns zero. Let's do that to be consistent.

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