# HG changeset patch
# User Alexandru Ghitza <aghitza@alum.mit.edu>
# Date 1247493554 -36000
# Node ID ecc3e3f7d0819748990e210599c7b0b1cc88511a
# Parent ca1f31d6f6bf7b1f8da0cb8973c838ab19921c29
trac 6159: real_part and imag_part for CC and CDF
diff -r ca1f31d6f6bf -r ecc3e3f7d081 sage/rings/complex_double.pyx
|
a
|
b
|
|
| 1164 | 1164 | sage: a = CDF(3,-2) |
| 1165 | 1165 | sage: a.real() |
| 1166 | 1166 | 3.0 |
| | 1167 | sage: a.real_part() |
| | 1168 | 3.0 |
| 1167 | 1169 | """ |
| 1168 | 1170 | return RealDoubleElement(self._complex.dat[0]) |
| 1169 | 1171 | |
| | 1172 | real_part = real |
| | 1173 | |
| 1170 | 1174 | def imag(self): |
| 1171 | 1175 | """ |
| 1172 | 1176 | Return the imaginary part of this complex double. |
| … |
… |
|
| 1176 | 1180 | sage: a = CDF(3,-2) |
| 1177 | 1181 | sage: a.imag() |
| 1178 | 1182 | -2.0 |
| | 1183 | sage: a.imag_part() |
| | 1184 | -2.0 |
| 1179 | 1185 | """ |
| 1180 | 1186 | return RealDoubleElement(self._complex.dat[1]) |
| 1181 | 1187 | |
| | 1188 | imag_part = imag |
| | 1189 | |
| 1182 | 1190 | def parent(self): |
| 1183 | 1191 | """ |
| 1184 | 1192 | Return the complex double field, which is the parent of self. |
diff -r ca1f31d6f6bf -r ecc3e3f7d081 sage/rings/complex_number.pyx
|
a
|
b
|
|
| 715 | 715 | 2.0000000000000000000000000000 |
| 716 | 716 | sage: x.parent() |
| 717 | 717 | Real Field with 100 bits of precision |
| | 718 | sage: z.real_part() |
| | 719 | 2.0000000000000000000000000000 |
| 718 | 720 | """ |
| 719 | 721 | cdef real_mpfr.RealNumber x |
| 720 | 722 | x = real_mpfr.RealNumber(self._parent._real_field(), None) |
| 721 | 723 | mpfr_set(<mpfr_t> x.value, self.__re, rnd) |
| 722 | 724 | return x |
| 723 | 725 | |
| | 726 | real_part = real |
| | 727 | |
| 724 | 728 | def imag(self): |
| 725 | 729 | """ |
| 726 | 730 | Return imaginary part of self. |
| … |
… |
|
| 733 | 737 | 3.0000000000000000000000000000 |
| 734 | 738 | sage: x.parent() |
| 735 | 739 | Real Field with 100 bits of precision |
| | 740 | sage: z.imag_part() |
| | 741 | 3.0000000000000000000000000000 |
| 736 | 742 | """ |
| 737 | 743 | cdef real_mpfr.RealNumber x |
| 738 | 744 | x = real_mpfr.RealNumber(self._parent._real_field(), None) |
| 739 | 745 | mpfr_set(<mpfr_t> x.value, self.__im, rnd) |
| 740 | 746 | return x |
| 741 | 747 | |
| | 748 | imag_part = imag |
| | 749 | |
| 742 | 750 | def __neg__(self): |
| 743 | 751 | r""" |
| 744 | 752 | Method for computing the negative of self. |