You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old June 11th, 2018, 11:56 AM   #1
Elnes
Member
Canada

Elnes is offline
 
Join Date: Jun 2018
Location: montreal
Posts: 5
multiplication wrong answer

Hi, I am trying to do this calculation in structured text with studio 5000:

(2147483647/ (117 / 241.23 *20))

all the numbers are stored in variables.

It looks simple but i don't get the same answer then in my excel spreedsheet.

any idea what it could be ? i tried with all real variable and all dint ( except for the 241.23 )

any hint ?

thx !
  Reply With Quote
Old June 11th, 2018, 12:02 PM   #2
LoganB
Lifetime Supporting Member
United States

LoganB is offline
 
Join Date: Apr 2017
Location: Michigan
Posts: 477
does either of them give you the answer 221383538.5323974?

Using the numbers you supplied
__________________
Present: Controls Engineer
Future: Skynet Engineer
  Reply With Quote
Old June 11th, 2018, 12:05 PM   #3
Elnes
Member
Canada

Elnes is offline
 
Join Date: Jun 2018
Location: montreal
Posts: 5
in fact they both give me 221383536 or 221383536.0 and the answer i want is the one you gave me
  Reply With Quote
Old June 11th, 2018, 12:12 PM   #4
Ron Beaufort
Lifetime Supporting Member
United States

Ron Beaufort is offline
 
Ron Beaufort's Avatar
 
Join Date: Jul 2002
Location: Charleston, SC
Posts: 5,412
sometimes you just can't get "there" from "here" ...

warning ... you're not going to like this answer ...

put the "math" aside for a second - and try this simple demonstration ...

just go to a "REAL" number location in the controller's memory - and manually type in the following value ...

123456789

what do you see when you hit the enter key? ...

HINT ... it won't be 123456789 ...

so ...

once you are aware that the number systems in the PLC have "limitations" then you can start understanding why certain math operations don't work right ...
__________________

2-B ?
Best regards, ----+----] [----+------------( )----
Ron | |
PLC Training Boot Camp | 2-B |
+----]/[----+

I once was lost, but now am found, was blind, but now I see.


Last edited by Ron Beaufort; June 11th, 2018 at 12:56 PM.
  Reply With Quote
Old June 11th, 2018, 12:22 PM   #5
Elnes
Member
Canada

Elnes is offline
 
Join Date: Jun 2018
Location: montreal
Posts: 5
Quote:
Originally Posted by Ron Beaufort View Post
warning ... you're not going to like this answer ...

put the "math" aside for a second - and try this simple demonstration ...

just go to a "REAL" number location in the controller's memory - and manually type in the following value ...

123456789

what do you see when you hit the enter key? ...

HINT ... it won't be 123456789 ...

so ...

once you are aware that the number systems in the PLC have "limitations" then you can start understanding why certain math operations don't work right ...
mmm interesting... 123456792.0

I tried with the value that should be my answer and it does change the 221383538.5 into 221383536

do you know what exactly is the logic behing this ?
  Reply With Quote
Old June 11th, 2018, 12:42 PM   #6
GaryS
Member
United States

GaryS is offline
 
GaryS's Avatar
 
Join Date: Aug 2003
Location: Lancaster Pa.
Posts: 680
it may the way you are doing the math
(117 / 241.23 *20))

