News:

  • June 28, 2026, 08:37:38 PM

Login with username, password and session length

Author Topic: Why does the Math box in line 50 not work?  (Read 8932 times)

Henryp

  • Hero Member
  • *****
  • Posts: 161
Why does the Math box in line 50 not work?
« on: April 01, 2014, 03:31:54 PM »
This ladder is converting a gallon per minute flow rate to million gallons per day.
I don't understand why my GPM value x 1440/1000000 yields a different answer than my GPM value X 0.00144.

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Re: Why does the Math box in line 50 not work?
« Reply #1 on: April 01, 2014, 03:40:07 PM »
Change the first MATH expression to ...

GPM value x 1440.0/1000000.0 (note the .0s)

With no floating point operands the first one is evaluated using integer math.
An output is a PLC's way of getting its inputs to change.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Why does the Math box in line 50 not work?
« Reply #2 on: April 01, 2014, 05:23:58 PM »
Computers have "optimized" integer math and then "floating point" math when needed.

So, 1/2 = 0 (integer divided by integer yields an integer, using TRUNCATION NOT ROUNDING)
2/3 = 0
9/10 = 0
10/10 = 1

Do-more will do everything in integer math UNTIL the expression uses a REAL, THEN ALL REMAINING CALCULATIONS use Floating Point.

So (1 + 4) / 2 = 2
(1 + 4) / 2.0 = 2.5
(1 + 4.0) / 2 = 2.5
TOREAL(1 + 4) / 2 = 2.5  (Do-more's TOREAL() function is usually used on D/V/.Acc integer registers, but can take any "expression" as its parameter)

RAD/DEG/SQRT functions always return a REAL result, regardless of whether its parameter expression type is integer or real.  There might be a couple more that are that way.  Can't remember off the top of my head.  STDEVR/STDEVPR are 2 more.

Henryp

  • Hero Member
  • *****
  • Posts: 161
Re: Why does the Math box in line 50 not work?
« Reply #3 on: April 03, 2014, 01:37:40 PM »
Thanks