| 1 |
package Rational_Arithmetic is |
| 2 |
-- Whole numbers |
| 3 |
type Whole is new Integer; |
| 4 |
-- |
| 5 |
-- Undefine unwanted operations |
| 6 |
function "/" (Left, Right: Whole) return Whole is abstract; |
| 7 |
-- |
| 8 |
-- Rational numbers |
| 9 |
-- |
| 10 |
type Rational is private; |
| 11 |
-- |
| 12 |
-- Constructors |
| 13 |
-- |
| 14 |
function "/" (Left, Right: Whole) return Rational; |
| 15 |
-- |
| 16 |
-- Rational operations |
| 17 |
-- |
| 18 |
function "-" (Left, Right: Rational) return Rational; |
| 19 |
-- |
| 20 |
-- Mixed operations |
| 21 |
-- |
| 22 |
function "+" (Left: Whole ; Right: Rational) return Rational; |
| 23 |
function "-" (Left: Whole ; Right: Rational) return Rational; |
| 24 |
function "-" (Left: Rational; Right: Whole ) return Rational; |
| 25 |
function "/" (Left: Whole ; Right: Rational) return Rational; |
| 26 |
function "*" (Left: Whole ; Right: Rational) return Rational; |
| 27 |
function "*" (Left: Rational; Right: Whole ) return Rational; |
| 28 |
-- |
| 29 |
-- Relational |
| 30 |
-- |
| 31 |
function "=" (Left: Rational; Right: Whole) return Boolean; |
| 32 |
-- |
| 33 |
private |
| 34 |
type Rational is record |
| 35 |
Numerator, Denominator: Whole; |
| 36 |
end record; |
| 37 |
end Rational_Arithmetic; |