Cover by Steve McConnell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Integers

Bear these considerations in mind when using integers:

Check for integer division. When you're using integers, 7/10 does not equal 0.7. It usually equals 0, or minus infinity, or the nearest integer, or—you get the picture. What it equals varies from language to language. This applies equally to intermediate results. In the real world 10 * (7/10) = (10*7) / 10 = 7. Not so in the world of integer arithmetic. 10 * (7/10) equals 0 because the integer division (7/10) equals 0. The easiest way to remedy this problem is to reorder the expression so that the divisions are done last: (10*7) / 10.

Check for integer overflow. When doing integer multiplication or addition, you need to be aware of the largest possible integer. The largest possible ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required