Skip to main content
Mathematics LibreTexts

3.4: Rational and Complex Numbers

  • Page ID
    63977
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    2//3
    -4//7
    178//11
    8//18
     

    One advantage that they have is that the numerator and denominator are stored as integers (64-bit by default) and are not subject to round-off errors that floating points are. The standard operations +, −, ·, ÷ between rationals results in a rational and as we will see in this course, there are advantages to using rationals instead of floating points.

    Exercise

    • \(\dfrac{1}{2} + \dfrac{2}{3}\)

    • \(\dfrac{1}{2} - \dfrac{2}{3}\)

    • \(\dfrac{2}{3} \cdot \dfrac{3}{5}\)
    • \(\dfrac{2}{3} \div \dfrac{3}{5}\)
    # insert your code here.
     

    The Rational Type

    If you enter 

    typeof(1//2)
     

    is called a Parametric Composite Type, which will be talked about later. In this particular case, this is a rational type, but inside it (the numerator and denominator), they are type Int64.

    For example, to make a different type of rational you need to declare a different integer type inside, enter

    Int16(1)//Int16(3)
     

     


    3.4: Rational and Complex Numbers is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?