truncate a number to the next nearest integer towards 0 - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Mathematics : Group Theory : Numbers : trunc

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 0x, 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.

  

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=xx and let b=xx.  Then floor(x) = floor(x) + I*floor(x) + X, where

  

 

X&equals;&lcub;0a&plus;b<111a&plus;bandbaI1a&plus;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 at the current setting of Digits.  If evalr() returns a result which is ambiguous with respect to the function being applied, the original function will return unevaluated.  In this case, increasing Digits may help.

• 

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.

trunc7

7

(1)

trunc83

2

(2)

trunc2.4

2

(3)

trunc&pi;

3

(4)

trunc3.5&plus;4.2I

3&plus;4I

(5)

Round a number to the nearest integer.

round7

7

(6)

round83

3

(7)

round2.4

2

(8)

round&pi;

3

(9)

round3.5&plus;4.2I

4&plus;4I

(10)

Fractional part of a number.

frac7

0

(11)

frac83

23

(12)

frac2.4

0.4

(13)

frac&pi;

&pi;3

(14)

frac3.5&plus;4.2I

0.5&plus;0.2I

(15)

Greatest integer less than or equal to a number.

floor7

7

(16)

floor83

2

(17)

floor2.4

3

(18)

floor&pi;

3

(19)

floor3.5&plus;4.2I

3&plus;4I

(20)

Smallest integer greater than or equal to a number.

ceil7

7

(21)

ceil83

3

(22)

ceil2.4

2

(23)

ceil&pi;

4

(24)

ceil3.5&plus;4.2I

4&plus;4I

(25)

More advanced operations.

ceil&ExponentialE;3

21

(26)

trunc&DifferentialD;&DifferentialD;x76.8x

76

(27)

roundx2&plus;5x9x&equals;2.1|x2&plus;5x9x&equals;2.1

6

(28)

The functions can be differentiated.

&DifferentialD;&DifferentialD;xtruncx

trunc1&comma;x

(29)

&DifferentialD;&DifferentialD;xroundx

round1&comma;x

(30)

&DifferentialD;&DifferentialD;xfracx

1trunc1&comma;x

(31)

&DifferentialD;&DifferentialD;xfloorx

floor1&comma;x

(32)

&DifferentialD;&DifferentialD;xceilx

floor1&comma;x

(33)

floor1&comma;3.5

0

(34)

trunc1&comma;243.422

0

(35)

Errors are returned when the functions are not defined:

floor1&comma;5

Error, (in floor) floor is not differentiable at integers

See Also

initialfunctions

References

  

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


Download Help Document

Was this information helpful?



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