Multiply integer with float?

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Multiply integer with float?

Post 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

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Multiply integer with float?

Post 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

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: Multiply integer with float?

Post by jadiflow »

Thanks Martin, that is helpful.

Jan Didden
Linear Audio

User avatar
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?

Post 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

Post Reply