Top
Back: 4.3.1 int declarations
Forward: 4.3.3 int operations
FastBack: 4. Data types
FastForward: 5. Functions and system variables
Up: 4.3 int
Top: Singular 2-0-4 Manual
Contents: Table of Contents
Index: F. Index
About: About This Document

4.3.2 int expressions

An int expression is:

  1. a sequence of digits (if the number represented by this sequence is too large to fit into the range of integers it is automatically converted to the type number, if a basering is defined)
  2. an identifier of type int
  3. a function returning int
  4. int expressions combined by the arithmetic operations +, -, *, div, /, % (mod), or ^
  5. a boolean expression
  6. a type cast to int

Note: Variables of type int represent the compiler integers and are, therefore, limited in their range (see Limitations). If this range is too small the expression must be converted to the type number over a ring with characteristic 0.


Example:

 
12345678901; // too large
→    ? `12345678901` greater than 2147483647(max. integer representation)
→    ? error occurred in line 1: `12345678901; // too large`
typeof(_);
→ none
ring r=0,x,dp;
12345678901;
→ 12345678901
typeof(_);
→ number
// Note: 11*13*17*100*200*2000*503*1111*222222
// returns a machine integer:
11*13*17*100*200*2000*503*1111*222222;
→ // ** int overflow(*), result may be wrong
→ // ** int overflow(*), result may be wrong
→ // ** int overflow(*), result may be wrong
→ // ** int overflow(*), result may be wrong
→ -1875651584
// using the type cast number for a greater allowed range
number(11)*13*17*100*200*2000*503*1111*222222;
→ 12075748128684240000000
ring rp=32003,x,dp;
12345678901;
→ 9603
typeof(_);
→ number
intmat m[2][2] = 1,2,3,4;
m;
→ 1,2,
→ 3,4 
m[2,2];
→ 4
typeof(_);
→ int
det(m);
→ -2
m[1,1] + m[2,1] == trace(m);
→ 0
! 0;
→ 1
1 and 2;
→ 1
intvec v = 1,2,3;
def d =transpose(v)*v;    // scalarproduct gives an 1x1 intvec
typeof(d);
→ intvec
int i = d[1];             // access the first (the only) entry in the intvec
ring rr=31,(x,y,z),dp;
poly f = 1;
i = int(f);               // cast to int
// Integers may be converted to constant  polynomials by an assignment,
poly g=37;
// define the constant polynomial g equal to the image of
// the integer 37 in the actual coefficient field, here it equals 6
g;
→ 6

See Type conversion and casting; number.


Top Back: 4.3.1 int declarations Forward: 4.3.3 int operations FastBack: 4. Data types FastForward: 5. Functions and system variables Up: 4.3 int Top: Singular 2-0-4 Manual Contents: Table of Contents Index: F. Index About: About This Document
            User manual for Singular version 2-0-4, October 2002, generated by texi2html.