Implement complex numbers and basic arithmetic#154040
Implement complex numbers and basic arithmetic#154040scimind2460 wants to merge 2 commits intorust-lang:mainfrom
Conversation
|
Some changes occurred in src/tools/cargo cc @ehuss |
|
r? @scottmcm rustbot has assigned @scottmcm. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6fec289 to
60e66dd
Compare
|
I'd recommend that the first PR only add A test in tests/codegen-llvm is needed for sure, also in tests/assembly-llvm would be ideal. Or only do addition+subtraction first, add compiler support later |
60e66dd to
b960263
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
23eb6b8 to
7a44277
Compare
I'll do that. I'm not entirely sure how to add support for calling conventions that exactly match up with _Complex. |
This comment has been minimized.
This comment has been minimized.
|
You can probably make it a lang item and check for it in the target specific call conv impls of |
7a44277 to
2e8643c
Compare
Thanks for the tip @bjorn3! I was planning to go with the lang item approach and #[repr(c)]. It is intentional as AFAIK libs didn't want the overhead of a full trait, and I'm not sure how we could implement it for non-float types. |
This comment has been minimized.
This comment has been minimized.
2e8643c to
2533dcc
Compare
This comment has been minimized.
This comment has been minimized.
2533dcc to
e3cad87
Compare
This comment has been minimized.
This comment has been minimized.
e3cad87 to
11b1734
Compare
This comment has been minimized.
This comment has been minimized.
f528121 to
fa06e21
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
648ce19 to
9a48039
Compare
This comment has been minimized.
This comment has been minimized.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
|
The job Click to see the possible cause of the failure (guessed by this bot) |
| /// The complex number type in Cartesian form. | ||
| /// Supports simple addition and subtraction. | ||
| /// ``` |
There was a problem hiding this comment.
| /// The complex number type in Cartesian form. | |
| /// Supports simple addition and subtraction. | |
| /// ``` | |
| /// The complex number type in Cartesian form. | |
| /// | |
| /// ``` |
In the future it will support more :) Also note that consecutive doc lines without a blank line get turned into a single paragraph.
| @@ -0,0 +1,32 @@ | |||
| use core::num::Complex; | |||
|
|
|||
| float_test! { | |||
There was a problem hiding this comment.
You need to actually import crate::num::float_test (CI failure)
| /// assert_eq!(x + y, Complex::new(4.0, 6.0); | ||
| /// assert_eq!(y - x, Complex::new(2.0, 2.0); | ||
| /// ``` | ||
| #[derive(Debug, PartialEq)] |
There was a problem hiding this comment.
Not sure if this was discussed before, but maybe
| #[derive(Debug, PartialEq)] | |
| #[derive(Clone, Copy, Debug, PartialEq)] |
?
| #[unstable(feature = "complex_numbers", issue = "154023")] | ||
| impl<T> Complex<T> { | ||
| /// Constructs a new instance of type `Complex`. | ||
| pub fn new(re: T, im: T) -> Self { |
There was a problem hiding this comment.
Not sure if this was discussed before, but maybe
| pub fn new(re: T, im: T) -> Self { | |
| #[must_use] | |
| pub const fn new(re: T, im: T) -> Self { |
?
|
Need some git help if it's the same as #154656? |
View all comments
Related to #154023
This PR adds complex numbers as a lang item behind a libs feature gate and adds simple implementations for arithmetic.