# Tag Info

99

Here's the key to your quandary: 10 is the product of 2 and 5. You can represent any number exactly in base 10 decimals that is k * 1/2n * 1/5m where k, n and m are integers. Alternatively phrased - if the number n in 1/n contains a factor that is not part of the factors of the base, the number will not be able to be represented exactly in a fixed number ...

68

Computation in science and engineering requires tradeoffs in precision, range, and speed. Fixed point arithmetic provides precision, and decent speed, but it sacrifices range. BigNum, arbitrary precision libraries, win on range and precision, but lose on speed. The crux of the matter is that most scientific and engineering calculations need high speed, and ...

61

This is because some fractions need a very large (or even infinite) amount of places to be expressed without rounding. This holds true for decimal notation as much as for binary or any other. If you would limit the amount of decimal places to use for your calculations (and avoid making calculations in fraction notation), you would have to round even a simple ...

57

Of course it is possible, both theoretically and practically. Theoretically, there are two classes of alternatives: digital number systems with a base other than 2 (in fact, the decimal system as we know it is one such system); and non-digital number systems. Mathematically speaking, we're talking about discrete vs. continuous domains. In practice, both ...

50

You use them when you're describing a continuous value rather than a discrete one. It's not any more complicated to describe than that. Just don't make the mistake of assuming any value with a decimal point is continuous. If it changes all at once in chunks, like adding a penny, it's discrete.

48

Primarily, rounding errors come from the fact that the infinity of all real numbers cannot possibly be represented by the finite memory of a computer, let alone a tiny slice of memory such as a single floating point variable, so many numbers stored are just approximations of the number they are meant to represent. Since there are only a limited number of ...

36

Your argumentation against floating point numbers is very fragile, probably because of naivety. (No offense here, I find your question is actually very interesting, I hope my answer will also be.) A classic argument is that floats provide a greater range, but high precision integers can meet this challenge now. For example: with modern 64-bit ...

36

You need to keep in mind that in FPU arithmetics, 0 doesn't necessarily has to mean exactly zero, but also value too small to be represented using given datatype, e.g. a = -1 / 1000000000000000000.0 a is too small to be represented correctly by float (32 bit), so it is "rounded" to -0. Now, let's say our computation continues: b = 1 / a Because a is ...

28

You really have two questions here. Why does anyone need floating point math, anyway? As Karl Bielefeldt points out, floating point numbers let you model continuous quantities - and you find those all over the place - not just in the physical world, but even places like business and finance. I've used floating point math in many, many areas in my ...

27

What alternative do you propose? Continuous quantities are represented using real numbers in mathematics. There is no data type that can encode every possible real number (because reals are uncountable), so that means we can only pick a subset of those real numbers that we're most interested in. You can pick all computable reals, which is similar to what ...

26

Because they are, for most purposes, more accurate than integers. Now how is that? "for speed of an object in a game..." this is a good example for such a case. Say you need to have some very fast objects, like bullets. To be able to describe their motion with integer speed variables, you need to make sure the speeds are in the range of the integer ...

26

To simplify things by defining a concrete implementation, I will assume (as other answers do) that we're talking about IEEE 754 64-bit floating point. Each floating point number has three parts: a sign, an exponent, and a mantissa. (Technical details about hidden bits are irrelevant to this discussion). Reciprocation doesn't affect the sign 1 / (2**e * m) ...

23

Because switching to integers doesn't solve anything. The problem with floats isn't that they have inaccuracies, it's that half the people using them don't pay any attention to what's going on. Those same people aren't going to pay proper attention to the units they are using when they use an integer, and a different set of screw ups will happen. Repeat ...

22

Those are called qubits, and are used in quantum computers. You'll find more information about them on the wikipedia entry. Research is being done to make such computers that are stable and economically feasible.

22

You're basically describing an analog signal, which are used in sensors, but rarely for internal computations. The problem is noise degrades the quality, you need very precise calibration of a reference point that is difficult to communicate, and transmission is a problem because it loses strength the farther it travels. If you're interested in exploring ...

21

