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.

Parameters:

other (SigFig) – The other SigFig object to add to this one.

Returns:

The sum of the two SigFig objects as a new SigFig object.

Return type:

SigFig

__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#
__init__(value, sigfigs=None, decimals=None, constant=False)[source]#

SigFig Constructor

__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.

Parameters:

other (SigFig) – The other SigFig object to multiply by this one.

Returns:

The product of the two SigFig objects as a new SigFig object.

Return type:

SigFig

__neg__()[source]#

Returns the negative of the SigFig object.

Returns:

The negative of the SigFig object.

Return type:

SigFig

__radd__(other)[source]#

Returns the sum of the two SigFig objects as a new SigFig object, following the rules of significant figures.

Parameters:

other (SigFig) – The other SigFig object to add to this one.

Returns:

The sum of the two SigFig objects as a new SigFig object.

Return type:

SigFig

__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.

Parameters:

other (SigFig) – The other SigFig object to multiply by this one.

Returns:

The product of the two SigFig objects as a new SigFig object.

Return type:

SigFig

__rsub__(other)[source]#

Returns the difference of the two SigFig objects as a new SigFig object, following the rules of significant figures.

Parameters:

other (SigFig) – The other SigFig object to subtract from this one.

Returns:

The difference of the two SigFig objects as a new SigFig object.

Return type:

SigFig

__rtruediv__(other)[source]#

Returns the quotient of the two SigFig objects as a new SigFig object, following the rules of significant figures.

Parameters:

other (SigFig) – The other SigFig object to divide by this one.

Returns:

Other SigFig object divided by this one.

Return type:

SigFig

__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.

Parameters:

other (SigFig) – The other SigFig object to subtract from this one.

Returns:

The difference of the two SigFig objects as a new SigFig object.

Return type:

SigFig

__truediv__(other)[source]#

Returns the quotient of the two SigFig objects as a new SigFig object, following the rules of significant figures.

Parameters:

other (SigFig) – The other SigFig object to divide by this one.

Returns:

This SigFig object divided by the other SigFig object.

Return type:

SigFig

__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:

SigFig

changeSigFigs(sigfigs)[source]#

Changes the number of significant figures of a number.

Parameters:
  • value (str) – The value of the number as a string.

  • sigfigs (int) – The number of significant figures to use.

Returns:

The number with the new number of significant figures.

Return type:

Decimal

deepCopy()[source]#

Returns a deep copy of the SigFig object.

Returns:

A deep copy of the SigFig object.

Return type:

SigFig