scuq.arithmetic¶
- scuq.arithmetic.gcd(m, n)[source]¶
Calculate the greatest common divisor.
- Parameters:
n – First integer value (greater or equal to zero).
m – Second value (greater or equal to zero).
- Returns:
The greatest common divisor of the inputs.
- scuq.arithmetic.rational(n, d)[source]¶
This function provides an interface for rational numbers creation, as suggested in PEP 239.
- Parameters:
d – The denominator (must be an interger type).
n – The nominator (must be an integer type).
- Returns:
An instance of RationalNumber
- scuq.arithmetic.complex_to_matrix(c)[source]¶
Convert a complex number to its 2x2 NumPy array representation.
- class scuq.arithmetic.RationalNumber(dividend, divisor=1)[source]¶
Bases:
objectRepresent a rational number with integer dividend and divisor. The arithmetic operators emulate rational arithmetic where possible. For unsupported mixed-type operations, methods may fall back to floating-point behavior.
- __init__(dividend, divisor=1)[source]¶
Default constructor. This initializes the rational number.
- Parameters:
dividend – An integer representing the dividend of this
rational number.
- Parameters:
divisor – An integer representing the divisor of this
rational number. If this parameter is obmitted it is initialized to 1.
- __str__()[source]¶
This method returns a string representing this rational number.
- Returns:
A string representing this rational number.
- normalize()[source]¶
This method maintains the canonical form of this rational number and avoids negative divisors.
- __complex__()[source]¶
Cast this rational number to a complex number.
- Returns:
A complex number, having a zero imaginary part.
- __add__(value)[source]¶
Add a number and return the result.
- Parameters:
value – The number to add.
- Returns:
The sum of this instance and the argument.
- __sub__(value)[source]¶
Substract a number and return the result.
- Parameters:
value – The number to substract.
- Returns:
The difference of this instance and the argument.
- __mul__(value)[source]¶
Multiply a number and return the result.
- Parameters:
value – The number to multiply.
- Returns:
The product of this instance and the argument.
- __pow__(value)[source]¶
Raise this rational number to the given power and return the result. a floating point number will be returned. Note that this may result in a loss of accuracy.
- Parameters:
value – A numeric value representing the power.
- Returns:
A new rational number representing power of this instance.
- __rpow__(value)[source]¶
Raise another value to the power of this rational number. the result.
- Parameters:
value – A value to be raised to the power.
- Returns:
A new rational number representing power of this instance.
- __truediv__(value)[source]¶
Divide by another number and return the result.
- Parameters:
value – A number.
- Returns:
The fraction of this instance and the number.
- __neg__()[source]¶
This method returns the negative of this instance.
- Returns:
A new rational number.
- __abs__()[source]¶
This method returns the absolute value of this instance.
- Returns:
A new rational number.
- __invert__()[source]¶
This method returns a new rational number that swapped dividend and divsor of this instance.
- Returns:
A new rational number.
- get_dividend()[source]¶
Returns the dividend of this instance.
- Returns:
The dividend of this instance.
- __eq__(value)[source]¶
Checks if this instance is equal to a number.
- Parameters:
value – The value to compare to.
- Returns:
If this rational number is equal to the argument.
- __lt__(value)[source]¶
Checks if this instance is less than another number.
- Parameters:
value – The value to compare to.
- Returns:
True, if this rational number is less than the argument.
- __ne__(value)[source]¶
Checks if this instance unequal to another number.
- Parameters:
value – The value to compare to.
- Returns:
True, if this rational number unequal to the argument.
- __gt__(value)[source]¶
Checks if this instance is greater than another number.
- Parameters:
value – The value to compare to.
- Returns:
True, if this rational number is greater than the argument.
- __ge__(value)[source]¶
Checks if this instance is greater or equal to another number.
- Parameters:
value – The value to compare to.
- Returns:
True, if this rational number is greater or equal to the argument.
- __le__(value)[source]¶
Checks if this instance is less or equal to another number.
- Parameters:
value – The value to compare to.
- Returns:
True, if this rational number is less or equal to the argument.
- __cmp__(value)[source]¶
Compares this instance to another number.
- Parameters:
value – The value to compare to.
- Returns:
-1: if this instance is less…; +1: if this is greater than the argument; 0 otherwise
- __radd__(value)[source]¶
Left addition of a numeric value.
- Parameters:
value – A value to left from this instance.
- __rsub__(value)[source]¶
Right substraction of a numeric value.
- Parameters:
value – A value to left from this instance.
- __rmul__(value)[source]¶
Right multiplication of a numeric value.
- Parameters:
value – A value to left from this instance.
- __rtruediv__(value)[source]¶
Right division of a numeric value.
- Parameters:
value – A value to left from this instance.
- __getstate__()[source]¶
Serialization using pickle.
- Returns:
A string that represents the serialized form of this instance.
- __setstate__(state)[source]¶
Deserialization using pickle.
- Parameters:
state – The state of the object.
- static value_of(number)[source]¶
Return a
RationalNumberfor an integer-like input.- Raises:
TypeError – If
numberis neither integer-like nor a
RationalNumber.
- is_integer()[source]¶
Check wether this instance could be be casted to long accurately.
- Returns:
True, if the divisor is equal to one.
- arccos()[source]¶
This method provides the broadcast interface for numpy.arccos.
- Returns:
The inverse Cosine of this number.
- arccosh()[source]¶
This method provides the broadcast interface for numpy.arccosh.
- Returns:
The inverse hyperbolic Cosine of this number.
- arcsin()[source]¶
This method provides the broadcast interface for numpy.arcsin.
- Returns:
The inverse Sine of this number.
- arcsinh()[source]¶
This method provides the broadcast interface for numpy.arcsinh.
- Returns:
The inverse hyperbolic Sine of this number.
- arctan()[source]¶
This method provides the broadcast interface for numpy.arctan.
- Returns:
The inverse Tangent of this number.
- arctanh()[source]¶
This method provides the broadcast interface for numpy.arctanh.
- Returns:
The inverse hyperbolic Tangent of this number.
- cos()[source]¶
This method provides the broadcast interface for numpy.cos.
- Returns:
The Cosine of this number.
- cosh()[source]¶
This method provides the broadcast interface for numpy.cosh.
- Returns:
The hyperbolic Cosine of this number.
- tan()[source]¶
This method provides the broadcast interface for numpy.tan.
- Returns:
The Tangent of this number.
- tanh()[source]¶
This method provides the broadcast interface for numpy.tanh.
- Returns:
The hyperbolic Tangent of this number.
- log10()[source]¶
This method provides the broadcast interface for numpy.log10.
- Returns:
The decadic Logarithm of this number.
- sin()[source]¶
This method provides the broadcast interface for numpy.sin.
- Returns:
The Sine of this number.
- sinh()[source]¶
This method provides the broadcast interface for numpy.sinh.
- Returns:
The hyperbolic Sine of this number.
- sqrt()[source]¶
This method provides the broadcast interface for numpy.sqrt.
- Returns:
The Square Root of this number.
- fabs()[source]¶
This method provides the broadcast interface for numpy.fabs.
- Returns:
The absolute value of this number.
- absolute()[source]¶
This method provides the broadcast interface for numpy.absolute.
- Returns:
The absolute value of this number.
- floor()[source]¶
This method provides the broadcast interface for numpy.floor.
- Returns:
The largest integer less than or equal to this number.
- ceil()[source]¶
This method provides the broadcast interface for numpy.ceil.
- Returns:
The largest integer greater than or equal to this number.
- exp()[source]¶
This method provides the broadcast interface for numpy.exp.
- Returns:
The Exponential of this number.
- log()[source]¶
This method provides the broadcast interface for numpy.log.
- Returns:
The Natural Logarithm of this number.
- log2()[source]¶
This method provides the broadcast interface for numpy.log2.
- Returns:
The binary logarithm of this number.
- square()[source]¶
This method provides the broadcast interface for numpy.square.
- Returns:
The binary logarithm of this number.
- arctan2(other)[source]¶
This method provides the broadcast interface for numpy.arctan2.
- Parameters:
other – Another rational number.
- Returns:
The binary logarithm of this number.
- hypot(other)[source]¶
This method provides the broadcast interface for numpy.hypot.
- Parameters:
other – Another rational number.
- Returns:
The binary logarithm of this number.
- fmod(other)[source]¶
Return
numpy.fmod(float(self), other). Note: This operation is intentionally one-way and may fail when called via reverse dispatch from other numeric types.