14.1 Elementary Operations for Integers

  • IsInt( obj ) C

    Every rational integer lies in the category IsInt, which is a subcategory of IsRat (see Rational Numbers).

  • IsPosInt( obj ) C

    Every positive integer lies in the category IsPosInt.

  • Int( elm ) A

    Int returns an integer int whose meaning depends on the type of elm.

    If elm is a rational number (see Rational Numbers) then int is the integer part of the quotient of numerator and denominator of elm (see QuoInt).

    If elm is an element of a finite prime field (see Chapter Finite Fields) then int is the smallest nonnegative integer such that elm = int * One( elm ).

    If elm is a string (see Chapter Strings and Characters) consisting of digits '0', '1', ¼, '9' and '-' (at the first position) then int is the integer described by this string. The operation String (see String) can be used to compute a string for rational integers, in fact for all cyclotomics.

    gap> Int( 4/3 );  Int( -2/3 );
    1
    0
    gap> int:= Int( Z(5) );  int * One( Z(5) );
    2
    Z(5)
    gap> Int( "12345" );  Int( "-27" );  Int( "-27/3" );
    12345
    -27
    fail
    

  • IsEvenInt( n ) F

    tests if the integer n is divisible by 2.

  • IsOddInt( n ) F

    tests if the integer n is not divisible by 2.

  • AbsInt( n ) F

    AbsInt returns the absolute value of the integer n, i.e., n if n is positive, -n if n is negative and 0 if n is 0.

    AbsInt is a special case of the general operation EuclideanDegree see EuclideanDegree).

    gap> AbsInt( 33 );
    33
    gap> AbsInt( -214378 );
    214378
    gap> AbsInt( 0 );
    0
    

  • SignInt( n ) F

    SignInt returns the sign of the integer n, i.e., 1 if n is positive, -1 if n is negative and 0 if n is 0.

    gap> SignInt( 33 );
    1
    gap> SignInt( -214378 );
    -1
    gap> SignInt( 0 );
    0
    

  • LogInt( n, base ) F

    LogInt returns the integer part of the logarithm of the positive integer n with respect to the positive integer base, i.e., the largest positive integer exp such that baseexp £ n. LogInt will signal an error if either n or base is not positive.

    gap> LogInt( 1030, 2 );
    10        # 2^10 = 1024
    gap> LogInt( 1, 10 );
    0
    

  • RootInt( n ) F
  • RootInt( n, k ) F

    RootInt returns the integer part of the kth root of the integer n. If the optional integer argument k is not given it defaults to 2, i.e., RootInt returns the integer part of the square root in this case.

    If n is positive, RootInt returns the largest positive integer r such that rk £ n. If n is negative and k is odd RootInt returns -RootInt( -n, k ). If n is negative and k is even RootInt will cause an error. RootInt will also cause an error if k is 0 or negative.

    gap> RootInt( 361 );
    19
    gap> RootInt( 2 * 10^12 );
    1414213
    gap> RootInt( 17000, 5 );
    7        # 7^5 = 16807
    

  • SmallestRootInt( n ) F

    SmallestRootInt returns the smallest root of the integer n.

    The smallest root of an integer n is the integer r of smallest absolute value for which a positive integer k exists such that n = rk.

    gap> SmallestRootInt( 2^30 );
    2
    gap> SmallestRootInt( -(2^30) );
    -4        # note that $(-2)^{30} = +(2^{30})$
    gap> SmallestRootInt( 279936 );
    6
    gap> LogInt( 279936, 6 );
    7
    gap> SmallestRootInt( 1001 );
    1001
    

    [Top] [Up] [Next] [Index]

    GAP 4 manual
    February 2000