polymerist.maths.fractions.ratios

For representing rational numbers, and more general ratios

Attributes

N

Classes

Ratio

For representing fractional ratios between two objects

Rational

For representing ratios of integers

Functions

sgnmag(→ tuple[bool, N])

Returns the sign and magnitude of a numeric-like value

Module Contents

polymerist.maths.fractions.ratios.N
polymerist.maths.fractions.ratios.sgnmag(num: N) tuple[bool, N][source]

Returns the sign and magnitude of a numeric-like value

class polymerist.maths.fractions.ratios.Ratio[source]

For representing fractional ratios between two objects

num: Any
denom: Any
to_latex() str[source]

Return latex-compatible string which represent fraction

property reciprocal: Ratio

Return the reciprocal of a ration

class polymerist.maths.fractions.ratios.Rational[source]

Bases: Ratio

For representing ratios of integers

num: int
denom: int
autoreduce: ClassVar[bool] = False
reduce() None[source]

Reduce numerator and denominator by greatest common factor

simplify
property reduced: Rational

Return reduced Rational equivalent to the current rational (does not modify in-place)

simplifed
as_proper() tuple[int, Rational][source]

Returns the integer and proper fractional component of a ratio