Aatch / ramp

RAMP - Rust Arithmetic in Multiple Precision
Apache License 2.0
261 stars 38 forks source link

[feature request] Checked primitive type conversion #13

Open kunerd opened 9 years ago

kunerd commented 9 years ago

Add checked conversion for Int to primitive types (u8, u16, u32, ...), similar as in num::bigint trait.

fn to_i64(&self) -> Option<i64> { ... }
rozbb commented 6 years ago

This is doable. Do you have a motivating use case for a feature like this?

kunerd commented 6 years ago

I think my main motivation back in the days was that I used ramp to implement algorithms which work in a cryptographic context, e.g. do some operations with encrypted values and in the end get the plain (decrypted) result. So my inputs where something like u8, u16 and so on, the encrypted values were ramps big ints and my result in the end should be again u8, u16, ...

rozbb commented 6 years ago

Hmm I see. For the sake of brevity, I would hold off on implementing this inside ramp, since it can be done pretty easily with an Int::to_str_radix followed by a u16::from_str_radix or what have you. Is that reasonable?