File numbers.icn

Summary

###########################################################################

	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

###########################################################################
Procedures:
adp, adr, amean, ceil, commas, decimal, decipos, digprod, digred, digroot, digsum, distseq, div, fix, floor, frn, gcd, gcdl, gmean, hmean, large, lcm, lcml, mantissa, mceil, mdp, mdr, mfloor, mod1, npalins, residue, roman, round, sigma, sign, spell, sum, trunc, unroman

Links:
factors.icn, strings.icn

This file is part of the (main) package.

Source code.

Details
Procedures:

adp(i)

: additive digital persistence


adr(i)

: additive digital root


amean(L)

: arithmetic mean


ceil(r)

: ceiling


commas(s)

: insert commas in number


decimal(i, j)

: decimal expansion of rational


decipos(r, i, j)

: position decimal point


digprod(i)

: product of digits


digred(i)

: sum digits of integer repeated to one digit


digroot(i)

: digital root


digsum(i)

: sum of digits


distseq(low, high)

: generate low to high nonsequentially


div(i, j)

: real division


fix(i, j, w, d)

: format real number


floor(r)

: floor


frn(r, w, d)

: format real number


gcd(i, j)

: greatest common divisor


gcdl(L)

: greatest common divisor of list


gmean(L)

: geometric mean


hmean(L)

: harmonic mean


large(i)


 The procedure above isn't thread safe because, if another thread
 makes a storage allocation between the two uses of &allocate,
 it might report that a small integer is a large integer.

 Updated return value on success to return the value supplied as per
 the procedure large() above.

: detect large integers


lcm(i, j)

: least common multiple


lcml(L)

: least common multiple of list


mantissa(r)

: mantissa (fractional part)


mceil(r)

: mceiling


mdp(i)

: multiplicative digital persistence


mdr(i)

: multiplicative digital root


mfloor(r)

: mfloor


mod1(i, m)

: modulus for 1-based integers


npalins(n)

: palindromic numbers


residue(i, m, j)

: residue for j-based integers


roman(n)

  This procedure is based on a SNOBOL4 function written by Jim Gimpel.

: convert integer to Roman numeral


round(r)

: round real


sigma(i)

: synonym for digroot()


sign(r)

: sign


spell(n)

: spell out integer


sum(values)

: sum of numbers


trunc(r)

: truncate real


unroman(s)

: convert Roman numeral to integer



This page produced by UniDoc on 2021/04/15 @ 23:59:54.