## 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.


 $$\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$$