Page 1 of 1

Multiply integer with float?

Posted: Tue Oct 13, 2020 11:53 am
by jadiflow
Hi all, question: if I multiply an integer with a floating point number, is the result a float? Will it work correctly?

Jan Didden
Linear Audio

Re: Multiply integer with float?

Posted: Tue Oct 13, 2020 12:34 pm
by mnf
Things should work as you expect,, with FC and the C compiler taking care of type conversions behind the scenes.
If using a constant then use 1.0 (etc) rather than 1 to avoid conversion.

Sometimes need a bit of care for example float = byte * byte - the conversion would take place after the multiplication and if it overflows 8 bits would be wrong..

Martin

Re: Multiply integer with float?

Posted: Tue Oct 13, 2020 1:17 pm
by jadiflow
Thanks Martin, that is helpful.

Jan Didden
Linear Audio

Re: Multiply integer with float?

Posted: Fri Oct 16, 2020 12:03 pm
by Benj
In Flowcode 7 and 8 you can typecast an int as a float for doing calculations using the keyword FLOAT.

For example.

floatvar = FLOAT intvar * floatvar2