syst-con.mkxl /size: 3187 b    last modification: 2020-07-01 14:35
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
<
1
0
0
\fi\number
#
1
}
56
\def
\threedigits
#
1
{
\ifnum
#
1
<
1
0
0
\ifnum
#
1
<
1
0
0
\fi
0
\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
%D
72
%D \starttyping
73
%D \def\modulonumber#1#2{\the\numexpr#2-((((#2+(#1/2))/#1)-1)*#1)\relax}
74
%D \stoptyping
75
%D
76
%D But \unknown\ now we can also do this:
77 78
\def
\modulonumber
#
1
#
2
{
\the\numexpr
#
2
-
(#
2
:
#
1
)
*
#
1
\relax
}
79 80
%D \macros{setcalculatedsin,setcalculatedcos,setcalculatedtan}
81 82
\unexpanded
\def
\setcalculatedsin
#
1
#
2
{
\edef
#
1
{
\clf_sind
#
2
}}
83
\unexpanded
\def
\setcalculatedcos
#
1
#
2
{
\edef
#
1
{
\clf_cosd
#
2
}}
84
\unexpanded
\def
\setcalculatedtan
#
1
#
2
{
\edef
#
1
{
\clf_tand
#
2
}}
85 86
%D \macros{formatted,format}
87 88
\def
\formatted
#
1
{
\ctxcommand{
format
(
#
1
)
}
}
% not clf
89
\unexpanded
\def
\format
#
1
{
\ctxcommand{
format
(
#
1
)
}
}
% not clf
90 91
%D The \type {\modulatednumber} and \type {\realnumber} macros have been removed.
92 93
\protect
\endinput
94