Friday Jul 22, 2011

More arithmetic operations now implemented in compiler

<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML.js" type="text/javascript"></script>

The Fortress compiler now implements some additional arithmetic operations.

For type\(\mskip3mu\) \(\newcommand\EXP[1]{#1} \newcommand\KWD[1]{\mathrel{\mathtt{#1}}} \newcommand\KWDVAR[1]{\mathord{\mathtt{#1}}} \newcommand\OPR[1]{\mathbin{\mathtt{#1}}} \newcommand\BIGOPR[1]{\mathop{\lower0.4ex\hbox{\vrule height 1.2em depth 0.1em width 0pt\Large$\mathtt{#1}$}}} \newcommand\BIGOP[1]{\mathop{\lower0.2ex\hbox{\Large$#1$}}} \newcommand\TYP[1]{\mathord{\mathrm{#1}}} \newcommand\VAR[1]{\mathord{\mathit{#1}}} \newcommand\STR[1]{\hbox{\tt\usefont{T1}{pcr}{m}{n}\selectfont#1}} \newcommand\CONDEQ{\mathrel{\mathtt{:}}=\mathrel{\mathtt{:}}} \newcommand\ASSIGN{\mathrel{\mathtt{:}}=} \newcommand\COLON{\mathpunct{\mathtt{:}}} \newcommand\COLONOP{\mathinner{\mathtt{:}}} \newcommand\SHORTCUT[1]{\mathrel{\mathord{#1}\mathord{:}}} \newcommand\twointersectand{\mathbin{\wedge\mskip-10mu\wedge}} \newcommand\twointersector{\mathbin{\vee\mskip-10mu\vee}} \newcommand\twointersectxor{\mathbin{\underline{\vee\mskip-10mu\vee}}} \newcommand\twointersectnot{\mathbin{\neg\mskip-8mu\neg}} \newcommand\verythin{{\mskip 1.5mu}} \newcommand\ultrathin{{\mskip 0.75mu}} \def\Vvert{\mathrel{\vert\mskip-1.5mu\vert\mskip-1.5mu\vert}} \def\VVert{\mathrel{\vert\mskip-1.5mu\vert\mskip-1.5mu\vert\mskip-1.5mu\vert}} \def\sequiv{\mathrel{\hbox{\raise0.215ex\hbox to 0pt{$\equiv$\hss}\lower0.215ex\hbox{$\equiv$}}}} \newcommand\bigllbracket{\bigl[\mkern-5mu\bigl[} \newcommand\bigrrbracket{\bigr]\mkern-5mu\bigr]} \newcommand\Bigllbracket{\Bigl[\mkern-5.5mu\Bigl[} \newcommand\Bigrrbracket{\Bigr]\mkern-5.5mu\Bigr]} \newcommand\biggllbracket{\biggl[\mkern-6mu\biggl[} \newcommand\biggrrbracket{\biggr]\mkern-6mu\biggr]} \newcommand\Biggllbracket{\Biggl[\mkern-6.5mu\Biggl[} \newcommand\Biggrrbracket{\Biggr]\mkern-6.5mu\Biggr]} \newcommand\leftllbracket{\left[\mkern-5.5mu\left[} \newcommand\rightrrbracket{\right]\mkern-5.5mu\right]}\EXP{\mathbb{Z}32}\mskip3mu\):

    \(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\twointersectnot}(\KWDVAR{self})\COLON \mathbb{Z}32}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\twointersectand}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}32)\COLON \mathbb{Z}32}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\twointersector}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}32)\COLON \mathbb{Z}32}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\twointersectxor}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}32)\COLON \mathbb{Z}32}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MIN}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}32)\COLON \mathbb{Z}32}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MAX}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}32)\COLON \mathbb{Z}32}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MINMAX}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}32)\COLON (\mathbb{Z}32, \mathbb{Z}32)}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\VAR{even}(\KWDVAR{self})\COLON \TYP{Boolean}}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\VAR{odd}(\KWDVAR{self})\COLON \TYP{Boolean}}\mskip3mu\)

The first four are bitwise NOT, AND, OR, and XOR operations. \(\OPR{MINMAX}\mskip3mu\) returns a 2-tuple of its two arguments, sorted so that the first element of the tuple is not larger than the second value.

