class interface RATIONAL

creation

make_rational (num: INTEGER; denom: INTEGER)

— Current will be reduced, if it is not already

require

denom /= 0

feature(s) from HASHABLE

hash_code: INTEGER

— The hash-code value of Current.

ensure

good_hash_value: Result >= 0

feature(s) from NUMERIC

infix "+" (other: RATIONAL): RATIONAL

— Current + other

infix "-" (other: RATIONAL): RATIONAL

— Current - other

infix "*" (other: RATIONAL): RATIONAL

— Current * other

infix "/" (other: like Current): NUMERIC

— Division by other.

require

other /= Void;

divisible(other)

prefix "+": like Current

— Unary plus of Current.

prefix "-": RATIONAL

— returns the opposite of Current

divisible (other: like Current): BOOLEAN

— May Current be divided by other ?

require

other /= Void

one: RATIONAL

— returns 1 in RATIONAL format
— there ought to be a better way to create 1 than this

zero: RATIONAL

— returns 0 in RATIONAL format
— there ought to be a better way to create 0 than this

sign: INTEGER_8

— result is compatible with predecessor

ensure

-1 <= Result;

Result <= 1

feature(s) from RATIONAL

numerator: INTEGER

denominator: INTEGER

make_rational (num: INTEGER; denom: INTEGER)

— Current will be reduced, if it is not already

require

denom /= 0

set_fraction (num: INTEGER; denom: INTEGER)

— Current will be reduced, if it is not already

require

denom /= 0

print_text

— Fomat: numerator / denominator

print_latex

— format: \frac{numerator}{denominator}

deep_copy: RATIONAL

— makes a completely new rational number, with the same value as this one

ensure

Current.is_equal(Result)

feature(s) from RATIONAL

reciprocal: RATIONAL

— 1/Current

infix "#^" (power: INTEGER): RATIONAL

— Current raised to the power

infix "//" (other: RATIONAL): RATIONAL

— Current / other; used // to maintain consistency with eiffel notation

infix ">" (other: RATIONAL): BOOLEAN

— Current > other?

infix "<" (other: RATIONAL): BOOLEAN

— Current < other?

is_equal (other: RATIONAL): BOOLEAN

— Current = other?

require

other /= Void

ensure

generating_type = other.generating_type implies Result = other.is_equal(Current)

is_one: BOOLEAN

— Current = 1?

is_zero: BOOLEAN

— Current = 0?

invariant

denominator > 0;

end of RATIONAL