2 real -- real numbers and the real number field. 4 The module real provides arbitrary precision real numbers and their 5 utilities. The functions provided are corresponding to the math 9 from __future__
import division
16 from nzmath.plugins import MATHMODULE
as math, FLOATTYPE
as Float, \
17 CHECK_REAL_OR_COMPLEX
as check_real_or_complex
22 Real is a class of real. 23 This class is only for consistency for other Ring object. 30 value will be wrapped in Float. 32 ring.FieldElement.__init__(self)
34 self.
data = value.toFloat()
36 self.
data = Float(value)
39 if isinstance(other, Real):
40 result = self.
data + other.data
42 result = self.
data + other
45 return self.__class__(result)
49 result = other + self.
data 52 return self.__class__(result)
55 if isinstance(other, Real):
56 result = self.
data - other.data
58 result = self.
data - other
61 return self.__class__(result)
65 result = other - self.
data 68 return self.__class__(result)
71 if isinstance(other, Real):
72 result = self.
data * other.data
74 result = self.
data * other
77 return self.__class__(result)
81 result = other * self.
data 84 return self.__class__(result)
87 if isinstance(other, Real):
88 result = self.
data / other.data
90 result = self.
data / other
93 return self.__class__(result)
99 result = other / self.
data 101 return NotImplemented
102 return self.__class__(result)
104 __rdiv__ = __rtruediv__
107 if isinstance(other, Real):
108 result = math.pow(self.
data, other.data)
110 result = math.pow(self.
data, other)
114 if isinstance(other, Real):
115 return self.
data == other.data
117 return self.
data == other
119 return NotImplemented
122 return hash(self.
data)
126 Return the real field instance. 133 RealField is a class of the field of real numbers. 134 The class has the single instance 'theRealField'. 138 ring.Field.__init__(self)
146 return "%s()" % (self.__class__.__name__, )
153 if check_real_or_complex(element):
156 if hasattr(element,
'conjugate'):
157 return element == element.conjugate()
159 if hasattr(element,
'getRing')
and element.getRing().
issubring(self):
164 return isinstance(other, self.__class__)
167 return not self.
__eq__(other)
177 one = property(_getOne,
None,
None,
"multiplicative unit.")
184 zero = property(_getZero,
None,
None,
"additive unit.")
187 if isinstance(aRing, RealField):
191 return aRing.issuperring(self)
194 if isinstance(aRing, RealField):
196 elif rational.theRationalField.issuperring(aRing):
198 return aRing.issubring(self)
205 The characteristic of the real field is zero. 211 " iterator for log(1+x)." 218 positive =
not positive
227 floor(x) returns the integer; if x is an integer then x itself, 228 otherwise the biggest integer less than x. 231 if rx.denominator == 1:
233 return rx.numerator // rx.denominator
237 ceil(x) returns the integer; if x is an integer then x itself, 238 otherwise the smallest integer greater than x. 241 if rx.denominator == 1:
243 return rx.numerator // rx.denominator + 1
247 tranc(x) returns the integer; if x is an integer then x itself, 248 otherwise the nearest integer to x. If x has the fraction part 249 1/2, then bigger one will be chosen. 252 if rx.denominator == 1:
258 returns absolute value of x. 264 returns x - n * y, where n is the quotient of x / y, rounded 265 towards zero to an integer. 276 Return a tuple (m, e) where x = m * 2 ** e, 1/2 <= abs(m) < 1 and 278 This function is provided as the counter-part of math.frexp, but it 309 Return an iterator which yields terms of Euler transform of the 315 for term
in iterator:
317 for i
in xrange(l, -1, -1):
318 stock[i] += stock[i+1]