TI-BASIC:Ipart

From Learn @ Cemetech
Jump to navigationJump to search

IPART.GIF

Command Summary

Returns the integer part of a value.

Command Syntax

iPart(value)

Menu Location

Press:

  1. MATH to access the Math menu.
  2. RIGHT to access the NUM submenu
  3. 3 to select iPart(, or use arrows.

Calculator Compatibility

TI-83/84/+/SE

Token Size

1 byte

iPart(value) returns the integer part of value. Also works on complex numbers, lists and matrices.

iPart(5.32)
               5
iPart(4/5)
               0
iPart(‾5.32)
               ‾5
iPart(‾4/5)
               0

The difference between iPart( and Int( is subtle, and many people aren't even aware of it, but it exists. Whereas iPart( always truncates its parameters, simply removing the integer part, int( always rounds down. This means that they return the same answers for positive numbers, but int( will return an answer 1 less than iPart( for (non-integer) negative numbers. For example, iPart(-5.32) is -5, while int(-5.32) is -6.

Most of the time, however, you're dealing with only positive numbers anyway. In this case, the decision to use iPart( or int( is mostly a matter of preference - some people only use int( because it is shorter, some people use iPart( when there is a corresponding FPart( taken. However, see the Command Timings section.

Advanced Uses

iPart(, along with FPart( and Int(, can be used for integer Compression.

Command Timings

The following table compares the speeds of Int( and iPart(. Each command was timed over 2000 iterations to find a noticeable difference.

Format Bars Pixels Total
iPart(1 10 1 81
iPart(1.643759 10 1 81
int(1 8 7 71
int(1.643759 10 2 82

Conclusion: Unless there are 6 or more decimals, you should consider using int( because of its speed, but with a lot of decimals, iPart( stays the same so it goes faster.

Related Commands

See Also