3.4: Rational and Complex Numbers

Scientific Computing · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under not declared, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    3.4: Rational and Complex Numbers
    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.