It's a common misconception, that everywhere you're dealing with money, you should store it's value as integer (cents). While in some simple cases like on-line store it's true, if you have something more advanced it doesn't help much. Let's have example: a developer makes \$100,000 a year. What is his exact month's salary? Using integer you get result ...

20

Physical characteristics of the universe (like the number of atoms in it) are not useful to determine the boundaries of number sizes, because useful calculations exist using numbers having wider ranges. Floating point numbers are a tradeoff between accuracy and range. They deliberately give up some accuracy to achieve greater range.

17

A matter of accuracy One reason we use bits is that it helps us store and retrieve information accurately. The real world is analog, therefore all the information computers pass or store is ultimately analog. For example, a current of a specific voltage on a wire, or magnetic charge of a specific strength on a disk, or a pit of a specific depth on a laser ...

15

The decimal point is not explicitly stored anywhere; that's a display issue. The following explanation is a simplification; I'm leaving out a lot of important details and my examples aren't meant to represent any real-world platform. It should give you a flavor of how floating-point values are represented in memory and the issues associated with them, ...

14

Because most of the processors that you use in your day to day life are not modern day 64 bit processors with crazy fast integer calculations or an over abundance of space. Most of your processors are 8-16 bit devices which run things like your car, microwave, or watch. Besides, what happens when you need to talk about a half of a unit, like a half of a ...

13

No. There is not a snowball's chance in Hell that numerical computing will switch (back) to fixed-point arithmetic in the near future, or in ANY future. There are several reasons for this, the biggest one being that doing fixed-point arithmetic requires that the programmer keep track of the final position of the decimal (binary) point in the calculation. ...

13

Variances in the "least significant digit" can cause the entire number to be rounded in the wrong direction. Lets take an item that costs \$0.705 - the half cent is from discount, or tax or something, or this is a 10% discount on something that is \$7.05. Whatever the case... three of them and we're computing the price (or discount). The total price is ...

13

Short answer It was a bug. Well, not exactly a bug, but the behavior was changed based on a proposal for Python 3. Now, ceil and floor return integers (see also delnan's comment). Some details are here: http://www.afpy.org/doc/python/2.7/whatsnew/2.6.html Why Python originally returned floats This question has some nice answers about the behaviour ...

12

Your proposition about science is wrong, Engineering and Science other then Math don't work with exact precise results. They work with a precision factor which is built into how many digits you show. The key term you need to understand here is: significant figures. The significant figures of a number are those digits that carry meaning contributing to its ...

11

There are three fundamental approaches to creating alternative numeric types that are free of floating point rounding. The common theme with these is that they use integer math instead in various ways. Rationals Represent the number as a whole part and rational number with a numerator and a denominator. The number 15.589 would be represented as w: 15; n: ...

11

Floating point stores the exponent and mantissa in base two, not base 10. Two to the 127th power corresponds roughly to ten to the 38th power, so that's the largest decimal number that can be stored. See https://www.google.com/#q=2+to+the+127th+power

11

If the documentation makes no special mention, is it implied that these kinds of functions are completely accurate to the last decimal place, within the precision offered by IEEE double-precision floating-point? I wouldn't make that assumption. Where I work we deal with telemetry data, and it's common knowledge that two different math libraries can ...

10

There are also ternary computers instead of binary ones. http://en.wikipedia.org/wiki/Ternary_computer A ternary computer (also called trinary computer) is a computer that uses ternary logic (three possible values) instead of the more common binary logic (two possible values) in its calculations...

10

Using a float instead of a high precision integer (with conversions!) is simply easier and faster. I can type in float myVar = 0.15; //my value... and move on to the rest of the logic of my simulation. I don't have to spend extra time thinking about converting to int and making sure that all of my scales are correct. And the results end up being good ...

10

I'm working on a report as I type this. One of the fields is a long milliseconds of duration that I got from somewhere else. This is going to be sent to Microsoft Excel and the duration units it uses is decimal days (1.25 = 1 day, 6 hours). Sure, you can subdivide a range from the lowest possible value to the largest and have integer units stepping ...

Only top voted, non community-wiki answers of a minimum length are eligible