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

Add convenience functions for conversion to primitive integer types. #28

Open
stencillogic opened this issue Apr 13, 2024 · 2 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@stencillogic
Copy link
Owner

Consider adding conversion functions to primitive integer types.
Possible signatures (<int_type> is i8, i16, i32, i64, i128, u8, u16,u32, u64, u128):

  • BigFloat::try_to_<int_type>(&self, RoundingMode) -> Result<<int_type>, Error>: returns Error if BigFloat's absolute values is larger than the the value <int_type> can hold.
  • BigFloat::to_<int_type>_saturating(&self, RoundingMode) -> <int_type>: if the value of BigFloat is larger than the value that <int_type> can hold, clamp the value to the maximum value of <int_type>.
@atrabattoni
Copy link

I think this would work in concert will all the floor/ceil/round kind of functions. In my case I need to go back and forth from i128/u128 to f64. I need higher precision floats as intermediate processing values but ultimately i need to go back to primitie.

@atrabattoni
Copy link

So the to_<int_type>_saturating would follow how as now works when casting from <float_type> as <int_type>. Looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants