From/To/AsPrimitive and NumCast for Complex<T>#33
Merged
bors[bot] merged 10 commits intorust-num:masterfrom Oct 3, 2018
Merged
From/To/AsPrimitive and NumCast for Complex<T>#33bors[bot] merged 10 commits intorust-num:masterfrom
bors[bot] merged 10 commits intorust-num:masterfrom
Conversation
Contributor
Author
|
Fix 1.15.0 case |
cuviper
requested changes
Oct 2, 2018
Member
cuviper
left a comment
There was a problem hiding this comment.
Looks good, just a couple comments.
src/cast.rs
Outdated
| ($ty:ty, $to:ident) => { | ||
| #[inline] | ||
| fn $to(&self) -> Option<$ty> { | ||
| if self.im == T::zero() { self.re.$to() } else { None } |
Member
There was a problem hiding this comment.
Should use self.im.is_zero() to avoid constructing a new value.
src/cast.rs
Outdated
| }; | ||
| } // impl_from_primitive | ||
|
|
||
| impl<T: FromPrimitive + Zero> FromPrimitive for Complex<T> { |
Member
There was a problem hiding this comment.
Why did you require just Zero here, but full Num elsewhere?
Most of the crate actually requires T: Clone + Num, and then you could leverage:
impl<T: Clone + Num> From<T> for Complex<T>
Contributor
Author
|
Thanks review. I fixed them. |
cuviper
approved these changes
Oct 3, 2018
Member
|
Thanks! bors r+ |
bors bot
added a commit
that referenced
this pull request
Oct 3, 2018
33: From/To/AsPrimitive and NumCast for Complex<T> r=cuviper a=termoshtt
I added a submodule `cast` which defines four traits in `num-traits::cast`:
- `ToPrimitive::to_xxx` returns `None` if `im` is non-zero
- `FromPrimitive::from_xxx(a)` returns `Complex { re: T::from_xxx(a), im: T::zero() }`
- `AsPrimitive` drops the imaginary part of complex
- `NumCast` is same as `ToPrimitive`
Co-authored-by: Toshiki Teramura <toshiki.teramura@gmail.com>
Contributor
Build succeeded |
Contributor
Author
|
Could you release 0.2.1? or any release schedule? |
Member
Done! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I added a submodule
castwhich defines four traits innum-traits::cast:ToPrimitive::to_xxxreturnsNoneifimis non-zeroFromPrimitive::from_xxx(a)returnsComplex { re: T::from_xxx(a), im: T::zero() }AsPrimitivedrops the imaginary part of complexNumCastis same asToPrimitive