“Truncated” means to be cut off. The problem that usually arises in computing is when you have a fraction/division that results in a number where the part to the right of the decimal point goes on forever. Since you don’t want to do math that takes an infinite amount of time, at some point you cut it off.
That can make future calculations very slightly wrong. It can be a bit annoying when you calculate 1/3 + 2/3 and get an answer of 0.9999999999. It doesn’t really matter usually, but it’s not pretty and clearly not precise.
The problem is that numbers are given a fixed amount of space in a computer. But sometimes the numbers do not fit. Floating point numbers do this clever trick where they store two numbers in the same space where one represent where the decimal point is, hence the name. This is very similar to scientific notation. However if you do some math that results in a number that requires more precision then is available then you have to truncate it to fit the space, but then you lose some precision. For example (10/3)*3 = (3.33333)*3 = 9.99999 which is a bit off the real answer. Similarly (1+BIG_NUM)-(2+BIG_NUM) = 0 because of the rounding issues. Obviously floating point numbers deals with binary numbers and not decimal numbers so these issues can appear even though they are not obvious when you do the math in the decimal system. But it is something you need to be aware of and it does often help to program defensively for example by avoiding to compare floating point numbers by their exact values.
Latest Answers