Tag Info

Hot answers tagged

56

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


46

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.


46

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


30

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


27

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


21

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.


21

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

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


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


13

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


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

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


9

If floating point values have rounding problems, and you don't want to have to run into rounding problems, it logically follows that the only course of action is to not use floating point values. Now the question becomes, "how do I do math involving non-integer values without floating point variables?" The answer is with arbitrary-precision data types. ...


8

Well, thorsten has the definitive link. I would add: Any form of representation will have some rounding error for some number. Try to express 1/3 in IEEE floating point, or in decimal. Neither can do it accurately. This is going beyond answering your question, but I have used this rule of thumb successfully: Store user-entered values in decimal ...


7

The comments by @ratchet, @Sjoerd and @Stephane answer you question. Your assertion in the question "All I currently know is that doubles are probably the most expensive because they are larger" shows the rules about optimization - are true - "Only for experts" followed by the "Your not an expert yet" ..... Unless you know the minutest details of the ...


7

The return result will be language specific based upon how the language handles implicit conversions. That having been said, if your language of choice will support returning a float from that implicit conversion, then yes, your example is a pretty common way of triggering the float point arithmetic. It's quick, clean, and clear. Some languages will ...


7

Primitive types in Objective-C are covered by the C standard, since ObjC is an OOP system grafted to C. Which transforms your question to "What special values are there for float/doubles in C?" Most (if not all) compilers will generate float and double arithmetic that conforms to IEEE 754. In this standard, there are 2 types of NaNs (signalling and quiet), ...


6

because base 10 decimal numbers cannot be expressed in base 2 or in other words 1/10 cannot be transformed into a fraction with a power of 2 in the denominator (which is what floating point numbers essentially are)


6

The . is not stored at all. First, you should understand engineering notation, which has a fixed-precision factor and an integer exponent: 1 is 1.0 · 100 = 1.0E0, 2 is 2.0E0, 10 is 1.0E1 etc. This allows for very short notation of large numbers. One billion is 1.0E9. The factor before the E is usually notated as a fixed-precision number: 1.00000E9. A result ...


5

In mathematics, there aer infinitly many rational numbers. A 32 bit variable can only have 2^32 different values, and a 64 bit variable only 2^64 values. Therefore, there are infinitely many rational numbers that have no precise representation. We could come up with schemes that would allow us to represent 1/3 perfectly, or 1/100. It turns out that for ...


5

What you have described are perfectly good work arounds for situations where you control all the inputs and outputs. In the real word it isn't the case. You'll need to be able to cope with systems that supply you their data as some real value to some degree of precision and will expect you to return the data in the same format. In such cases you will ...


4

It might well be more natural to us but there are specific reasons why binary was chosen for digital circuitry and thereby for programming languages. If you have two states you only need to distinguish between two volt settings say 0V and 5V. For each additional increase to the radix (base) you'd need to further divide that range thus getting values that are ...


3

Convert to +INF or -INF as appropriate. The result certainly should be numerical, NaN is logically wrong.


3

In a sentence, floating-point decimal types encapsulate the conversion to and from integer values (which is all the computer knows how to deal with at the binary level; there is no decimal point in binary) providing a logical, generally easy-to-understand interface for calculations of decimal numbers. Frankly, saying that you don't need floats because you ...


3

"God created the whole numbers, everything else is Man’s work." – Leopold Kronecker (1886). By definition, you don't need any other kinds of numbers. Turing completeness for a programming language is based on the simple relationships among the various kinds of numbers. If you can work with whole numbers (a/k/a natural numbers), you can do anything. ...


2

I think you could nowadays built items that could hold any amount of states or even work with analog data. Though building a whole system and getting all the logical components running to get a full featured and programmable architecture would be a lot of work and a financial risk for any company to undertake this task. I think ENIAC was the last ...


2

A clue and an inkling are smaller pieces of information than a bit. Several clues are usually required to establish the definite value of a bit. Inklings are worse: no matter how many you add up, you still can't know the value of the resulting bit for certain. More seriously, there are multi-valued logics where the fundamental unit can have one of n states, ...


2

Storage can be thought as transmission to the future, all of the transmission problems with continuous(analogue) media will apply. Storing those states could be trivial (a three way switch or some sort of grid) and physically storing these states is one issue that many answers cover, much better than I could. My primary concern is how this stored state is ...



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