Integer functions

For a real expression expr, the function round( expr ) attempts to round the argument to the nearest integer, and if the expression falls between two integers (e.g., $7.5$), it rounds away from zero.

Note that this is not meant to be IEEE 754 rounding, where $1.5$ would round to $2$ while $2.5$ would also round to $2$, as that impacts floating-point operations. The only numbers that round to $0$ are those that fall in the interval $(-0.5, 0.5)$.

[> round( 5325531/134123 );

$40$

[> round( exp(Pi) - Pi );

$20$

[> round( exp(-x^2)/4 );

$\left\lfloor \frac{1}{4} e^{-x^2} \right\rceil$

Note how Maple cleverly uses $\lfloor x \rceil$ to represent rounding?

[> round( exp(-x^2)/4 ) assuming x::'real';

$0$

The function ceil( expr ) attempts to round up to the least integer greater than or equal to the expression, while the function floor( expr ) attempts to round down to the greatest integer less than or equal to the expression. If unevaluated, these functions display as $\lceil x \rceil$ and $\lfloor x \rfloor$, respectively.

The function trunc( expr ) attempts to round towards zero, or in other words, truncates any fractional part, and the function frac( expr ) attempts to return the fractional remaining part.

Note that unlike C and C++ where floor(...) and ceil(...) return double-precision floating-point numbers that are integers, Maple returns actual integers, as opposed to floating-point numbers.

The ilog( expr ) function attempts to calculate that integer $r$ such that $e^r \le |\textit{expr}| < e^{r + 1}$. It is possible to specify a different base by calling ilog[b]( expr ), where this will return that integer $r$ such that $r$ such that $b^r \le |\textit{expr}| < b^{r + 1}$.

As engineers, the bases you are most likely to user are $2$ and $10$, so for example:

[> ilog[2]( 1485524417446386118863917 );

$80$

[> ilog[10]( 892724559912597525851927837131981824 );

$35$

Unfortunately, these functions do not attempt to perform a more careful analysis:

[> ilog[2]( Pi );

$\textrm{ilog}_2(\pi)$