should be( 117((241.23*20) ) or ((117/241.23)*20)
what ever way you need to do the math
The standard is innermost brackets are calculated first then the next level out in your case it doing the math in the wrong order. From the way you displayed it I can't tell what order you want calculate it.
  Reply With Quote
Old June 11th, 2018, 12:50 PM   #7
Elnes
Member
Canada

Elnes is offline
 
Join Date: Jun 2018
Location: montreal
Posts: 5
@GaryS

The operation I need it (2147483647/((117/241.23)*20)) I did not put the () because of the priorisation of operations. But it still give me the wrong answer with the ().
  Reply With Quote
Old June 11th, 2018, 12:51 PM   #8
LoganB
Lifetime Supporting Member
United States

LoganB is offline
 
Join Date: Apr 2017
Location: Michigan
Posts: 477
I followed PEMDAS to give him the correct answer. Inner brackets first, left to right with all multiplication and division. The problem is how the PLC stores numbers that large, but I don't know the answer to how to get around that.
__________________
Present: Controls Engineer
Future: Skynet Engineer
  Reply With Quote
Old June 11th, 2018, 01:17 PM   #9
GaryS
Member
United States

GaryS is offline
 
GaryS's Avatar
 
Join Date: Aug 2003
Location: Lancaster Pa.
Posts: 680
What PLC are you using?
Rockwell used 2 different formats to store numbers
INT and DINT are stored and used a bits words
Real or Floating Point data uses the EEE numbers format
Large numbers don't convert well between the 2
Real number store the number with engineering note
try to do the same calculation using real data type
  Reply With Quote
Old June 11th, 2018, 01:22 PM   #10
Elnes
Member
Canada

Elnes is offline
 
Join Date: Jun 2018
Location: montreal
Posts: 5
@garyS

I tried to use both Dint and real, and they gave me the same answer. If i use smaller numbers, i get good answers. For now I will try to figure a way of using smaller numbers to get at the same results.

Still i am curious about the way these big numbers are managed by the PLC
  Reply With Quote
Old June 11th, 2018, 01:40 PM   #11
Mickey
Lifetime Supporting Member
United States

Mickey is offline
 
Mickey's Avatar
 
Join Date: May 2003
Location: Palmdale,Ca
Posts: 10,088
Quote:
Originally Posted by Elnes View Post
@garyS


Still i am curious about the way these big numbers are managed by the PLC

https://www.google.com/search?ei=WcA....0.Zun4gURB9co
__________________
Mickey

If you want happiness for an hour-take a nap. If you want happiness for a day-go fishing. If you want happiness for a month-getmarried. If you want happiness for a year-inherit a fortune. If you want happiness for a lifetime-help someone else.
----- Chinese Proverb
  Reply With Quote
Old June 11th, 2018, 01:47 PM   #12
Peter Nachtwey
Member
United States

Peter Nachtwey is offline
 
Peter Nachtwey's Avatar
 
Join Date: Apr 2002
Location: Vancouver, WA, US
Posts: 6,694
Which numbers are constants that can be computed ahead of time on a calculator or spread sheet? Which numbers are from variables?

2147483647 = 2^31-1
Why are you using this number? What are you really trying to do because I bet what you are doing what you really want to do the wrong way.

My simple answer is that the computer doesn't have enough resolution to be lazy about the math. Some simplification needs to occur.
"You don't always get what you want, but get what you need."
__________________
"Living is easy with eyes closed, misunderstanding all you see...." Strawberry Fields Forever, John Lennon
  Reply With Quote
Old June 11th, 2018, 01:52 PM   #13
osmanmom
Member
Malaysia

osmanmom is offline
 
Join Date: Mar 2014
Location: JOHOR
Posts: 1,423
refresh and exercise


a:=((2.0/ (2.0 )))/ ((2.0 *2.0));

b:=(2.0/ 2.0) /(( 2.0 *2.0));

c:=(2.0)/( 2.0) /(( 2.0)) *((2.0));

d:=(2.0/ (2.0 / 2.0 *2.0));

e:=(2.0/ (2.0 / 2.0))*2.0;


aa:=((200000000.0/ (2.0 )))/ ((2.0 *2.0));

bb:=(200000000.0/ 2.0) /(( 2.0 *2.0));

cc:=(200000000.0)/( 2.0) /(( 2.0)) *((2.0));

dd:=(200000000.0/ (2.0 / 2.0 *2.0));

ee:=(200000000.0/ (2.0 / 2.0))*2.0;
  Reply With Quote
Old June 11th, 2018, 01:53 PM   #14
lfe
Member
France

lfe is offline
 
Join Date: Jun 2007
Location: Barcelona
Posts: 227
try

(2147483647*241.23 )/(117*20)

To avoid losing precision it is better to first multiply and then divide, but be careful not to have an overflow
__________________
Suppanel HMI
Beta Testers

Last edited by lfe; June 11th, 2018 at 02:00 PM.
  Reply With Quote
Old June 11th, 2018, 01:54 PM   #15
GaryS
Member
United States

GaryS is offline
 
GaryS's Avatar
 
Join Date: Aug 2003
Location: Lancaster Pa.
Posts: 680
You mite try this
Create a Real data type tag for each of the parameters in the calculation
and populate it with the values you need
then do the calculation you need
that will put all the data to the same type
just make sure that the result is put in a real data type tag

as I said the conversion of large numbers from one type to another dos not go well

the plc trims the value to fit the data type.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Wrong Select: Modul select 0 -20 mA to Device 4 - 20 mA Herbrata LIVE PLC Questions And Answers 10 August 16th, 2016 08:19 PM
What's wrong with my factorytalk system? seuzhang LIVE PLC Questions And Answers 0 November 5th, 2008 08:36 PM
Power Flex drive outputting wrong speed to user's plc BTL_Man LIVE PLC Questions And Answers 1 March 3rd, 2008 05:36 PM
OT - Multiplication and PLCs RMA LIVE PLC Questions And Answers 4 September 6th, 2005 06:33 AM
Hello!help To Stop Down Loading Wrong plcbuddy LIVE PLC Questions And Answers 1 August 29th, 2003 01:20 PM


All times are GMT -5. The time now is 12:47 PM.


.