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
Parameters
Description
Thread Safety
Examples
References
trunc(n, x)
round(n, x)
frac(n, x)
floor(n, x)
ceil(n, x)
n
-
(optional) any expression, assumed to be a non-negative integer
x
any expression
These functions compute integer or fractional parts of numbers. For real arguments x:
For 0≤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(ℜ⁡x) + I*trunc(ℑ⁡x)
round(x) = round(ℜ⁡x) + I*round(ℑ⁡x)
frac(x) = frac(ℜ⁡x) + I*frac(ℑ⁡x)
For floor(x), let a=ℜ⁡x−ℜ⁡x and let b=ℑ⁡x−ℑ⁡x. Then floor(x) = floor(ℜ⁡x) + I*floor(ℑ⁡x) + X, where
X=0a+b<111≤a+bandb≤aI1≤a+banda<b
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.
The trunc command is thread-safe as of Maple 15.
For more information on thread safety, see index/threadsafe.
Truncate a number to the nearest integer towards 0.
trunc⁡7
7
trunc⁡83
2
trunc⁡−2.4
−2
trunc⁡π
3
trunc⁡3.5+4.2⁢I
3+4⁢I
Round a number to the nearest integer.
round⁡7
round⁡83
round⁡−2.4
round⁡π
round⁡3.5+4.2⁢I
4+4⁢I
Fractional part of a number.
frac⁡7
0
frac⁡83
23
frac⁡−2.4
−0.4
frac⁡π
π−3
frac⁡3.5+4.2⁢I
0.5+0.2⁢I
Greatest integer less than or equal to a number.
floor⁡7
floor⁡83
floor⁡−2.4
−3
floor⁡π
floor⁡3.5+4.2⁢I
Smallest integer greater than or equal to a number.
ceil⁡7
ceil⁡83
ceil⁡−2.4
ceil⁡π
4
ceil⁡3.5+4.2⁢I
More advanced operations.
ceil⁡exp⁡3
21
trunc⁡diff⁡76.8⁢x,x
76
round⁡eval⁡x2+5⁢x−9,x=2.1
6
The functions can be differentiated.
diff⁡trunc⁡x,x
trunc⁡1,x
diff⁡round⁡x,x
x′
diff⁡frac⁡x,x
1−trunc⁡1,x
diff⁡floor⁡x,x
x1
diff⁡ceil⁡x,x
floor⁡1,3.5
trunc⁡1,243.422
Errors are returned when the functions are not defined:
floor⁡1,5
Error, (in floor) floor is not differentiable at integers
McDonnell, E.E. "Integer functions of complex numbers, with applications." IBM Philadelphia Scientific Center Tech. Rep. pp. 320-3015. Feb., 1973.
See Also
initialfunctions
Download Help Document