Multiply by 100?

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

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:

Multiply by 100?

Post by Jan Lichtenbelt »

I try to calculate the percentage of A compared to B. In the simulation I get the right answer of 98%, but with the 16LF1847 completely wrong result.
Who is that possible. And what to do?
Test_ULong_V1.fcfx
(7.41 KiB) Downloaded 353 times
Results
Results
Test_ULong_V1.jpg (61.32 KiB) Viewed 5370 times
With kind regards

Jan Lichtenbelt
Last edited by Jan Lichtenbelt on Thu Apr 06, 2017 6:21 pm, edited 1 time in total.

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 by 100?

Post by Benj »

Hi Jan,

Is that the right program in the attachment?

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: Multiply by 100?

Post by Jan Lichtenbelt »

Hi Ben,

Sorry but I used the wrong file. Plaes find the Test_Ulong_V1 above.

Jan

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 by 100?

Post by Benj »

Hi Jan,

The calculation D = 100 * B is what is causing the problem.

If you instead change to this then it should work as expected.

D = B
D = D * 100

This forces the * 100 to be a 32-bit calculation.

If you use the PrintFormattedNumber function to print out the D variable then you will see the true 32-bit value on the LCD - 590000.

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: Multiply by 100?

Post by Jan Lichtenbelt »

Hi Ben

Thanks a lot. It works.

Multiplying by a number ( eg. 100) is no problem if one uses Uint. But is seems that in case of Ulong the number has to be changed first into a Ulong variable.


Kind regards

Jan Lichtenbelt

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: Multiply by 100?

Post by medelec35 »

Hi Jan,
One thing I have noticed.
If you want to display correct 590000 instead of 176 then instead of using LCD

Code: Select all

PrintNumber
you can use

Code: Select all

 PrintFormattedNumber
.
Use 1 in the Bool input box for Unsigned number.

Martin
Martin

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: Multiply by 100?

Post by LeighM »

Multiplying by a number ( eg. 100) is no problem if one uses Uint. But is seems that in case of Ulong the number has to be changed first into a Ulong variable.
Yes, it's a "C" thing. It depends upon the size of an "int" on the platform/processor.
So it isn't a problem on say ARM, which is 32 bit.
For interesting reading search "integer promotion" :lol:

Post Reply