Conversation
| let &$name(ref arr) = self; | ||
| if (arr[0] & (0xffffffffu64 << 32)) != 0 { | ||
| panic!("Integer overflow when casting U256") | ||
| panic!("Integer overflow when casting to u64") |
There was a problem hiding this comment.
| panic!("Integer overflow when casting to u64") | |
| panic!("Integer overflow when casting to u32") |
|
|
||
| impl $crate::core_::convert::From<i128> for $name { | ||
| fn from(value: i128) -> $name { | ||
| match value >= 0 { |
There was a problem hiding this comment.
this could be match (value as u128) >> 127 == 0 { ... } but the assembly is identical according to https://rust.godbolt.org/z/5kXf8K, so better keep it way more readable
| #[inline] | ||
| pub fn as_u128(&self) -> u128 { | ||
| let &$name(ref arr) = self; | ||
| for i in (2..$n_words) { |
There was a problem hiding this comment.
needless paratheses
| for i in (2..$n_words) { | |
| for i in 2..$n_words { |
niklasad1
left a comment
There was a problem hiding this comment.
Looks good, a couple of minor things to clean up.
However, I'm unsure of the differences between uint in this repo and the primitives repo
Would be good add some benchmarks just to see the difference between u64 and u128 (I suspect it's a bit slower but not much)
| impl_map_from!($name, isize, i64); | ||
|
|
||
| // Converts from big endian representation of U256 | ||
| // Converts from big endian representation of $name |
There was a problem hiding this comment.
This is a comment. Does macro name resolve for comments?
There was a problem hiding this comment.
Good point, seems it doesn't rust-lang/rust#37903
|
@niklasad1 I think we moved |
|
Looks like test fails because metadata macro is broken somehow: https://travis-ci.org/paritytech/parity-common/jobs/478340732#L807 |
|
All right I see, makes sense with your pending PR in the `primitives repo´. |
I think long term it would be good to use
u128as words instead ofu64