justbases._rationals module

Methods dealing with rationals.

class justbases._rationals.Radices

Bases: object

Methods for Radices.

classmethod from_rational(value, to_base, precision=None, method=_RoundingMethod(Round down.))

Convert rational value to a base.

Parameters:
  • value (Rational) – the value to convert
  • to_base (int) – base of result, must be at least 2
  • precision (int or NoneType) – number of digits in total or None
  • method (element of RoundingMethods.METHODS()) – rounding method
Returns:

the conversion result and its relation to actual result

Return type:

Radix * int

Raises BasesValueError:
 

if to_base is less than 2

Complexity: Uncalculated.

class justbases._rationals.Radix(sign, integer_part, non_repeating_part, repeating_part, base, validate=True, canonicalize=True)

Bases: object

An object containing information about a rational representation.

Such values can not be ordered, but can be compared for equality.

as_int(method)

This value as an int, rounded according to method.

Parameters:method – rounding method
Raises BasesValueError:
 on bad parameters
Returns:corresponding int value
Return type:int
as_rational()

Return this value as a Rational.

Returns:this radix as a rational
Return type:Rational
getString(config, relation=0)

Return a representation of a Radix according to config.

Parameters:
  • config (DisplayConfig) – configuration
  • relation (int) – the relation of this value to actual value
in_base(base)

Return value in base.

Returns:Radix in base
Return type:Radix
Raises ConvertError:
 if base is less than 2
rounded(precision, method)

This value with fractional part rounded to precision digits according to method.

Parameters:
  • precision (int) – number of digits in total
  • method – rounding method
Raises BasesValueError:
 

on bad parameters

Precondition: Radix is valid and canonical

Complexity: O(len(components))

class justbases._rationals.Rationals

Bases: object

Miscellaneous methods for rationals.

static round_to_int(value, method)

Round value to an int according to method.

Parameters:
  • value (Rational) – the value to round
  • method – the rounding method (of RoundingMethods.METHODS())
Returns:

rounded value and relation of rounded value to actual value.

Return type:

(int * int)

Complexity: O(1)

Previous topic

justbases._nats module

Next topic

justbases.version module

This Page