summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/genmisc/longdiv.tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2006-01-12 23:46:03 +0000
committerKarl Berry <karl@freefriends.org>2006-01-12 23:46:03 +0000
commit873660d1a83ece926fe7206288dda9c36b349c1b (patch)
treea48f77125c309a355b5d0eb58d6b24446abe9d62 /Master/texmf-dist/tex/generic/genmisc/longdiv.tex
parent2939242967231097459df0fc3150fabc2f639111 (diff)
generic 1
git-svn-id: svn://tug.org/texlive/trunk@613 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/genmisc/longdiv.tex')
-rw-r--r--Master/texmf-dist/tex/generic/genmisc/longdiv.tex53
1 files changed, 53 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/generic/genmisc/longdiv.tex b/Master/texmf-dist/tex/generic/genmisc/longdiv.tex
new file mode 100644
index 00000000000..4c9a1d4fd16
--- /dev/null
+++ b/Master/texmf-dist/tex/generic/genmisc/longdiv.tex
@@ -0,0 +1,53 @@
+% longdiv.tex v.1 (1994) Donald Arseneau
+%
+% Work out and print integer long division problems. Use:
+% \longdiv{numerator}{denominator}
+% The numerator and denominator (divisor and dividend) must be integers, and
+% the quotient is an integer too. \longdiv leaves a remainder.
+% Use this in any type of TeX.
+
+\newcount\gpten % (global) power-of-ten -- tells which digit we are doing
+\countdef\rtot2 % running total -- remainder so far
+\countdef\LDscratch4 % scratch
+
+\def\longdiv#1#2{%
+ \vtop{\normalbaselines \offinterlineskip
+ \setbox\strutbox\hbox{\vrule height 2.1ex depth .5ex width0ex}%
+ \def\showdig{$\underline{\the\LDscratch\strut}$\cr\the\rtot\strut\cr
+ \noalign{\kern-.2ex}}%
+ \global\rtot=#1\relax
+ \count0=\rtot\divide\count0by#2\edef\quotient{\the\count0}%\show\quotient
+ % make list macro out of digits in quotient:
+ \def\temp##1{\ifx##1\temp\else \noexpand\dodig ##1\expandafter\temp\fi}%
+ \edef\routine{\expandafter\temp\quotient\temp}%
+ % process list to give power-of-ten:
+ \def\dodig##1{\global\multiply\gpten by10 }\global\gpten=1 \routine
+ % to display effect of one digit in quotient (zero ignored):
+ \def\dodig##1{\global\divide\gpten by10
+ \LDscratch =\gpten
+ \multiply\LDscratch by##1%
+ \multiply\LDscratch by#2%
+ \global\advance\rtot-\LDscratch \relax
+ \ifnum\LDscratch>0 \showdig \fi % must hide \cr in a macro to skip it
+ }%
+ \tabskip=0pt
+ \halign{\hfil##\cr % \halign for entire division problem
+ $\quotient$\strut\cr
+ #2$\,\overline{\vphantom{\big)}%
+ \hbox{\smash{\raise3.5\fontdimen8\textfont3\hbox{$\big)$}}}%
+ \mkern2mu \the\rtot}$\cr\noalign{\kern-.2ex}
+ \routine \cr % do each digit in quotient
+}}}
+
+\endinput % Demonstration below:
+
+\noindent Here are some long division problems
+
+\indent
+\longdiv{12345}{13} \quad
+\longdiv{123}{1234} \quad
+\longdiv{31415926}{2} \quad
+\longdiv{81}{3} \quad
+\longdiv{1132}{99} \quad
+\longdiv{86491}{94}
+\bye