Changeset 2585:90c3e261c5f2 for sage/rings/real_mpfr.pyx
- Timestamp:
- 01/23/07 13:23:38 (6 years ago)
- Branch:
- default
- File:
-
- 1 edited
-
sage/rings/real_mpfr.pyx (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/rings/real_mpfr.pyx
r2569 r2585 9 9 -- William Stein (2006-10): default printing truncates to avoid base-2 10 10 rounding confusing (fix suggested by Bill Hart) 11 12 EXAMPLES: 13 14 A difficult conversion: 15 16 sage: RR(sys.maxint) 17 9223372036854770000 # 64-bit 11 18 """ 12 19 … … 202 209 if hasattr(x, '_mpfr_'): 203 210 return x._mpfr_(self) 204 return RealNumber(self, x, base) 211 cdef RealNumber z 212 z = self._new() 213 z._set(x, base) 214 return z 205 215 206 216 cdef _coerce_c_impl(self, x): … … 471 481 return x 472 482 473 def __init__(self, RealField parent, x=0, int base=10 , special=None):483 def __init__(self, RealField parent, x=0, int base=10): 474 484 """ 475 485 Create a real number. Should be called by first creating … … 514 524 self.init = 1 515 525 if x is None: return 526 self._set(x, base) 527 528 cdef _set(self, x, int base): 529 # This should not be called except when the number is being created. 530 # Real Numbers are supposed to be immutable. 516 531 cdef RealNumber _x, n, d 517 cdef int _ix 532 cdef Integer _ix 533 cdef RealField parent 534 parent = self._parent 518 535 if PY_TYPE_CHECK(x, RealNumber): 519 536 _x = x # so we can get at x.value 520 537 mpfr_set(self.value, _x.value, parent.rnd) 521 elif PY_TYPE_CHECK(x, sage.rings.rational.Rational):522 n = parent(x.numerator())523 d = parent(x.denominator())524 mpfr_ div(self.value, n.value, d.value, parent.rnd)525 elif PY_TYPE_CHECK(x, int):526 _ix = x527 mpfr_set_ si(self.value, _ix, parent.rnd)538 elif PY_TYPE_CHECK(x, Integer): 539 mpfr_set_z(self.value, (<Integer>x).value, parent.rnd) 540 elif PY_TYPE_CHECK(x, Rational): 541 mpfr_set_q(self.value, (<Rational>x).value, parent.rnd) 542 elif isinstance(x, (int, long)): 543 _ix = Integer(x) 544 mpfr_set_z(self.value, _ix.value, parent.rnd) 528 545 else: 529 546 s = str(x).replace(' ','')
Note: See TracChangeset
for help on using the changeset viewer.
