16.1 Elementary Operations for Rationals

  • IsRat( obj ) C

    Every rational number lies in the category IsRat, which is a subcategory of IsCyc (see Cyclotomic Numbers).

    gap> IsRat( 2/3 );
    true
    gap> IsRat( 17/-13 );
    true
    gap> IsRat( 11 );
    true
    gap> IsRat( IsRat );
    false    # `IsRat' is a function, not a rational
    

  • IsPosRat( obj ) C

    Every positive rational number lies in the category IsPosRat.

  • IsNegRat( obj ) C

    Every negative rational number lies in the category IsNegRat.

  • NumeratorRat( rat ) F

    NumeratorRat returns the numerator of the rational rat. Because the numerator holds the sign of the rational it may be any integer. Integers are rationals with denominator 1, thus NumeratorRat is the identity function for integers.

    gap> NumeratorRat( 2/3 );
    2
    gap> NumeratorRat( 66/123 );
    22    # numerator and denominator are made relatively prime
    gap> NumeratorRat( 17/-13 );
    -17    # the numerator holds the sign of the rational
    gap> NumeratorRat( 11 );
    11    # integers are rationals with denominator 1
    

  • DenominatorRat( rat ) F

    DenominatorRat returns the denominator of the rational rat. Because the numerator holds the sign of the rational the denominator is always a positive integer. Integers are rationals with the denominator 1, thus DenominatorRat returns 1 for integers.

    gap> DenominatorRat( 2/3 );
    3
    gap> DenominatorRat( 66/123 );
    41    # numerator and denominator are made relatively prime
    gap> DenominatorRat( 17/-13 );
    13    # the denominator holds the sign of the rational
    gap> DenominatorRat( 11 );
    1    # integers are rationals with denominator 1
    

  • Rat( elm ) A

    Rat returns a rational number rat whose meaning depends on the type of elm.

    If elm is a string consisting of digits '0', '1', ¼, '9' and '-' (at the first position), '/' and the decimal dot '.' then rat is the rational described by this string. The operation String (see String) can be used to compute a string for rational numbers, in fact for all cyclotomics.

    gap> Rat( "1/2" );  Rat( "35/14" );  Rat( "35/-27" );  Rat( "3.14159" );
    1/2
    5/2
    -35/27
    314159/100000
    

    [Top] [Up] [Index]

    GAP 4 manual
    February 2000