Skip to content

IntegerPart ​

The integer part of x: x truncated toward 0.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageIntegerPart!
IntegerPart(x)x truncated toward 0.
Typed signatures
TypePackageApplies
(number) -> numberanalyticalways

Domain: Elementary functions

Details
  • Truncates toward 0, unlike Floor (which rounds toward −∞-\infty): IntegerPart(−2.4)=−2\mathrm{IntegerPart}(-2.4) = -2, where Floor(−2.4)=−3\mathrm{Floor}(-2.4) = -3.
  • Exact at an exact argument -- a rational reduces to an exact integer, and so does a symbolic constant like Pi (IntegerPart(π)=3\mathrm{IntegerPart}(\pi) = 3, not a decimal).
  • At a concretely complex argument, truncates the real and imaginary parts separately.
  • x=IntegerPart(x)+FractionalPart(x)x = \mathrm{IntegerPart}(x) + \mathrm{FractionalPart}(x) always -- see FractionalPart.

Examples

Basic #
live ↗
InIntegerPart(2.4)\mathrm{IntegerPart}(2.4)Out22

Truncates toward 0, unlike Floor

live ↗
InIntegerPart(−2.4)\mathrm{IntegerPart}(-2.4)Out−2-2
live ↗
InIntegerPart(72)\mathrm{IntegerPart}(\frac{7}{2})Out33
live ↗
InIntegerPart(−72)\mathrm{IntegerPart}(-\frac{7}{2})Out−3-3
Scope #

Exact numeric arguments stay exact

live ↗
InIntegerPart(π)\mathrm{IntegerPart}(π)Out33

Threads element-wise over a list

live ↗
InIntegerPart([2.5,−2.5])\mathrm{IntegerPart}(\bigl\lbrack2.5, -2.5\bigr\rbrack)Out[2,−2]\bigl\lbrack2, -2\bigr\rbrack

Complex numbers: real and imaginary parts truncated separately

live ↗
InIntegerPart(2.5+3.7i)\mathrm{IntegerPart}(2.5+3.7i)Out2+3i2+3i

The integer part truncates toward zero: −54→−1-\frac54\to-1

live ↗
InIntegerPart(−54)\mathrm{IntegerPart}(-\frac{5}{4})Out−1-1

Zero is its own integer part

live ↗
InIntegerPart(0)\mathrm{IntegerPart}(0)Out00

Truncation on a bounded domain: a branch per integer

live ↗
InPiecewiseExpand(IntegerPart(x),0<x<4)\mathrm{PiecewiseExpand}(\mathrm{IntegerPart}(x), 0\lt x\lt4)OutPiecewise([[1,1≤x∧x<2],[2,2≤x∧x<3],[3,3≤x]],0)\mathrm{Piecewise}(\bigl\lbrack\bigl\lbrack1, 1≤x∧x\lt2\bigr\rbrack, \bigl\lbrack2, 2≤x∧x\lt3\bigr\rbrack, \bigl\lbrack3, 3≤x\bigr\rbrack\bigr\rbrack, 0)
live ↗
InIntegerPart(e+π)\mathrm{IntegerPart}(e+π)Out55
Properties #

x=IntegerPart(x)+FractionalPart(x)x = \mathrm{IntegerPart}(x) + \mathrm{FractionalPart}(x)

live ↗
InIntegerPart(−72)+FractionalPart(−72)=−72\mathrm{IntegerPart}(-\frac{7}{2})+\mathrm{FractionalPart}(-\frac{7}{2})=-\frac{7}{2}OutTrue\mathrm{True}

The same with a mixed expression: no piecewise rewriting

live ↗
InPiecewiseExpand(IntegerPart(x2+x),0<x<2)\mathrm{PiecewiseExpand}(\mathrm{IntegerPart}(x^2+\sqrt{x}), 0\lt x\lt2)OutIntegerPart(x2+x)\mathrm{IntegerPart}(x^2+\sqrt{x})

An integer is its own integer part

live ↗
InIntegerPart(1)\mathrm{IntegerPart}(1)Out11

Known value · Wolfram MathematicalFunctionData, IntegerPart

−1-1 is unchanged

live ↗
InIntegerPart(−1)\mathrm{IntegerPart}(-1)Out−1-1

Known value · Wolfram MathematicalFunctionData, IntegerPart

Truncates 2.32.3 to 2

live ↗
InIntegerPart(2310)\mathrm{IntegerPart}(\frac{23}{10})Out22

Known value · Wolfram MathematicalFunctionData, IntegerPart

A negative integer is unchanged

live ↗
InIntegerPart(−3)\mathrm{IntegerPart}(-3)Out−3-3

Known value · Wolfram MathematicalFunctionData, IntegerPart

Truncation toward zero gives −3-3 for −π-\pi

live ↗
InIntegerPart(−π)\mathrm{IntegerPart}(-π)Out−3-3

Known value · Wolfram MathematicalFunctionData, IntegerPart

Negative values round up toward zero: −2.7→−2-2.7\to-2

live ↗
InIntegerPart(−2710)\mathrm{IntegerPart}(-\frac{27}{10})Out−2-2

Known value · Wolfram MathematicalFunctionData, IntegerPart

Simplify cannot reduce ⌊x⌋\lfloor x\rfloor difference even with x≥0x\ge0

live ↗
InSimplify(IntegerPart(x+1)−IntegerPart(x),x≥0)\mathrm{Simplify}(\mathrm{IntegerPart}(x+1)-\mathrm{IntegerPart}(x), x≥0)OutIntegerPart(x+1)−IntegerPart(x)\mathrm{IntegerPart}(x+1)-\mathrm{IntegerPart}(x)

Nested integer parts: the inner one is expanded first, then the outer one over its pieces

live ↗
InPiecewiseExpand(IntegerPart(x+13+IntegerPart(1−x/2)3),x∈R∧−2<x<3)\mathrm{PiecewiseExpand}(\mathrm{IntegerPart}(x+\frac{1}{3}+\mathrm{IntegerPart}(1-x/2)^3), x∈ℝ∧-2\lt x\lt3)OutPiecewise([[1,2/3≤x∧x<5/3∨−1/3≤x≤0],[2,5/3≤x∧x<8/3],[3,8/3≤x]],0)\mathrm{Piecewise}(\bigl\lbrack\bigl\lbrack1, 2/3≤x∧x\lt5/3∨-1/3≤x≤0\bigr\rbrack, \bigl\lbrack2, 5/3≤x∧x\lt8/3\bigr\rbrack, \bigl\lbrack3, 8/3≤x\bigr\rbrack\bigr\rbrack, 0)
live ↗
InIntegerPart(i)\mathrm{IntegerPart}(i)Outii

Known value · Wolfram MathematicalFunctionData, IntegerPart

live ↗
InIntegerPart(−i)\mathrm{IntegerPart}(-i)Out−i-i

Known value · Wolfram MathematicalFunctionData, IntegerPart

live ↗
InIntegerPart(2310−ie)\mathrm{IntegerPart}(\frac{23}{10}-ie)Out2−2i2-2i

Known value · Wolfram MathematicalFunctionData, IntegerPart

Possible issues #

An expression that is exactly 0 gives 0

live ↗
InIntegerPart(1+2π−(1+π)2+π2)\mathrm{IntegerPart}(1+2π-(1+π)^2+π^2)Out00
About
Examples25
Checked againstWolfram Language 23 agree2 differ
CrosswalkWolfram Language