Floating point numbers do not work as expected?

Because internally, computers use a format (binary floating-point) that cannot accurately represent a number like 0.1, 0.2 or 0.3 at all. When the code is compiled or interpreted, your “0.1” is already rounded to the nearest number in that format, which results in a small rounding error even before the calculation happens.

The decimal number 31.2 is not representable as a binary fraction. To be more specific, the nearest value of type float is 31.200000762939453125 which is exactly 8178893 * 2-18. If you need a number that is closer to the decimal 31.2, consider using the type double, where your result would be 31.199999999999999289457264239899814128875732421875 or 8782019273372467 * 2-48.

This is the nature of floats. They are not guaranteed to be perfectly accurate. See here for more detail on how/why this is the case.

31.2 is not a representable number in binary floating-point. No matter what calculation is used to produce it, you will never get a float which is exactly equal to 31.2. The answer you got is about as good as you can reasonably expect.

.. But you can try to reduce this possibility. You need to take into account of the exponents for addition/subtraction amongst other things.

The important factors under consideration with float or double numbers are: Precision & Rounding Precision: The precision of a floating point number is how many digits it can represent without losing any information it contains. Consider the fraction 1/3. The decimal representation of this number is 0.33333333333333… with 3′s going out to infinity.An infinite length number would require infinite memory to be depicted with exact precision, but float or double data types typically only have 4 or 8 bytes.

Thus Floating point & double numbers can only store a certain number of digits, and the rest are bound to get lost. Thus, there is no definite accurate way of representing float or double numbers with numbers that require more precision than the variables can hold. Rounding: There is a non-obvious differences between binary and decimal (base 10) numbers.

Consider the fraction 1/10. In decimal, this can be easily represented as 0.1, and 0.1 can be thought of as an easily representable number. However, in binary, 0.1 is represented by the infinite sequence: 0.00011001100110011….

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions