trunc - Maple Help

# Online Help

###### All Products    Maple    MapleSim

trunc

truncate a number to the next nearest integer towards 0

round

round a number to the nearest integer

frac

fractional part of a number

floor

greatest integer less than or equal to a number

ceil

smallest integer greater than or equal to a number

 Calling Sequence trunc(n, x) round(n, x) frac(n, x) floor(n, x) ceil(n, x)

Parameters

 n - (optional) any expression, assumed to be a non-negative integer x - any expression

Description

 • These functions compute integer or fractional parts of numbers.  For real arguments x:
 For $0\le x$, trunc(x) is the greatest integer less than or equal to x.  For $x<0$, trunc(x) = -trunc(-x).
 round(x) rounds x to the nearest integer. In case of a tie (at half-integers), it rounds away from 0.
 frac(x) is the fractional part of x, that is, frac(x) = x - trunc(x).
 floor(x) (floor) is the greatest integer less than or equal to x.
 ceil(x) (ceiling) is the smallest integer greater than or equal to x.
 • For complex arguments x:
 trunc(x) = trunc($\Re \left(x\right)$) + I*trunc($\mathrm{\Im }\left(x\right)$)
 round(x) = round($\Re \left(x\right)$) + I*round($\mathrm{\Im }\left(x\right)$)
 frac(x) = frac($\Re \left(x\right)$) + I*frac($\mathrm{\Im }\left(x\right)$)
 For floor(x), let $a=\Re \left(x\right)-⌊\Re \left(x\right)⌋$ and let $b=\mathrm{\Im }\left(x\right)-⌊\mathrm{\Im }\left(x\right)⌋$.  Then floor(x) = floor($\Re \left(x\right)$) + I*floor($\mathrm{\Im }\left(x\right)$) + X, where

$X={\begin{array}{cc}0& a+b<1\\ 1& 1\le a+b\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b\le a\\ I& 1\le a+b\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{and}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}a

 ceil(x) = -floor(-x)
 • For all functions, the two-argument case indicates the nth derivative of the function at x.  Except for frac, these derivatives are 0 wherever they are defined.  For frac, the first derivative is 1 wherever it is defined.
 • If x is a constant, these functions will use evalr() to try to cautiously evaluate x to a floating point number and then apply themselves to the result.  This computation is performed initially at the current setting of Digits, and then if necessary a limited number of times more at higher settings.  If evalr() continues to return a result which is ambiguous with respect to the function being applied, the original function will return unevaluated. In this case, increasing Digits before calling the function may still help in rare cases.
 • In all other cases, these functions return unevaluated.

Thread Safety

 • The trunc command is thread-safe as of Maple 15.
 • For more information on thread safety, see index/threadsafe.

Examples

Truncate a number to the nearest integer towards 0.

 > $\mathrm{trunc}\left(7\right)$
 ${7}$ (1)
 > $\mathrm{trunc}\left(\frac{8}{3}\right)$
 ${2}$ (2)
 > $\mathrm{trunc}\left(-2.4\right)$
 ${-}{2}$ (3)
 > $\mathrm{trunc}\left(\mathrm{π}\right)$
 ${3}$ (4)
 > $\mathrm{trunc}\left(3.5+4.2I\right)$
 ${3}{+}{4}{}{I}$ (5)

Round a number to the nearest integer.

 > $\mathrm{round}\left(7\right)$
 ${7}$ (6)
 > $\mathrm{round}\left(\frac{8}{3}\right)$
 ${3}$ (7)
 > $\mathrm{round}\left(-2.4\right)$
 ${-}{2}$ (8)
 > $\mathrm{round}\left(\mathrm{π}\right)$
 ${3}$ (9)
 > $\mathrm{round}\left(3.5+4.2I\right)$
 ${4}{+}{4}{}{I}$ (10)

Fractional part of a number.

 > $\mathrm{frac}\left(7\right)$
 ${0}$ (11)
 > $\mathrm{frac}\left(\frac{8}{3}\right)$
 $\frac{{2}}{{3}}$ (12)
 > $\mathrm{frac}\left(-2.4\right)$
 ${-}{0.4}$ (13)
 > $\mathrm{frac}\left(\mathrm{π}\right)$
 ${\mathrm{π}}{-}{3}$ (14)
 > $\mathrm{frac}\left(3.5+4.2I\right)$
 ${0.5}{+}{0.2}{}{I}$ (15)

Greatest integer less than or equal to a number.

 > $\mathrm{floor}\left(7\right)$
 ${7}$ (16)
 > $\mathrm{floor}\left(\frac{8}{3}\right)$
 ${2}$ (17)
 > $\mathrm{floor}\left(-2.4\right)$
 ${-}{3}$ (18)
 > $\mathrm{floor}\left(\mathrm{π}\right)$
 ${3}$ (19)
 > $\mathrm{floor}\left(3.5+4.2I\right)$
 ${3}{+}{4}{}{I}$ (20)

Smallest integer greater than or equal to a number.

 > $\mathrm{ceil}\left(7\right)$
 ${7}$ (21)
 > $\mathrm{ceil}\left(\frac{8}{3}\right)$
 ${3}$ (22)
 > $\mathrm{ceil}\left(-2.4\right)$
 ${-}{2}$ (23)
 > $\mathrm{ceil}\left(\mathrm{π}\right)$
 ${4}$ (24)
 > $\mathrm{ceil}\left(3.5+4.2I\right)$
 ${4}{+}{4}{}{I}$ (25)

More advanced operations.

 > $\mathrm{ceil}\left({ⅇ}^{3}\right)$
 ${21}$ (26)
 > $\mathrm{trunc}\left(\frac{ⅆ}{ⅆx}\left(76.8x\right)\right)$
 ${76}$ (27)
 > $\mathrm{round}\left(\genfrac{}{}{0}{}{\left({x}^{2}+5x-9\right)}{\phantom{x=2.1}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}|\phantom{\rule[-0.0ex]{0.1em}{0.0ex}}\genfrac{}{}{0}{}{\phantom{\left({x}^{2}+5x-9\right)}}{x=2.1}\right)$
 ${6}$ (28)

The functions can be differentiated.

 > $\frac{ⅆ}{ⅆx}\mathrm{trunc}\left(x\right)$
 ${\mathrm{trunc}}{}\left({1}{,}{x}\right)$ (29)
 > $\frac{ⅆ}{ⅆx}\mathrm{round}\left(x\right)$
 ${\mathrm{round}}{}\left({1}{,}{x}\right)$ (30)
 > $\frac{ⅆ}{ⅆx}\mathrm{frac}\left(x\right)$
 ${1}{-}{\mathrm{trunc}}{}\left({1}{,}{x}\right)$ (31)
 > $\frac{ⅆ}{ⅆx}\mathrm{floor}\left(x\right)$
 ${\mathrm{floor}}{}\left({1}{,}{x}\right)$ (32)
 > $\frac{ⅆ}{ⅆx}\mathrm{ceil}\left(x\right)$
 ${\mathrm{floor}}{}\left({1}{,}{x}\right)$ (33)
 > $\mathrm{floor}\left(1,3.5\right)$
 ${0}$ (34)
 > $\mathrm{trunc}\left(1,243.422\right)$
 ${0}$ (35)

Errors are returned when the functions are not defined:

 > $\mathrm{floor}\left(1,5\right)$

References

 McDonnell, E.E. "Integer functions of complex numbers, with applications." IBM Philadelphia Scientific Center Tech. Rep. pp. 320-3015. Feb., 1973.

 See Also

## Was this information helpful?

 Please add your Comment (Optional) E-mail Address (Optional) What is ? This question helps us to combat spam