FLOATING POINT MATHS

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
wayne millard
Posts: 234
Joined: Thu May 31, 2007 2:18 pm
Has thanked: 7 times
Been thanked: 12 times

FLOATING POINT MATHS

Post by wayne millard »

Can you please provide a flowcode example of floating point maths.
With one number that divides into the other.

Looked at the example but don't understand how to use it for simple maths.

Thanks
Wayne M

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Post by Steve »

In the top box of the "supplementary code" window, you need to add the following line:

Code: Select all

#include <float.h>
Also, create an INT variable called "x".

Then, put this C code into a 'C' icon:

Code: Select all

float x = 1238.56;
float y = 10.0;
float z;
z = float32_div(x,y);
FCV_X = float32_to_int32(z);
At the end of this, your variable "X" will contain the value 124.

The functions available are in the "float.h" file (in the "boostc\include" directory). Here's a summary:

Code: Select all

// Software IEC/IEEE integer-to-floating-point conversion routines.
float float32_from_int32( int32 );

//Software IEC/IEEE single-precision conversion routines.
int32 float32_to_int32( float );
int32 float32_to_int32_round_to_zero( float );

// Software IEC/IEEE single-precision operations.
float float32_round_to_int( float );
float float32_add( float, float );
float float32_sub( float, float );
float float32_mul( float, float );
float float32_div( float, float );
float float32_rem( float, float );
float float32_sqrt( float );

wayne millard
Posts: 234
Joined: Thu May 31, 2007 2:18 pm
Has thanked: 7 times
Been thanked: 12 times

floating point maths

Post by wayne millard »

Sorry still not understand have you got a simple example of a number that is divide by other number.

Sorry
Thanks
Wayne M

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Post by Steve »

The first half of the post contains the answer. Your variable "x" will contain the result of the division 1238.56 / 10.0.

You need to use the "float32_XXX" functions to convert between integers and floating point numbers, and to perform calculations on the floating point numbers.

wayne millard
Posts: 234
Joined: Thu May 31, 2007 2:18 pm
Has thanked: 7 times
Been thanked: 12 times

floating point maths

Post by wayne millard »

Steve,

sorry.

how do i use float32_XXX. do i need to call this in flowcode.
Because i can see this in the example but do not understand how to use it.
do i need to put float32 C code in to the flowcode to call float32.

Wayne M
:D

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Post by Steve »

Yes, the functions need to be called from within a C icon.

Note that the code will not simulate.

Post Reply