ordec.core.rational — Rational numbers

ORDeC represents coordinates of schematics internally as ordec.core.rational.Rational. So far, it seems like this was a good idea, as it prevents the mess of floating-point number comparisons. For example, we can use them as (hashable) dictionary keys to find connectivity in sanitize_schematic. Also, the limitations and problems of having to define library units are absent.

It is not clear yet whether this approach will also be used for layout data.

class ordec.core.rational.Rational(number=0, denominator=None)

This class is meant to offer a convenient and exact numeric data type for circuit design, where decimal exponents vary greatly (e.g. megaohm resistances, nanometer transistor parameters and distances in layout.)

It extends fractions.Fraction from Python’s standard library:

  • The constructor supports the new format “f’[numerator]/[denominator]”, e.g.: Rational(“f’15/19”).

  • The constructor supports SI suffixes as alternative to decimal exponents, e.g.: Rational(“100n”), Rational(“12.345G”).

  • str() shows Rational objects as decimal fractions when possible and automatically selects an SI suffix such that the non-fractional part is greater or equal 1 and less than 1000. If the fractional part is zero, the trailing decimal point is kept. If the decimal fraction is not finite, the format “f’[numerator]/[denominator]” is used.

  • repr() yields a different format, i.e. “R(…)”

ordec.core.rational.R

alias of Rational