Home Online Manual
Top
Back: number expressions
Forward: number related functions
FastBack: module
FastForward: package
Up: number
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

4.13.3 number operations

+
addition
-
negation or subtraction
*
multiplication
/
division
%, mod
modulo
^, **
power, exponentiation (by an integer)
<=, >=, ==, <>
comparison
mod
integer modulo (the remainder of the division div), always non-negative

Note: Quotient and exponentiation is only recognized as a number expression if it is already a number, see Miscellaneous oddities.
For the behavior of comparison operators in rings with ground field different from real or the rational numbers, see boolean expressions.


Example:

 
  ring r=0,x,dp;
  number n = 1/2 +1/3;
  n;
==> 5/6
  n/2;
==> 5/12
  1/2/3;
==> 1/6
  1/2 * 1/3;
==> 1/6
  n = 2;
  n^-2;
==> 1/4
  // the following oddities appear here
  2/(2+3);
==> // ** int division with `/`: use `div` instead in line >>  2/(2+3);<<
==> 0
  number(2)/(2+3);
==> 2/5
  2^-2; // for int's exponent must be non-negative
==>    ? exponent must be non-negative
==>    ? error occurred in or before ./examples/number_operations.sing line 1\
   2: `  2^-2; // for int's exponent must be non-negative`
  number(2)^-2;
==> 1/4
  3/4>=2/5;
==> 1
  2/6==1/3;
==> 1