Search In
• More options...
Find results that contain...
Find results in...

# 0.1 + 0.1 + 0.1 does not equal 0.3

## Recommended Posts

... at least according to most programming languages.

I've actually known this for a while, but I felt like saying it now.

... so what does it equal O_o

0.30000000000000000004 or something like that. Therefore, the language will tell you that they're not equal.

Meanwhile, in "learn your tech" land, most programmers attribute that to floating point inaccuracies. The FPU is great and fast for the most part, but is known to lose accuracy. In the case of the amount of digits there though, it appears to be a double precision floating point number, which is done in software (unless you're a shiny new 64 bit processor). If you really want accuracy with your fractional numbers, try fixed point processing (stability traded off with flexibility).

That's just wonderful, AndrewB. I feel so enlightened.

Fixed point processing is basically just using integers that are divided by whatever.

The most common implementations are divided by powers of two. There are a few other methods some of which are explained in here.

Fun fact: the PS2's main processor (the EE) has no FPU. All operations are done in fixed point arithmetic. Only the Vector Units perform operations in floating point arithmetic. I doubt most of you have access to a PS2, but you'll ********ly notice that this is true if you try something like 1.f / 60.f * 60.f on the EE as opposed to trying it on your PC.

EDIT: Why the fuck is D E F I N A T E being starred out?

,

because ling is a big jerk.

Psyonisis said:

Because it's spelled 'definite'.

Not in Australia.

GooberMan said:

In the case of the amount of digits there though, it appears to be a double precision floating point number, which is done in software (unless you're a shiny new 64 bit processor).

Uhh no, 32-bit x86 processors (and many others) do floating-point math with 80 bits precision in hardware.

And of course, since 0.1 can't be represented accurately as a binary fraction no matter how many bits you use, it doesn't matter if a float or double or quad is used. If precision is needed, use ints (multiplying all values by 100 or whatever first) or a decimal type instead.

GooberMan said:

Not in Australia.

Are you serious?

AndrewB said:

0.30000000000000000004

This is (un)commonly known as the epsilon error.

There is one fundamental reason why this occurs. Can anyone say what it is?

The IEEE 754 standard is a method of storing floating-point numbers in a compact way that is easy to manipulate. This standard is used by Intel coprocessors and most PC-based programs that implement floating-point math.

IEEE 754 specifies that numbers be stored in binary format to reduce storage requirements and allow the built-in binary arithmetic instructions that are available on all microprocessors to process the data in a relatively rapid fashion. However, some numbers that are simple, nonrepeating decimal numbers are converted into repeating binary numbers that cannot be stored with perfect accuracy.

For example, the number 1/10 can be represented in a decimal number system with a simple decimal:
.1
However, the same number in binary format becomes the repeating binary decimal:
.0001100011000111000111 (and so on)
This number cannot be represented in a finite amount of space. Therefore, this number is rounded down by approximately -2.78E-17 when it is stored.

If several arithmetic operations are performed to obtain a given result, these rounding errors may be cumulative.

AndrewB said:

There is one fundamental reason why this occurs. Can anyone say what it is?

Yes.

Fredrik said:

0.1 can't be represented accurately as a binary fraction no matter how many bits you use

GooberMan said:

Not in Australia.

Not even Australians are that dumb.

Captain Red said:

because ling is a big jerk.

I'd like it if people learned to fucking spell. Ling's done a good thing.

Syzmanski wins the award.

... However, I believe the binary number for 1/10 is 0.00011001100 ... not whatever it was you said.

I said it first, damnit.

And he cheated.

I sorta cheated, I've had it explained before by the guy who writes the drivers for our hardware. But it's easier to copy+paste.

Captain Red said:

because ling is a big jerk.

WRONG

GooberMan said:

Not in Australia.

Any other wierd ways to spell words you'd like to share with us?

Fredrik said:

Uhh no, 32-bit x86 processors (and many others) do floating-point math with 80 bits precision in hardware.

Oops. I remembered the FPU did processing with 80 bits, dunno why I thought it did double in software.

Everyone said:

Australian spelling differences

There are plenty. Jail is spelt gaol for example. Civilization is spelt civilisation (in fact, many words with a z similar to above is spelt with an s).

don't forget coloUr ;)

Captain Red said:

because ling is a big jerk.

Or he's prejudice against Australians.

Bloodshedder said:

This is (un)commonly known as the epsilon error.

I call it racism. All numbers are not equal? FOR SHAME.

0.99999999999.... = 1

fraggle said:

0.99999999999.... = 1

ARGH ARGH ARGH ARGH ARGH ARGH ARGH
For the love of God
ARGH ARGH ARGH ARGH ARGH ARGH ARGH

fraggle said:

0.99999999999.... = 1

Then I take it 3 = 1 × 3 = 0.99999999... × 3 = 2.9999999....997, mister clever?

Ling is an arse and should definately definitely go to gaol for his Prejudice ageist Australians. Anyway, I’ve got to put some Petrol in the car (it can go up to 160 kilometres per hour!) and paint the house a different colour. After that, I think I’ll play Medal of Honour, or maybe some Zed-doom.

:P

Paaaaaaaaach the caaaaaaaaaaaaaaaaaant!