Division¶
Fractional and rational numbers
can be divided using the /
operator. For example:
Disco> 1 / 5
1/5
Disco> (2/3) / (7/5)
10/21
It is not possible to divide natural numbers or integers since those numeric types have no concept of fractions; however, in many situations, if you divide natural numbers or integers they will be automatically converted to fractionals or rationals as appropriate:
Disco> :type 1 * (-2)
1 * (-2) : ℤ
Disco> :type 1 / (-2)
1 / (-2) : ℚ
Some related operations:
- If you want only the quotient when dividing (i.e. the integer number of times one thing fits into another, disregarding any remainder), you can use integer division.
- If you want the remainder instead, you can use the mod operator.
- If you just want to test whether one number evenly divides another, you should use the divides operator.