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\permanent\def\lchexnumber #1{ {#1}} 24\permanent\def\uchexnumber #1{ {#1}} 25\permanent\def\lchexnumbers#1{{#1}} 26\permanent\def\uchexnumbers#1{{#1}} 27 28\aliased\let\hexnumber\uchexnumber 29 30%D \macros{octnumber} 31%D 32%D For \UNICODE\ remapping purposes, we need octal numbers. 33 34\permanent\def\octnumber#1{{#1}} 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\permanent\def\hexstringtonumber#1{{#1}} 42\permanent\def\octstringtonumber#1{{#1}} 43 44%D \macros{twodigits, threedigits} 45%D 46%D These macros provides two or three digits always: 47 48\permanent\def\twodigits #1{\ifnum #1<10 0\fi\number#1} 49\permanent\def\threedigits#1{\ifnum#1<100 \ifnum#1<10 0\fi0\fi\number#1} 50 51%D \macros{modulonumber} 52%D 53%D In the conversion macros described in \type {core-con} we need a wrap||around 54%D method. The following solution is provided by Taco. 55%D 56%D The \type {modulonumber} macro expands to the mathematical modulo of a positive 57%D integer. It is crucial for it's application that this macro is fully exandable. 58%D 59%D The expression inside the \type {\numexpr} itself is somewhat bizarre because 60%D \ETEX\ uses a rounding division instead of truncation. If \ETEX's division would 61%D have behaved like \TEX's normal\type {\divide}, then the expression could have 62%D been somewhat simpler, like \type {#2-(#2/#1)*#1}. This works just as well, but a 63%D bit more complex. 64 65%permanent\def\modulonumber#1#2{\the\numexpr#2-((((#2+(#1/2))/#1)-1)*#1)\relax} 66%permanent\def\modulonumber#1#2{\the\numexpr#2-(#2:#1)*#1\relax} 67 68%D \macros{setcalculatedsin,setcalculatedcos,setcalculatedtan} 69 70\permanent\protected\def\setcalculatedsin#1#2{\edef#1{#2}} 71\permanent\protected\def\setcalculatedcos#1#2{\edef#1{#2}} 72\permanent\protected\def\setcalculatedtan#1#2{\edef#1{#2}} 73 74%D \macros{formatted,format} 75 76\permanent \def\formatted#1{format(#1)} % not clf 77\permanent\protected\def\format #1{format(#1)} % not clf 78 79%D The \type {\modulatednumber} and \type {\realnumber} macros have been removed. 80 81%D \macros{tobits} 82%D 83%D Thso macro expects a number of bits, chunk size and the number. 84%D 85%D \starttyping 86%D \tobits 32 4 "00000003 87%D \stoptyping 88 89\protect \endinput 90 |