Repository navigation
Conversation
| fn repr(&self) -> String { | ||
| let Complex64 { re, im } = self.value; | ||
| if re == 0.0 { | ||
| let re_part = if re.is_nan() { |
There was a problem hiding this comment.
So, here's a another idea. We can re-use float formatting to get the job done (and get long float values for the real and imag parts to print out in scientific notation).
Inside float_ops we have to_string that takes an f64 and returns it nicely formatted (it also includes handling of the NaN). The main issue is the sign we add, if its a nan for imag we must always prefix with a "+" (granted that a real part exists).
There was a problem hiding this comment.
That's a really great suggestion, sorry I did not check float_ops before 😞
Changing this right now.
So I've made the change you suggested as: if re == 0.0 {
format!("{}j", float_ops::to_string(im))
} else if im.is_nan() {
format!("({}+nanj)", float_ops::to_string(re))
} else {
format!("({}{:+}j)", float_ops::to_string(re), float_ops::to_string(im))
}It covered examples given in the issue: >>>>> complex(0, float('nan'))
nanj
>>>>> complex(float('nan'), float('nan'))
(nan+nanj)
>>>>> complex(float('nan'), -float('nan'))
(nan+nanj)
>>>>> complex(-float('nan'), float('nan'))
(nan+nanj)However, when I tested it with some random complex numbers, it does not go as planned: >>>>> 10j
10.0j
>>>>> 10j
10.0j
>>>>> 1-10j
(1.0-10.0j)
>>>>> complex(10, float('10'))
(10.010.0j)
>>>>> complex(-10, float('10'))
(-10.010.0j)I know that Second to that, Right now, I am little bit confused how to proceed (maybe I misunderstood something?) . Open to any suggestion 😿 |
|
You can forward the |
|
I've done some work on this issue but using I do not want to steal any ones work so, in the name of simplicity #3228 can be merged. |
|
Thank you for considerate response. Do you want another issue to work on? |
No, thank you. |
This PR will fix #3182
Tested Scenarios
I am really new to Rust so feel free to give any constructive criticism 🥊