Opened 7 years ago
Closed 7 years ago
#15032 closed defect (fixed)
`real` and `imag` of `complex` should return `float`
Reported by: | eviatarbach | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-5.12 |
Component: | symbolics | Keywords: | |
Cc: | Merged in: | sage-5.12.beta3 | |
Authors: | Eviatar Bach | Reviewers: | Punarbasu Purkayastha |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
real(z)
and imag(z)
, where z
is complex
, as of now returns a complex
. It should return a float
, since that makes it consistent with real(CC(3, 4))
, for example. It also fixes problems with plotting the real or imaginary parts of complex functions.
Attachments (1)
Change History (7)
comment:1 Changed 7 years ago by
- Status changed from new to needs_review
comment:2 Changed 7 years ago by
The new functions needs some doctests to check that the type is correct.
I am actually quite surprised by the inconsistency of the Sage implementation. self.real
contains the number in the case of python's complex
but it is a function in Sage's implementation. Do you know what is the reason behind the function in the Sage implementation?
sage: a = CC(1) sage: a.real <function real> sage: a = complex(1) sage: a.real 1.0
EDIT Actually just shift the doctests to within the __call__
functions.
comment:3 Changed 7 years ago by
Okay, I'll add the tests.
I think the reason for the functions is that it's converting from MPFR. It could be changed with the @property
decorator so that self.real
will work.
Changed 7 years ago by
comment:4 Changed 7 years ago by
I added the tests to __call__
but also left the other ones intact, since the __call__
ones aren't visible in the documentation.
comment:5 Changed 7 years ago by
- Reviewers set to Punarbasu Purkayastha
- Status changed from needs_review to positive_review
Looks good to me. All tests pass in sage/rings and sage/functions
Patchbot apply trac15032.3.patch
comment:6 Changed 7 years ago by
- Merged in set to sage-5.12.beta3
- Resolution set to fixed
- Status changed from positive_review to closed
Patchbot apply trac15032.patch