diff options
author | Karl Berry <karl@freefriends.org> | 2006-01-11 22:58:36 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-01-11 22:58:36 +0000 |
commit | ac3c55a3216b5988f0e48ba9414ddb059f19a699 (patch) | |
tree | a752ab12de05a9ac4511903abc09675172018fd6 /Master/texmf-dist/metapost/base/sarith.mp | |
parent | d087712418726a64822e40ce1c0627a514d17975 (diff) |
trunk/Master/texmf-dist/metapost
git-svn-id: svn://tug.org/texlive/trunk@104 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/metapost/base/sarith.mp')
-rw-r--r-- | Master/texmf-dist/metapost/base/sarith.mp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Master/texmf-dist/metapost/base/sarith.mp b/Master/texmf-dist/metapost/base/sarith.mp new file mode 100644 index 00000000000..26f99c0fa61 --- /dev/null +++ b/Master/texmf-dist/metapost/base/sarith.mp @@ -0,0 +1,47 @@ +% Macros for arithmetic on strings that represent big numbers +% All the macros below except ordinary numeric values as well + +% Scvnum <number> % convert to an ordinary numeric +% Sabs <number> % absolute value +% <number> Sadd <number> % add +% <number> Ssub <number> % subtract +% <number> Smul <number> % multiply +% <number> Sdiv <number> % divide +% <number> Sleq <number> % compare <= +% <number> Sneq <number> % numeric compare <> + +% All other externally visible names start with `S' and end with `_' + + +if unknown Mzero: + begingroup interim % marith.mp starts with `warningcheck:=0' + input marith + endgroup; % restore warningcheck; we zero it when necessary +fi + + +vardef Sunop_(expr x)(text o) = + interim warningcheck:=0; + o if numeric x: decimal fi x +enddef; + + +vardef Sbinop_@#(expr a, b)(text o) = + interim warningcheck:=0; + @# (Mlog_Str a o Mlog_Str b) +enddef; + + +def Ssbinop_ = Sbinop_.Mexp_str enddef; + + +vardef Sabs primary x = Sunop_(x, Mexp_str Mabs Mlog_str) enddef; +vardef Scvnum primary x = Sunop_(x, Mexp Mlog_str) enddef; +% The inverse of Scvnum is the `decimal' primitive. + +primarydef a Smul b = Ssbinop_(a,b,Mmul) enddef; +primarydef a Sdiv b = Ssbinop_(a,b,Mdiv) enddef; +secondarydef a Sadd b = Ssbinop_(a,b,Madd) enddef; +secondarydef a Ssub b = Ssbinop_(a,b,Msub) enddef; +tertiarydef a Sleq b = Sbinop_(a,b,Mleq) enddef; +tertiarydef a Sneq b = Sbinop_(a,b,<>) enddef; |