Floating point Precision -- Is this expected difference?

Continuing the discussion from Double floating-point precision for all indicator/math calculations:

Amibroker version - 32 bit, 6.35.1.

Dear Experts,

image

For the 9:26:00 AM row, H= 320.7, L=320.2, C=320.25.
Range = H-L = 0.5 it is as expected.
H-C = 0.45 Expected (from windows calculator) and but it is coming as 0.4500122 in amibroker.

From other discussions on the forum, the difference should be coming from the floating precisions. I just need a confirmation that it is as expected.

if I have if conditions, such as candle_body = (c-o)

                  if(candle_body[i]>.9)
			body_score[i] = 20;
		else if(candle_body[i]>.8)
			body_score[i] = 20;
		else if(candle_body[i]>.7)
			body_score[i] = 16;
		else if(candle_body[i]>.6)
			body_score[i] = 16;
		else if(candle_body[i]>.5)
			body_score[i] = 12;
		else if(candle_body[i]>.4)
			body_score[i] = 12;
		else if(candle_body[i]>.3)
			body_score[i] = 8;
		else if(candle_body[i]>.2)
			body_score[i] = 8;
		else if(candle_body[i]>.1)
			body_score[i] = 4;	
		else if(candle_body[i]>=0)
			body_score[i] = 0;

then, it can result in different values than the manual calculations. So, is there any solution or have to just live with it ? Will this be better in 64 bit amibroker ?

Thank you!

It has been already explained to death in a numerous threads and articles. All results that you got are 100% in-line with IEEE754 and they are as expected and correct (as per IEEE754 standard) All calc are done in HARDWARE. Amibroker does not do them - YOUR CPU does.

1 Like

Thanks Tomasz. I understand this has been visited and revisited many times. Sincerely appreciate answering again. My confusion arose from [windows calculator app] which probably is using higher precision. (Windows Calculator - Wikipedia).)
"In Windows 98 and later, it uses an arbitrary-precision arithmetic library, replacing the standard IEEE floating point library" ..

Calculators generally (including pocket hand held calculators) pretty much NEVER use IEEE standard, but proprietary solutions, pretty often using BCD (binary coded decimal) and they behave differently and are slow. They also display results that are rounded to much less digits than internal representation. If you displayed the result rounded to two decimals you would see your 0.45.

IEEE754 is implemented in HARDWARE for SPEED, not for "decimalism". First and foremost thing to remember is that computers work in BINARY system, not decimal (unless of course somebody uses BCD), so all numbers must be represented in BINARY form. Your 320.7 and 320.2 have both INFINITE binary representation that is subject to rounding in BINARY.

1 Like

Thanks again Tomasz. I have always learnt something new just going through your posts.

Adding 2 links to the post. This might help others.

What Every Computer Scientist Should Know About Floating-Point Arithmetic

Decimal Arithmetic Specification, version 1.70 :: mentioned in https://docs.python.org/3/library/decimal.html#

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.