###########################################################################
File: numbers.icn
Subject: Procedures related to numbers
Author: Ralph E. Griswold
Date: June 10, 2001
Modified: Bruce Rennie
Date: August 13, 2020
###########################################################################
This file is in the public domain.
###########################################################################
Contributors: Robert J. Alexander, Richard Goerwitz
Tim Korb, and Gregg M. Townsend
May 08, 2019: add mfloor() and mceil() functions
Nov 15, 2019: add thread-safe large() function
Aug 13, 2020: fix thread-safe large() function to return parameter
###########################################################################
These procedures deal with numbers in various ways:
adp(i) additive digital persistence of i
adr(i) additive digital root of i (same as digred())
amean ! L returns arithmetic mean of numbers in L.
ceil(r) returns nearest integer to r away from 0.
mceil(r) returns the least integer greater than or equal to r.
commas(s) inserts commas in s to separate digits into groups of
three.
decimal(i, j) decimal expansion of i / j; terminates when expansion
terminates or the end of a recurring period is reached.
The format of the returned value is <integer>.<seq>,
where <seq> is a string a decimal digits if the
expansion is finite but [<recurr>] if it
is not, where is a string of decimal digits
(possibly empty) before the recurring part.
decipos(r, i, j)
positions decimal point at i in real number r in
field of width j.
digprod(i) product of digits of i
digred(i) reduction of number by adding digits until one digit is
reached.
digroot(i) same as digred().
digsum(i) sum of digits in i.
distseq(i, j) generates i to j in distributed order.
div(i, j) produces the result of real division of i by j.
fix(i, j, w, d) formats i / j as a real (floating-point) number in
a field of width w with d digits to the right of
the decimal point, if possible. j defaults to 1,
w to 8, and d to 3. If w is less than 3 it is set
to 3. If d is less than 1, it is set to 1. The
function fails if j is 0 or if the number cannot
be formatted.
floor(r) nearest integer to r toward 0.
mfloor(r) returns the greatest integer less than or equal to r.
frn(r, w, d) format real number r into a string with d digits
after the decimal point; a result narrower than w
characters is padded on the left with spaces.
Fixed format is always used; there is no exponential
notation. Defaults: w 0, d 0
gcd(i, j) returns greatest common divisor of i and j.
gcdl ! L returns the greatest common division of the integers
list L.
gmean ! L returns geometric mean of numbers in L.
hmean ! L returns harmonic mean of numbers in L.
large(i) succeeds if i is a large integer but fails otherwise.
lcm(i, j) returns the least common multiple of i and j.
lcml ! L returns the least common multiple of the integers
in the list L.
mantissa(r) mantissa (fractional part) of r.
max ! L produces maximum of numbers in L.
mdp(i) multiplicative digital persistence of i
mdr(i) multiplicative digital root of i
min ! L produces minimum of numbers in L.
mod1(i, m) residue for 1-based indexing.
npalins(n) generates palindromic n-digit numbers.
residue(i, m, j)
residue for j-based indexing.
roman(i) converts i to Roman numerals.
round(r) returns nearest integer to r.
sigma(i) synonym for digroot(i)
sign(r) returns sign of r.
spell(i) spells out i in English.
sum ! L sum of numbers in list L
trunc(r) returns nearest integer to r toward 0
unroman(s) converts Roman numerals to integers.
###########################################################################
Links: factors, strings
###########################################################################