Trying to increase precision, from FLOAT to DOUBLE when multiplying

I thought to write a small plugin that will give me more precision when multiplying numbers. It will take two FLOAT numbers, convert them to DOUBLE, multiply them, then pass the result to Amibroker.

My tests show that the plugin gives exactly the same results as if I made the multiplication from inside Amibroker, with FLOAT variables.

Here is the plugin code:

AmiVar VFloatMultiply( int NumArgs, AmiVar *ArgsTable )
    AmiVar result;

    float x1 = ArgsTable[ 0 ].val; 
    float x2 = ArgsTable[ 1 ].val; 
 double d1 = x1;
 double d2 = x2;
 double d3 = d1*d2;
    result.type = VAR_FLOAT;
    result.val = d3;
    return result;  

Why am I not getting different results? Am I doing some programming error, or is my logic flawed?

Why do you expect different result? They should be the same since you store the result in float and they are.


I would expect that double multiplication (d1 x d2) is more accurate that float (x1 x x2). But probably the difference is too far to the right of the decimal point.

The first 7 significant digits of the result obviously are the same, they are accurate enough. Then I convert it back to FLOAT and the rest of the digits change as if I had multiplied x1 x x2.

Makes sense, I guess.

There is no gain. If you cast from float to double they do not magically gain more resolution. That is the same as you copied analog vinyl recording to Digital 24 bit 192 kHz. You won't get automagically more dynamics or less noise than in the original source material. Also when you convert from double to float you obviously truncate to 32-bit IEEE which has 7 significant digits.

Of course. It is the multiplication that I was hoping to have some benefit.