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
Multiply integer with float?
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: Multiply integer with float?
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
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
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Multiply integer with float?
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
For example.
floatvar = FLOAT intvar * floatvar2
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel