({{, (RefLink[IntegerPart, paclet:ref/IntegerPart])[x]
gives the integer part of x. }})

OpenersNotesSection(Spacer1)Details

Mathematical function, suitable for both symbolic and numerical manipulation.

(RefLink[IntegerPart, paclet:ref/IntegerPart])[x] in effect takes all digits to the left of the decimal point and drops the others.

(RefLink[IntegerPart, paclet:ref/IntegerPart])[x]+(RefLink[FractionalPart, paclet:ref/FractionalPart])[x] is always exactly x.

(RefLink[IntegerPart, paclet:ref/IntegerPart])[x] returns an integer when x is any numeric quantity, whether or not it is an explicit number.

For exact numeric quantities, (RefLink[IntegerPart, paclet:ref/IntegerPart]) internally uses numerical approximations to establish its result. This process can be affected by the setting of the global variable (RefLink[$MaxExtraPrecision, paclet:ref/$MaxExtraPrecision]).

(RefLink[IntegerPart, paclet:ref/IntegerPart]) applies separately to real and imaginary parts of complex numbers.

(RefLink[IntegerPart, paclet:ref/IntegerPart]) automatically threads over lists.

OpenersPrimaryExamplesSection(Spacer1)Examples  (36)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Find the integer part of a real number:

IntegerPart[2.4]

Plot[IntegerPart[x],{x,-3,3},Filling->Axis]

OpenersExampleSection1(Spacer1)Scope  (14)

OpenersExampleSubsection0(Spacer1)Numerical Evaluation  (3)

Evaluate numerically:

IntegerPart[456.457]

IntegerPart[-56.45]

Complex number inputs:

IntegerPart[78/47-4.2I]

Evaluate efficiently at high precision:

IntegerPart[7545/466]//Timing

IntegerPart[7545/4660];//Timing

OpenersExampleSubsection1(Spacer1)Specific Values   (6)

Values of (RefLink[IntegerPart, paclet:ref/IntegerPart]) at fixed points:

Table[IntegerPart[n ],{n,{5/3,11/3,9/2}}]

Value at infinity:

IntegerPart[Infinity]

Value at zero:

IntegerPart[0]

Evaluate symbolically:

PiecewiseExpand[IntegerPart[x],-2<x<2]

Manipulate (RefLink[IntegerPart, paclet:ref/IntegerPart]) symbolically:

FullSimplify[IntegerPart[x]+IntegerPart[x+1/2], 1/3<x<1/2]

Reduce[IntegerPart[x]+IntegerPart[2x-1]==2&&0<x<4,x,Reals]

Find a value of x for which the (RefLink[IntegerPart, paclet:ref/IntegerPart])[x]=1:

xval=x/.FindRoot[IntegerPart[x]== 1,{x,1.5}]

Plot[IntegerPart[x],{x,-2,3},Epilog->{PointSize[Large],Red,Point[{xval,IntegerPart[xval]}]},ExclusionsStyle->Dotted]

OpenersExampleSubsection2(Spacer1)Function Properties  (3)

Function domain of (RefLink[IntegerPart, paclet:ref/IntegerPart]):

FunctionDomain[IntegerPart[x],x]

FunctionDomain[IntegerPart[x],x,Complexes]

Function range of (RefLink[IntegerPart, paclet:ref/IntegerPart]):

FunctionRange[IntegerPart[x],x,y]//Quiet

(RefLink[IntegerPart, paclet:ref/IntegerPart]) threads elementwise over lists:

IntegerPart[{2.4,2.5,3.0}]

OpenersExampleSubsection3(Spacer1)Differentiation and Integration  (2)

First derivative with respect to x:

D[IntegerPart[x],x]

Definite integrals of (RefLink[IntegerPart, paclet:ref/IntegerPart]):

Integrate[IntegerPart[x],{x,0,E}]

Integrate[IntegerPart[x^3],{x,0,2}]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (4)

Use with negative arguments:

IntegerPart[{-2.4,-2.5,-3.0}]

Use with complex-number arguments:

IntegerPart[3+11/5 I]

(RefLink[IntegerPart, paclet:ref/IntegerPart]) can deal with real-valued intervals:

IntegerPart[Interval[{-1,3/2}]]

Infinite arguments give symbolic results:

IntegerPart[Infinity]

Series expansion:

Series[IntegerPart[x^2],{x,1,2},Assumptions->Element[x, Reals]]

OpenersExampleSection3(Spacer1)Applications  (8)

Plot[IntegerPart[x+x^2],{x,-3,3}]

Plot3D[Abs[IntegerPart[x+I y]],{x,-2.5,2.5},{y,-2.5,2.5},ExclusionsStyle->{None,Directive[Thick,White]}]

Iso-curves become full-dimensional regions for piecewise constant functions:

RegionPlot[IntegerPart[x^2+y^2]==1,{x,-2,2},{y,-2,2}]

Fibonacci numbers:

Table[IntegerPart[GoldenRatio^k/Sqrt[5]]+Mod[k,2],{k,15}]

Table[Fibonacci[k],{k,15}]

Implement a divide-and-conquer-type recursion relation:

f[x_]:=2/3 f[IntegerPart[x/2]]+2;f[0]=0;

f[10]

Find the 1000000(^th) digit of the fraction 1/99^2 in base 10:

With[{p = 1,q=99^2,n=10^6,base=10},IntegerPart[base Mod[p PowerMod[base, n - 1, q], q]/q]]

Compare with (RefLink[RealDigits, paclet:ref/RealDigits]) functionality:

RealDigits[1/99^2,10,1,-10^6]

Find the day of the week in the Gregorian calendar:

dow[year_,month_,day_]:={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}[[Mod[IntegerPart[23 month/9]+day+4+year+
                    (IntegerPart[#/4]-IntegerPart[#/100]+IntegerPart[#/400])&[If[month<3,year-1,year]]-If[month>=3,2,0],7]+1]]

Birthday of Leonard Euler:

dow[1707,4,15]

Compare with (RefLink[DateString, paclet:ref/DateString]):

DateString[{1707,04,15},"DayName"]

Implement the Frisch continuous-but-nowhere-differentiable function:

f[x_,n_]:=Sum[Boole[IntegerPart[k x]==IntegerPart[(k+1) x]]/2^k,{k, n}]

ListLinePlot[{#,f[#,100]}&/@Union[Flatten[Table[i/j,{j,50},{i,0,j}]]]]

OpenersExampleSection4(Spacer1)Properties & Relations  (5)

Simplify expressions containing (RefLink[IntegerPart, paclet:ref/IntegerPart]):

Simplify[IntegerPart[x+1]-IntegerPart[x],x≥0]

FullSimplify[IntegerPart[z-IntegerPart[z]]-2IntegerPart[Round[z]]]

Symbolically expand for complex arguments:

ComplexExpand[IntegerPart[x+I y]]

(RefLink[IntegerPart, paclet:ref/IntegerPart]) is idempotent:

IntegerPart[IntegerPart[x]]

Use (RefLink[PiecewiseExpand, paclet:ref/PiecewiseExpand]) to canonicalize:

PiecewiseExpand[IntegerPart[x^2 + Sqrt[x]],0<x<2]

PiecewiseExpand[IntegerPart[x+1/3+IntegerPart[1-x/2]^3],x∈Reals&&-2<x<3]

Reduce equations containing (RefLink[IntegerPart, paclet:ref/IntegerPart]):

Reduce[IntegerPart[x+1/2]==2 IntegerPart[x]&&-1<x<1,x,Reals]

OpenersExampleSection5(Spacer1)Possible Issues  (3)

Numerical decision procedures with default settings cannot simplify this expression:

IntegerPart[π^2+2π+1-(π+1)^2]

Use (RefLink[Simplify, paclet:ref/Simplify]) to resolve:

Simplify[%]

Machine-precision numericalization of (RefLink[IntegerPart, paclet:ref/IntegerPart]) can give wrong results:

IntegerPart[1+(E+1)^2-E^2-2E-1+Exp[-Exp[E]^2]]

N[%]

Use arbitrary-precision evaluation instead:

N[%%, 20]

Because the answer is exact, raising the internal precision does not remove the message:

Block[{$MaxExtraPrecision=10000},N[%%%,100]]

Symbolic preprocessing of functions containing (RefLink[IntegerPart, paclet:ref/IntegerPart]) can be time consuming:

NIntegrate[IntegerPart[x +x^2],{x,0,5}]//Timing

As a discontinuous function, (RefLink[IntegerPart, paclet:ref/IntegerPart]) can cause numerical algorithms to converge slowly:

NIntegrate[IntegerPart[x +x^2],{x,0,5},Method->{Automatic,"SymbolicProcessing"->0}]//Timing

OpenersExampleSection6(Spacer1)Neat Examples  (1)

Build a nondecreasing sequence of integers where each number n occurs n times [(WebLink[more info, http://mathworld.wolfram.com/Self-CountingSequence.html])]:

s[n_]:=Table[IntegerPart[Sqrt[2k]+1/2],{k,n (1+n)/2}]

Generate the sequence up to 5:

s[5]

Group the same numbers:

Split[%]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[FractionalPart, paclet:ref/FractionalPart])  ▪  (RefLink[Round, paclet:ref/Round])  ▪  (RefLink[Floor, paclet:ref/Floor])  ▪  (RefLink[Ceiling, paclet:ref/Ceiling])  ▪  (RefLink[Chop, paclet:ref/Chop])  ▪  (RefLink[Numerator, paclet:ref/Numerator])  ▪  (RefLink[FindDivisions, paclet:ref/FindDivisions])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Numerical Functions, paclet:tutorial/NumericalFunctions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Numerical Functions, paclet:guide/NumericalFunctions])}, {▪(RefLinkPlain[Number Digits, paclet:guide/NumberDigits])}, {▪(RefLinkPlain[Representation of Numbers, paclet:guide/RepresentationOfNumbers])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-MathWorld.png(Spacer1)MathWorld, http://mathworld.wolfram.com/IntegerPart.html])}, {DocumentationFooterIconsRelatedLinks-Functions.png(Spacer1)The Wolfram Functions Site}})}})