NormalizeDouble

 

Ive been having a problem in my code I think i have it narrowed down to my use of NormalizeDouble, i tested NormalizeDouble to see what its output is with this simple code:

double var=1.12345678;

Alert)"var= ",var);

NormalizeDouble(var,1);
Alert("normalizedvar= ",var,1);

output is

var= 1.1235

normalizedvar=1.1235

i didnt expect var to be automatically rounded down to 4 decimal places before normalizing but it is,

I expected after NormaliseDouble the variable would be rounded down to 1 decimal place but it isnt, it is still 1.1235

why is this ? is normalizedouble not what i thought it was ?

 

The OUTPUT of normalizedouble function is rounded to the specified digits...NOTHING is done to the inputs themselves.

try:

double var=1.12345678;

Alert("var= ",var); // <- corrected left-bracket typo

double normalizedvar = NormalizeDouble(var,1);
Alert("normalizedvar= ",normalizedvar);
 

ahh i see, thats what was causeing my whole function to malfunction !! thanks Phillip !!

 

This is why my function wasnt working properly, it uses a fib sequence and I discovered the golden ratio number 1.618 isnt really true, it is almost true but not quite, it is a few hundredths out so to create a fib sequence from it I needed to normalise each time to 0 places. it works now like this, so now the whole function has the correct values to work on. Thanks again Phillip.

for(fib=1; fib<1000; fib=NormalizeDouble(fib*1.618,0)) //fib sequence

 

 
The default output of Alert and Print is four digits. To see the real values use Alert(DoubleToStr(var,8)) or
Alert("var="+var,", Norm="+normalizedvar);