For type\(\mskip3mu\) \(\EXP{\mathbb{Z}64}\mskip3mu\):

    \(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\twointersectnot}(\KWDVAR{self})\COLON \mathbb{Z}64}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\twointersectand}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}64)\COLON \mathbb{Z}64}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\twointersector}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}64)\COLON \mathbb{Z}64}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\twointersectxor}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}64)\COLON \mathbb{Z}64}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MIN}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}64)\COLON \mathbb{Z}64}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MAX}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}64)\COLON \mathbb{Z}64}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MINMAX}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{Z}64)\COLON (\mathbb{Z}64, \mathbb{Z}64)}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\VAR{even}(\KWDVAR{self})\COLON \TYP{Boolean}}\mskip3mu\)
\(\mskip3mu\)\(\EXP{\VAR{odd}(\KWDVAR{self})\COLON \TYP{Boolean}}\mskip3mu\)

For type\(\mskip3mu\) \(\EXP{\mathbb{R}64}\mskip3mu\):

    \(\mskip3mu\)\(\EXP{\KWD{getter} \VAR{isNaN}(\ultrathin)\COLON \TYP{Boolean} }\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MIN}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{R}64)\COLON \mathbb{R}64 }\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MAX}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{R}64)\COLON \mathbb{R}64 }\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MINNUM}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{R}64)\COLON \mathbb{R}64 }\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MAXNUM}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{R}64)\COLON \mathbb{R}64 }\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MINNUMMAX}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{R}64)\COLON (\mathbb{R}64, \mathbb{R}64) }\mskip3mu\)
\(\mskip3mu\)\(\EXP{\KWD{opr}\, \mathord{\OPR{MINMAXNUM}}(\KWDVAR{self}, \VAR{other}\COLON\mathbb{R}64)\COLON (\mathbb{R}64, \mathbb{R}64) }\mskip3mu\)

\(\OPR{MIN}\mskip3mu\) and\(\mskip3mu\) \(\OPR{MAX}\mskip3mu\) return NaN is either argument is NaN;\(\mskip3mu\) \(\OPR{MINNUM}\mskip3mu\) and\(\mskip3mu\) \(\OPR{MAXNUM}\mskip3mu\), if either argument is NaN, return the other argument (and so the result is NaN only if both arguments are NaN).\(\mskip3mu\) \(\OPR{MINNUMMAX}\mskip3mu\) and\(\mskip3mu\) \(\OPR{MINMAXNUM}\mskip3mu\) both return a 2-tuple of the two arguments, sorted so that the first element of the tuple is not larger than the second value; but if one argument is NaN and the other is some non-NaN value\(\mskip1.5mu\) \(\VAR{v}\mskip1.5mu\), then\(\mskip3mu\) \(\OPR{MINNUMMAX}\mskip3mu\) returns\(\mskip3mu\) \(\EXP{(v,\TYP{NaN})}\mskip3mu\) but\(\mskip3mu\) \(\OPR{MINMAXNUM}\mskip3mu\) returns\(\mskip3mu\) \(\EXP{(\TYP{NaN},v)}\mskip3mu\).

For type\(\mskip1.5mu\) \(\TYP{String}\mskip1.5mu\):

    \(\mskip3mu\)\(\EXP{\KWD{opr} \unicode{x5E}(\KWDVAR{self}, n\COLON \mathbb{Z}32)\COLON \TYP{String}}\mskip3mu\)

(This last operation returns the concatenation of\(\mskip1.5mu\) \(\VAR{n}\mskip1.5mu\) copies of the string.)

One can also make a character, given its codepoint, by using\(\mskip1.5mu\) \(\VAR{makeCharacter}\mskip1.5mu\):

    \(\mskip3mu\)\(\EXP{\VAR{makeCharacter}(n\COLON \mathbb{Z}32)\COLON \TYP{Character}}\mskip3mu\)
About

Technical discussion of the Fortress programming language and its applications

Search

Categories
Archives
« July 2011 »
SunMonTueWedThuFriSat
     
1
2
3
4
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23
24
25
26
27
28
29
30
31
      
Today