Calculations with brackets

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Calculations with brackets

Post by Jan Lichtenbelt »

I simulate the calculation in Flowcode 4 with variable I(byte):
I=8
I=6*(I/3)
This gives for me the unexpected results of I=16 instead of I=12. It looks like the brackets are not seen.
The following calculation :
I=8
I=I/3
I=6*I
This gives I=12 as expected.

I tried to check the C and asm files, but both looks correct. That means in asm first de division has been done before the multiplication.
Then I downloaded the program into PIC16F88, which shows as results of the first calculation the expected 12! That means the brackets in Flowcode 4 simulation are not seen. Be prepared!

Jan

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

Re: Calculations with brackets

Post by Steve »

This is a known issue, but is actually not directly a fault of the brackets. It is because in simulation, all calculations are performed as if the numbers are floats until they are placed into an actual variable.

So, I = 6*(I/3) = 6*(8/3) = 6*(2.66666) = 16.0000

Only once the calculation is complete does the float get changed to an integer.

Doing the calculation in separate steps works because the I = I/3 = 2.66666 gets turned into 2 because it is being placed into the "I" variable.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Calculations with brackets

Post by medelec35 »

Hiya Jan,
This is an issue I raised concern with here:
http://www.matrixmultimedia.com/mmforum ... =31&t=7714
Martin

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: Calculations with brackets

Post by Jan Lichtenbelt »

Dear Steve and Medelec,

I was afraid this was not a new issue. But I could not find the answer in the Forum.

Both thanks

Jan

Post Reply