Eli5: What is a truncation problem?

873 views

Hey, I’m learning Python and the book is talking about truncation problems when i creat float Numbers out of fractions or decimals. I know what it looks like but I don’t really understand what it means. Please help.

In: Mathematics

4 Answers

Anonymous 0 Comments

[deleted]

Anonymous 0 Comments

“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.

Anonymous 0 Comments

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.

Anonymous 0 Comments

In computing, truncated means “cut short”.

In the scenario your describe, changing from one data type to another could mean the number is truncated, I e. 3.24575432456 becomes 3.25.