syst-con.mkiv /size: 3475 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=syst-con,
3%D        version=2006.09.16, % real old stuff ... 2000.12.10
4%D          title=\CONTEXT\ System Macros,
5%D       subtitle=Conversions,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\registerctxluafile{syst-con}{}
15
16\unprotect
17
18%D \macros{lchexnumber,uchexnumber,lchexnumbers,uchexnumbers}
19%D
20%D In addition to the uppercase hex conversion, as needed in math families, we
21%D occasionally need a lowercase one.
22
23\def\lchexnumber #1{\clf_lchexnumber \numexpr#1\relax}
24\def\uchexnumber #1{\clf_uchexnumber \numexpr#1\relax}
25\def\lchexnumbers#1{\clf_lchexnumbers\numexpr#1\relax}
26\def\uchexnumbers#1{\clf_uchexnumbers\numexpr#1\relax}
27
28\let\hexnumber\uchexnumber
29
30%D \macros{octnumber}
31%D
32%D For \UNICODE\ remapping purposes, we need octal numbers.
33
34\def\octnumber#1{\clf_octnumber\numexpr#1\relax}
35
36%D \macros{hexstringtonumber,octstringtonumber}
37%D
38%D This macro converts a two character hexadecimal number into a decimal number,
39%D thereby taking care of lowercase characters as well.
40
41\def\hexstringtonumber#1{\clf_hexstringtonumber\numexpr#1\relax}
42\def\octstringtonumber#1{\clf_octstringtonumber\numexpr#1\relax}
43
44%D \macros{rawcharacter}
45%D
46%D This macro can be used to produce proper 8 bit characters that we sometimes need
47%D in backends and round||trips.
48
49\def\rawcharacter#1{\clf_rawcharacter\numexpr#1\relax}
50
51%D \macros{twodigits, threedigits}
52%D
53%D These macros provides two or three digits always:
54
55\def\twodigits  #1{\ifnum             #1<10     0\fi\number#1}
56\def\threedigits#1{\ifnum#1<100 \ifnum#1<10 0\fi0\fi\number#1}
57
58%D \macros{modulonumber}
59%D
60%D In the conversion macros described in \type {core-con} we need a wrap||around
61%D method. The following solution is provided by Taco.
62%D
63%D The \type {modulonumber} macro expands to the mathematical modulo of a positive
64%D integer. It is crucial for it's application that this macro is fully exandable.
65%D
66%D The expression inside the \type {\numexpr} itself is somewhat bizarre because
67%D \ETEX\ uses a rounding division instead of truncation. If \ETEX's division would
68%D have behaved like \TEX's normal\type {\divide}, then the expression could have
69%D been somewhat simpler, like \type {#2-(#2/#1)*#1}. This works just as well, but a
70%D bit more complex.
71
72\def\modulonumber#1#2{\the\numexpr#2-((((#2+(#1/2))/#1)-1)*#1)\relax}
73
74%D \macros{modulatednumber}
75%D
76%D Modulo numbers run from zero to one less than the limit, but for conversion sets,
77%D we need a value between 1 and the limit. The \type {\modulatednumber} arranges
78%D that. This macro also needs to be fully expandable, resulting in two \type
79%D {\numexpr}s.
80
81\def\modulatednumber#1#2%
82  {\ifnum\the\numexpr\modulonumber{#1}{#2}\relax=0 #1%
83   \else \the\numexpr\modulonumber{#1}{#2}\relax  \fi}
84
85%D \macros{setcalculatedsin,setcalculatedcos,setcalculatedtan}
86
87\protected\def\setcalculatedsin#1#2{\edef#1{\clf_sind#2}}
88\protected\def\setcalculatedcos#1#2{\edef#1{\clf_cosd#2}}
89\protected\def\setcalculatedtan#1#2{\edef#1{\clf_tand#2}}
90
91%D \macros{formatted,format}
92
93          \def\formatted#1{\ctxcommand{format(#1)}} % not clf
94\protected\def\format   #1{\ctxcommand{format(#1)}} % not clf
95
96%D The \type {\modulatednumber} and \type {\realnumber} macros have been removed.
97
98\protect \endinput
99