summaryrefslogtreecommitdiff
path: root/ipl/procs/divide.icn
blob: feff85921d5eccd4a004026ae4151a5e0e4fdeae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
############################################################################
#
#	File:     divide.icn
#
#	Subject:  Procedure to perform long division
#
#	Author:   Ralph E. Griswold
#
#	Date:     March 29, 2000
#
############################################################################
#
#  This file is in the public domain.
#
############################################################################
#
#  Doesn't get the decimal point.  Not sure what the padding does;
#  to study.
#
############################################################################
#
#  Requires:  Large integer arithmetic, potentially
#
############################################################################

procedure divide(i, j, k)		# long division
   local q, pad

   /k := 5

   q := ""

   pad := 20

   i ||:= repl("0", pad)

   every 1 to k do {
      q ||:= i / j
      i %:= j
      if i = 0 then break
      }

   return q[1:-pad]

end