SigFig
#
- class pymeasurement.SigFig(value, sigfigs=None, decimals=None, constant=False)[source]#
A class for representing numbers with significant figures. SigFig objects are immutable. Internally, all numbers are stored as Decimal objects (fixed point numbers) for extra accuracy and precision. The central paradigm of this class is that the decimal value is the true value of the number, and the sigfigs and decimals are the precision of the number. The sigfigs and decimals are used to determine the precision of the number when it is printed.
- Parameters:
value (str) – The value of the number as a string.
sigfigs (int or None) – The number of significant figures to use when printing the number. If None, the number of significant figures will be automatically determined.
decimals (int or None) – The number of decimal places to use when printing the number. If None, the number of decimal places will be automatically determined.
constant (bool) – If True, the number will be assumed to be perfectly accurate for all calculations. If False, the number will be assumed to have some precision that must be followed.
- __add__(other)[source]#
Returns the sum of the two SigFig objects as a new SigFig object, following the rules of significant figures.
- __eq__(other)[source]#
Checks if the two SigFig objects are equal.
- Parameters:
other (SigFig) – The other SigFig object to compare to this one.
- Returns:
True if the two SigFig objects are equal.
- Return type:
bool
- __ge__(other)[source]#
Checks if the SigFig object is greater than or equal to the other SigFig object.
- Parameters:
other (SigFig) – The other SigFig object to compare to this one.
- Returns:
True if the SigFig object is greater than or equal to the other SigFig object.
- Return type:
bool
- __gt__(other)[source]#
Checks if the SigFig object is greater than the other SigFig object.
- Parameters:
other (SigFig) – The other SigFig object to compare to this one.
- Returns:
True if the SigFig object is greater than the other SigFig object.
- Return type:
bool
- __hash__ = None#
- __le__(other)[source]#
Checks if the SigFig object is less than or equal to the other SigFig object.
- Parameters:
other (SigFig) – The other SigFig object to compare to this one.
- Returns:
True if the SigFig object is less than or equal to the other SigFig object.
- Return type:
bool
- __lt__(other)[source]#
Checks if the SigFig object is less than the other SigFig object.
- Parameters:
other (SigFig) – The other SigFig object to compare to this one.
- Returns:
True if the SigFig object is less than the other SigFig object.
- Return type:
bool
- __mul__(other)[source]#
Returns the product of the two SigFig objects as a new SigFig object, following the rules of significant figures.
- __neg__()[source]#
Returns the negative of the SigFig object.
- Returns:
The negative of the SigFig object.
- Return type:
- __radd__(other)[source]#
Returns the sum of the two SigFig objects as a new SigFig object, following the rules of significant figures.
- __repr__()[source]#
Returns the string representation of the SigFig object.
- Returns:
The string representation of the SigFig object.
- Return type:
str
- __rmul__(other)[source]#
Returns the product of the two SigFig objects as a new SigFig object, following the rules of significant figures.
- __rsub__(other)[source]#
Returns the difference of the two SigFig objects as a new SigFig object, following the rules of significant figures.
- __rtruediv__(other)[source]#
Returns the quotient of the two SigFig objects as a new SigFig object, following the rules of significant figures.
- __str__()[source]#
Returns the string representation of the SigFig object.
- Returns:
The string representation of the SigFig object.
- Return type:
str
- __sub__(other)[source]#
Returns the difference of the two SigFig objects as a new SigFig object, following the rules of significant figures.
- __truediv__(other)[source]#
Returns the quotient of the two SigFig objects as a new SigFig object, following the rules of significant figures.
- __weakref__#
list of weak references to the object (if defined)
- abs()[source]#
Returns the absolute value of the SigFig object.
- Returns:
The absolute value of the SigFig object.
- Return type: