Summary
###########################################################################
File: rational.icn
Subject: Procedures for arithmetic on rational numbers
Author: Ralph E. Griswold
Date: June 10, 2001
###########################################################################
This file is in the public domain.
###########################################################################
Contributor: Gregg M. Townsend
###########################################################################
These procedures perform arithmetic on rational numbers (fractions):
addrat(r1,r2) Add rational numbers r1 and r2.
divrat(r1,r2) Divide rational numbers r1 and r2.
medrat(r1,r2) Form mediant of r1 and r2.
mpyrat(r1,r2) Multiply rational numbers r1 and r2.
negrat(r) Produce negative of rational number r.
rat2real(r) Produce floating-point approximation of r
rat2str(r) Convert the rational number r to its string
representation.
real2rat(v,p) Convert real to rational with precision p.
The default precision is 1e-10.
(Too much precision gives huge, ugly factions.)
reciprat(r) Produce the reciprocal of rational number r.
str2rat(s) Convert the string representation of a rational number
(such as "3/2") to a rational number.
subrat(r1,r2) Subtract rational numbers r1 and r2.
###########################################################################
Links: numbers
###########################################################################
Procedures:
addrat, divrat, medrat, mpyrat, negrat, rat2real, rat2str, ratred, real2rat, reciprat, str2rat, subrat
Records:
rational
Links:
numbers.icn
This file is part of the (main) package.
Source code.
addrat(r1, r2)
: sum of rationals
divrat(r1, r2)
: divide rationals.
medrat(r1, r2)
: form rational mediant
mpyrat(r1, r2)
: multiply rationals
negrat(r)
: negative of rational
rat2real(r)
: floating-point approximation of rational
rat2str(r)
: convert rational to string
ratred(r)
: reduce rational to lowest terms
real2rat(r, p)
: convert to rational with precision p
reciprat(r)
: reciprocal of rational
str2rat(s)
convert string to rational
subrat(r1, r2)
: difference of rationals
rational(numer, denom, sign)
This page produced by UniDoc on 2021/04/15 @ 23:59:54.