Guest matic Posted November 18, 2015 Report Share Posted November 18, 2015 Hi, on Samba SM43-J-T20 I am using formula block to calculate simple equation "OUT = A / B * 1000000", where OUT is ML, operand A is MI (range 0 - 10000) and operand B is MI (constant 15747). Is it possible to get exact rounded integer result calculated with floating point registers without using any MF operand? In Help it says: In the following cases, controller will process the formula using floating registers: If the formula contains one or more floating operands. If a constant value in the formula is not a whole number If an operator, such as trigonometric operators, requires that the PLC use a floating register to complete its operation. If I use constant 1000000,0 or 1000,0 * 1000,0 in the formula it does not use floating point registers. For testing I have tried the following formulas (A = 5000, B = 15747): (1000,1 * ( 1000,1 * A ) ) / B result was 44772 (999,9 * ( 1000,1 * A ) ) / B result was 317521 ( ( 1000,1 * A ) / B ) * 1000,1 result was 317000 ( ( 1000,1 * A ) / B ) * 999,9 result was 317521 Can somebody explain these results and give some guidelines on how correctly use formula block. Regards, Matic Quote Link to comment Share on other sites More sharing options...

Alexander Posted November 19, 2015 Report Share Posted November 19, 2015 The nature of floating point operands it to be able to hold very small and very large numbers using a scientific format. Due to the nature of how the 32 bit floats operate they often will have small rounding errors as their format is not exact. For this reason we do not recommend using the float operands for precise math operations. If possible whole number integers such as a Memory Long or Double Word may be used instead. Although they do not have a true decimal point, a theoretical one can be applied and displayed on the HMI. Quote Link to comment Share on other sites More sharing options...

MVP 2022 Flex727 Posted November 19, 2015 MVP 2022 Report Share Posted November 19, 2015 By the way, this is not a problem with VisiLogic or Unitronics, this problem occurs with any computer system that operates in binary. The conversion of fractional numbers between binary and decimal cannot always be exact without an infinite number of digits. Quote Link to comment Share on other sites More sharing options...

Guest matic Posted November 19, 2015 Report Share Posted November 19, 2015 I understand the nature of floating point numbers and I am aware that each number is represented by a finite number of digits and exponent. What I do not understand is how Formula block works. I cannot agree that this is not a Visilogic issue. All four formulas in my first post give the same and "correct" (expected) result if one of the operands (A, B or OUT) is MF. It is obvious that 1st and 3rd formula are not calculated with floating point registers. But Help says they should be if they contain a floating point constant which they do (1000,1 and 999,9). 1st formula gives correct results if A < 2148. When A is greater overflow happens as 1000*1000*5000 is greater than 2^31= and thus the final result is 44772 3rd formula also does not use floats. Result of equation in parenthesis is 317, multiplied with 1000 gives the final result 317000. My questions are: 1.) Why 2nd and 4th formula are calculated with floating point registers and why 1st and 3rd formula are not? I think this is Visilogic problem on how it reads the formula block and compiles it... 2.) Does PLC have a status bit to indicate an integer overflow when it happens? I could not find any. 3.) Is using the MF operands the only option which guarantees the Formula block calculations are done with floating registers? Quote Link to comment Share on other sites More sharing options...

## Recommended Posts

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Note:Your post will require moderator approval before it will be visible.