diff options
Diffstat (limited to 'tex/context/base/mkxl')
-rw-r--r-- | tex/context/base/mkxl/cldf-pos.lmt | 152 | ||||
-rw-r--r-- | tex/context/base/mkxl/cldf-pos.mkxl | 20 | ||||
-rw-r--r-- | tex/context/base/mkxl/cont-new.mkxl | 2 | ||||
-rw-r--r-- | tex/context/base/mkxl/context.mkxl | 2 | ||||
-rw-r--r-- | tex/context/base/mkxl/luat-cnf.lmt | 2 | ||||
-rw-r--r-- | tex/context/base/mkxl/toks-ini.lmt | 2 | ||||
-rw-r--r-- | tex/context/base/mkxl/toks-scn.lmt | 2 |
7 files changed, 126 insertions, 56 deletions
diff --git a/tex/context/base/mkxl/cldf-pos.lmt b/tex/context/base/mkxl/cldf-pos.lmt index 40c88c716..9378b01be 100644 --- a/tex/context/base/mkxl/cldf-pos.lmt +++ b/tex/context/base/mkxl/cldf-pos.lmt @@ -21,13 +21,15 @@ local posittonumber = posit.tonumber local values = tokens.values local boolean_code = values.boolean +local float_code = values.float -do +local scanners = tokens.scanners +local scanposit = scanners.posit +local scanfloat = scanners.float +local scaninteger = scanners.integer +local scancsname = scanners.csname - local scanners = tokens.scanners - local scanfloat = scanners.float - local scaninteger = scanners.integer - local scancsname = scanners.csname +do -- these are only for testing and might go to a module eventually local codes = tex.codes @@ -78,60 +80,108 @@ do end, } -end + do -do - - local p_number = lpeg.patterns.number - local p = lpeg.Cs( - lpeg.Cc("local new = new ; return ") - * ( - lpeg.C(p_number) / function(s) - return "new(" .. s .. ")" - end - + lpeg.P(1) - )^0 - ) + local p_number = lpeg.patterns.number + local p = lpeg.Cs( + lpeg.Cc("local new = new ; return ") + * ( + lpeg.C(p_number) / function(s) + return "new(" .. s .. ")" + end + + lpeg.P(1) + )^0 + ) - local t = setmetatableindex({ new = posit.new }, posit) + local t = setmetatableindex({ new = posit.new }, posit) - local function calculate(s) - local new = lpegmatch(p,s) - new = load(new,nil,nil,t) - if new then - new = new() + local function calculate(s) + local new = lpegmatch(p,s) + new = load(new,nil,nil,t) if new then - return new + new = new() + if new then + return new + end end + return old end - return old - end - implement { - name = "positunum", - public = true, - arguments = "string", - actions = function(s) - local r = calculate(s) - local t = type(r) - if t == "boolean" then - context(tostring(r)) - elseif t == "string" then - context(r) - else - context("%N",posittonumber(r)) + implement { + name = "positunum", + public = true, + arguments = "string", + actions = function(s) + local r = calculate(s) + local t = type(r) + if t == "boolean" then + context(tostring(r)) + elseif t == "string" then + context(r) + else + context("%N",posittonumber(r)) + end end - end - } + } + + implement { + name = "ifpositunum", + public = true, + usage = "condition", + arguments = "string", + actions = function(s) + return boolean_code, calculate(s) and true or false + end, + } - implement { - name = "ifpositunum", - public = true, - usage = "condition", - arguments = "string", - actions = function(s) - return boolean_code, calculate(s) and true or false - end, - } + end + +end + +do + + local xsin = xmath.sin local xasin = xmath.asin local xsinh = xmath.sinh local xasinh = xmath.asinh + local xcos = xmath.cos local xacos = xmath.acos local xcosh = xmath.cosh local xacosh = xmath.acosh + local xtan = xmath.tan local xatan = xmath.atan local xtanh = xmath.tanh local xatanh = xmath.atanh + + local xsqrt = xmath.sqrt + local xlog = xmath.log + local xexp = xmath.exp + local xpow = xmath.pow + local xceil = xmath.ceil + local xfloor = xmath.floor + local xround = xmath.round + local xabs = xmath.fabs + local xmod = xmath.fmod + local xrem = xmath.remainder + local xrad = xmath.rad + local xdeg = xmath.deg + local xatan2 = xmath.atan2 + + implement { name = "pfsin", public = true, usage = "value", actions = function() return float_code, xsin (scanposit(true)) end } + implement { name = "pfcos", public = true, usage = "value", actions = function() return float_code, xcos (scanposit(true)) end } + implement { name = "pftan", public = true, usage = "value", actions = function() return float_code, xtan (scanposit(true)) end } + implement { name = "pfasin", public = true, usage = "value", actions = function() return float_code, xasin (scanposit(true)) end } + implement { name = "pfacos", public = true, usage = "value", actions = function() return float_code, xacos (scanposit(true)) end } + implement { name = "pfatan", public = true, usage = "value", actions = function() return float_code, xatan (scanposit(true)) end } + implement { name = "pfsinh", public = true, usage = "value", actions = function() return float_code, xsinh (scanposit(true)) end } + implement { name = "pfcosh", public = true, usage = "value", actions = function() return float_code, xcosh (scanposit(true)) end } + implement { name = "pftanh", public = true, usage = "value", actions = function() return float_code, xtanh (scanposit(true)) end } + implement { name = "pfasinh", public = true, usage = "value", actions = function() return float_code, xasinh(scanposit(true)) end } + implement { name = "pfacosh", public = true, usage = "value", actions = function() return float_code, xacosh(scanposit(true)) end } + implement { name = "pfatanh", public = true, usage = "value", actions = function() return float_code, xatanh(scanposit(true)) end } + implement { name = "pfsqrt", public = true, usage = "value", actions = function() return float_code, xsqrt (scanposit(true)) end } + implement { name = "pflog", public = true, usage = "value", actions = function() return float_code, xlog (scanposit(true)) end } + implement { name = "pfexp", public = true, usage = "value", actions = function() return float_code, xexp (scanposit(true)) end } + implement { name = "pfceil", public = true, usage = "value", actions = function() return float_code, xceil (scanposit(true)) end } + implement { name = "pffloor", public = true, usage = "value", actions = function() return float_code, xfloor(scanposit(true)) end } + implement { name = "pfround", public = true, usage = "value", actions = function() return float_code, xround(scanposit(true)) end } + implement { name = "pfabs", public = true, usage = "value", actions = function() return float_code, xabs (scanposit(true)) end } + implement { name = "pfrad", public = true, usage = "value", actions = function() return float_code, xrad (scanposit(true)) end } + implement { name = "pfdeg", public = true, usage = "value", actions = function() return float_code, xdeg (scanposit(true)) end } + implement { name = "pfatantwo", public = true, usage = "value", actions = function() return float_code, xatan2(scanposit(true),scanposit(true)) end } + implement { name = "pfpow", public = true, usage = "value", actions = function() return float_code, xpow (scanposit(true),scanposit(true)) end } + implement { name = "pfmod", public = true, usage = "value", actions = function() return float_code, xmod (scanposit(true),scanposit(true)) end } + implement { name = "pfrem", public = true, usage = "value", actions = function() return float_code, xrem (scanposit(true),scanposit(true)) end } end diff --git a/tex/context/base/mkxl/cldf-pos.mkxl b/tex/context/base/mkxl/cldf-pos.mkxl index e8868eece..fb419d070 100644 --- a/tex/context/base/mkxl/cldf-pos.mkxl +++ b/tex/context/base/mkxl/cldf-pos.mkxl @@ -13,8 +13,24 @@ \writestatus{loading}{ConTeXt Posit Numbers / Initialization} -% \newcount\trialtypesettingstate % gets aliased at the Lua end - \registerctxluafile{cldf-pos}{autosuffix} +\newposit\pfpi \pfpi 3.1415926535897932384626433832795028841971 +\newposit\pftwopi \pftwopi \floatexpr \pfpi * 2 \relax + +% \newfloat\fooA +% +% \scratchdimen=123.456pt\relax [\type{dim:} \the\scratchdimen==123.456pt]\par +% \fooA =123.456\relax [\type{pos:} \the\fooA ==123.456] \par +% \fooA =\scratchdimen\relax [\type{pos:} \the\fooA ==123.456] \par +% \scratchdimen=\fooA\relax [\type{dim:} \the\scratchdimen==123.456pt]\par +% \scratchdimen\dimexpr\fooA+10pt\relax[\type{dim:} \the\scratchdimen==133.456pt]\par +% +% \fooA\pfsin \pfpi [\the\fooA]\par +% \fooA\pfcos \pfpi [\the\fooA]\par +% \fooA\pfsqrt\pfpi [\the\fooA]\par +% \fooA\pfexp \pfpi [\the\fooA]\par +% \fooA\pflog \pfpi [\the\fooA]\par +% \fooA\pfpow \pfpi 2 [\the\fooA]\par + \endinput diff --git a/tex/context/base/mkxl/cont-new.mkxl b/tex/context/base/mkxl/cont-new.mkxl index ebc5e13fc..23dc6bbef 100644 --- a/tex/context/base/mkxl/cont-new.mkxl +++ b/tex/context/base/mkxl/cont-new.mkxl @@ -13,7 +13,7 @@ % \normalend % uncomment this to get the real base runtime -\newcontextversion{2023.04.27 09:34} +\newcontextversion{2023.04.27 16:54} %D This file is loaded at runtime, thereby providing an excellent place for hacks, %D patches, extensions and new features. There can be local overloads in cont-loc diff --git a/tex/context/base/mkxl/context.mkxl b/tex/context/base/mkxl/context.mkxl index 1e286f461..9ee1d3803 100644 --- a/tex/context/base/mkxl/context.mkxl +++ b/tex/context/base/mkxl/context.mkxl @@ -29,7 +29,7 @@ %D {YYYY.MM.DD HH:MM} format. \immutable\edef\contextformat {\jobname} -\immutable\edef\contextversion{2023.04.27 09:34} +\immutable\edef\contextversion{2023.04.27 16:54} %overloadmode 1 % check frozen / warning %overloadmode 2 % check frozen / error diff --git a/tex/context/base/mkxl/luat-cnf.lmt b/tex/context/base/mkxl/luat-cnf.lmt index ea9eb0d89..585941173 100644 --- a/tex/context/base/mkxl/luat-cnf.lmt +++ b/tex/context/base/mkxl/luat-cnf.lmt @@ -60,7 +60,7 @@ function texconfig.init() -- not in luametatex "unicode", "utf", "gzip", "zip", "zlib", -- in luametatex - "xzip", "xmath", "xcomplex", "xdecimal", "basexx", + "xzip", "xmath", "xcomplex", "xdecimal", "basexx", "posit", -- maybe some day in luametatex "lz4", "lzo", -- always (mime can go) diff --git a/tex/context/base/mkxl/toks-ini.lmt b/tex/context/base/mkxl/toks-ini.lmt index e4bf7626f..d45e3ae1c 100644 --- a/tex/context/base/mkxl/toks-ini.lmt +++ b/tex/context/base/mkxl/toks-ini.lmt @@ -48,6 +48,7 @@ local scanvalue = token.scanvalue local scanchar = token.scanchar local scancsname = token.scancsname local scannextchar = token.scannextchar +local scanposit = token.scanposit local scanreal = token.scanreal local scanfloat = token.scanfloat local scanluanumber = token.scanluanumber @@ -160,6 +161,7 @@ tokens.scanners = { -- these expand gluespec = scanskip, integer = scaninteger, cardinal = scancardinal, + posit = scanposit, real = scanreal, float = scanfloat, luanumber = scanluanumber, diff --git a/tex/context/base/mkxl/toks-scn.lmt b/tex/context/base/mkxl/toks-scn.lmt index c08e8415a..855bca6ad 100644 --- a/tex/context/base/mkxl/toks-scn.lmt +++ b/tex/context/base/mkxl/toks-scn.lmt @@ -29,6 +29,7 @@ local scantoks = scanners.toks local scaninteger = scanners.integer local scancardinal = scanners.cardinal local scannumber = scanners.number +local scanfloat = scanners.float local scankeyword = scanners.keyword local scankeywordcs = scanners.keywordcs local scanword = scanners.word @@ -226,6 +227,7 @@ local shortcuts = { scaninteger = scaninteger, scancardinal = scancardinal, scannumber = scannumber, + scanfloat = scanfloat, scantable = scantable, -- not directly useable scankeyword = scankeyword, scankeywordcs = scankeywordcs, |