%% Hideki ISOZAKI isozaki@expert-sun.ntt.junet
%% December 2, 1987
%% $@@5$N@0?t$r4A?t;z$K$9$k(J $@$?$@$7!$(J$2^{31}$ $@0J2<(J
%%
\global\newcount\residu@l
\global\newcount\qu@tient
\global\newcount\residu@lf
\global\newcount\qu@tientf
\def\kansuuji#1{\kanjinumeral{\@nameuse{c@#1}}}
\def\kanjinumeral{\@ifstar{\let\kanji@one=\old@one\gdef\kanji@ten{$@=&(J}%
\gdef\kanji@man{$@h_(J}\let\kanji@two=\old@two\k@njinumeral}%
{\let\kanji@one=\new@one\gdef\kanji@ten{$@==(J}\gdef\kanji@man{$@K|(J}%
\let\kanji@two=\new@two\k@njinumeral}}
\def\k@njinumeral#1{%
\residu@lf#1%
\qu@tientf#1%
%
\divide\qu@tientf by 100000000%
\kanji@sen{\qu@tientf}\ifnum\qu@tientf>0{$@2/(J}\fi%
\multiply\qu@tientf by 50000000%
\advance\qu@tientf by \qu@tientf%  Trick to Avoid Overflow
\advance\residu@lf by -\qu@tientf%
\qu@tientf\residu@lf%
%
\divide\qu@tientf by 10000%
\kanji@sen{\qu@tientf}\ifnum\qu@tientf>0{\kanji@man}\fi%
\multiply\qu@tientf by 10000%
\advance\residu@lf by -\qu@tientf%
\qu@tientf\residu@lf%
%
\kanji@sen{\qu@tientf}
}

\def\kanji@sen#1{%
\residu@l#1%
\qu@tient#1%
%
\divide\qu@tient by 1000 % This space seems important
\kanji@one{\qu@tient}\ifnum\qu@tient>0{$@@i(J}\fi%
\multiply\qu@tient by 1000%
\advance\residu@l by -\qu@tient%
\qu@tient\residu@l%
%
\divide\qu@tient by 100 % This space seems important
\kanji@two{\qu@tient}\ifnum\qu@tient>0{$@I4(J}\fi%
\multiply\qu@tient by 100%
\advance\residu@l by -\qu@tient%
\qu@tient\residu@l%
%
\divide\qu@tient by 10 % This space seems important
\kanji@two{\qu@tient}\ifnum\qu@tient>0{\kanji@ten}\fi%
\multiply\qu@tient by 10%
\advance\residu@l by -\qu@tient%
\qu@tient\residu@l%
%
\kanji@one{\qu@tient}%
}%
%
\def\new@two#1{\ifcase#1\or\or $@Fs(J\or $@;0(J\or $@;M(J\or $@8^(J\or%
$@O;(J\or $@<7(J\or $@H,(J\or $@6e(J\else\@ctrerr\fi}%
\def\new@one#1{\ifcase#1\or $@0l(J\or $@Fs(J\or $@;0(J\or $@;M(J\or $@8^(J\or%
$@O;(J\or $@<7(J\or $@H,(J\or $@6e(J\else\@ctrerr\fi}%
\def\old@two#1{\ifcase#1\or\or $@Fu(J\or $@;2(J\or $@;M(J\or $@8^(J\or%
$@O;(J\or $@<7(J\or $@H,(J\or $@6e(J\else\@ctrerr\fi}%
\def\old@one#1{\ifcase#1\or $@0m(J\or $@Fu(J\or $@;2(J\or $@;M(J\or $@8^(J\or%
$@O;(J\or $@<7(J\or $@H,(J\or $@6e(J\else\@ctrerr\fi}%


% The first 18 characters of I-RO-HA
\def\iroha#1{\@iroha{\@nameuse{c@#1}}}
\def\@iroha#1{\ifcase#1\or $@%$(J\or $@%m(J\or $@%O(J\or $@%K(J\or $@%[(J\or $@%X(J\or $@%H(J\or
$@%A(J\or $@%j(J\or $@%L(J\or$@%k(J\or $@%r(J\or $@%o(J\or $@%+(J\or $@%h(J\or $@%?(J\or $@%l(J\or $@%=(J\else\@ctrerr\fi}


% Jikkan-Juunishi (ETO)
\def\jikkan#1{\ifcase#1\or $@9C(J\or $@25(J\or $@J:(J\or $@Cz(J\or $@Jj(J\or $@8J(J\or $@9.(J\or
$@?I(J\or $@?Q(J\or $@b#(J\else\@ctrerr\fi}
\def\juunishi#1{\ifcase#1\or $@;R(J\or $@1/(J\or $@FR(J\or $@1,(J\or $@C$(J\or $@L&(J\or
$@8a(J\or $@L$(J\or $@?=(J\or $@FS(J\or $@X|(J\or $@0g(J\else\@ctrerr\fi}

