Implement complex numbers and basic arithmetic#154040
Implement complex numbers and basic arithmetic#154040scimind2460 wants to merge 1 commit 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
There was a problem hiding this comment.
add a new line on the end of this file
|
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
|
The job Click to see the possible cause of the failure (guessed by this bot) |
| /// This promises to be equivalent to the C type on each platform. | ||
| #[unstable(feature = "complex_numbers", issue = "154023")] | ||
| #[derive(Copy, Clone)] | ||
| pub struct Complex<T: Copy> { |
There was a problem hiding this comment.
It's extremely rare that we have bounds on types in the library. Why does this have the bound rather than just being
| pub struct Complex<T: Copy> { | |
| pub struct Complex<T> { |
There was a problem hiding this comment.
Because it made it a bit easier to implement the functions themselves rather than think of whether they wilp be consumed or taken by reference (given that floats are Copy)
| impl<T> Complex<T> { | ||
| pub fn new(re: T, im: T) -> Self { | ||
| Self { re, im } | ||
| } | ||
| } |
There was a problem hiding this comment.
notably, this can't work as written with the bound on the type
|
I would suggest splitting the PRs to not do too much in one. For example, start with just adding a library type with no compiler changes. You can do another PR for lang items and such later. |
Related to #154023
This PR adds complex numbers as a lang item behind a libs feature gate and adds simple implementations for arithmetic.