# Purple Sage Computing Solutions, Inc.

Home --> Fact Sheet --> Free Source Code --> type_rational

The module type_rational defines a type rational containing two 32 bit integers. This module includes arithmetic and logical operators and extends some intrinsic procedures to operate on objects of type rational. This module uses module standard_types, which may be obtained from the Portability Project pages.

A list of (most) constants and procedures defined follows.

Operators
= is extended to allow conversion between a type rational value and an integer array of size two.
+ and - unary operators providing identity and negation, and returning values of type rational.
.inverse. and .reduce. unary operators providing inverse and reduction to lowest terms.
+, -, * and / are binary operators, returning values of type rational.
.eq., .ne., .lt., .le., .ge. and .gt. are binary operators returning a logical value.
Library
rat() converts its integer input to type rational.
int() truncates its rational input to integer.
nint() converts its rational input to the closest integer.
real() converts its rational input to type real.
sign() returns an integer with the sign of a rational.
abs() returns a rational with positive value.
huge(), tiny() and epsilon() return the largest rational value, the smallest rational value or the smallest rational value which may be added to unity to get a value different from unity.
numerator() and denominator() return the numerator or denominator or a type rational entity.
is_finite(), is_infinity() and is_nan() return logical values characterizing their rational arguments.
inverse() returns the rational inverse of its rational argument.
reduce() returns a rational value equal to its rational argument reduced to lowest terms.
swap() swaps its rational arguments.
bit_size() returns the bit size of its rational argument.