Floating error  [SOLVED]

Questions about MultiCharts and user contributed studies. stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Floating error

Hi,

Hope that someone can help.

I have problem with floating error. I know that it is because you are deviding with zero.
I have tried though to multiply with 1.0000001 but it does not help.

Anyone that can suggest a better way to write the code below?

Best regards
Stefan
Value1= ((C+2*StdDev(C,20)-average(C,20)) / (4*(StdDev(C,20)))*100);

TJ
Posts: 7210
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2052 times

Re: Floating error

Hi,

Hope that someone can help.

I have problem with floating error. I know that it is because you are deviding with zero.
I have tried though to multiply with 1.0000001 but it does not help.

Anyone that can suggest a better way to write the code below?

Best regards
Stefan
Value1= ((C+2*StdDev(C,20)-average(C,20)) / (4*(StdDev(C,20)))*100);

Please show us what/how you tried to correct the problem. stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: Floating error

Something like this:
value1=(C+2*StdDev(C,length)-average(C,length))*1.0000001;
Value2=(4*(StdDev(C,length)))*1.0000001;
Value3= ((value1)/(value2)*1.000001) *100;

TJ
Posts: 7210
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2052 times

Re: Floating error

What is zero times 1.0000001 ? stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: Floating error

you are right. How can i come around that then? stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: Floating error  [SOLVED]

I should add 0.000001 then? stefanols
Posts: 51
Joined: 01 Jan 2014
Has thanked: 14 times
Been thanked: 2 times

Re: Floating error

Thanks!

ABC
Posts: 631
Joined: 16 Dec 2006
Has thanked: 119 times
Been thanked: 356 times
Contact:

Re: Floating error

I should add 0.000001 then?
stefanols,

what if Value2 = -0.000001?

I would suggest to check if the denominator of a division is different than 0 (for every division that you perform within a code). If it is, do the division otherwise you can do something else (optional).

For example:

Code: Select all

if denominator <> 0 then
result = numerator / denominator
else
result = 0 ;
Regards,

ABC