multiplication wrong answer

Elnes

Member
Join Date
Jun 2018
Location
montreal
Posts
5
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 !
 
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 ...
 
Last edited:
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 ?
 
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.
 
@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 ().
 
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.
 
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
 
@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
 
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."
 
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;
 
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
 
Last edited:
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.
 

Similar Topics

I've got a Q68DAIN (Mitsubishi Q series analogue output module). On the HMI, Basically on the screen, the user types in a value as a percentage...
Replies
11
Views
2,199
In my last year at Glasgow Uni in 1966 I indulged myself by taking the newly introduced course in "Computing". This allowed us a few seconds...
Replies
4
Views
2,894
We have a quad monitor setup with FT SE and we are utilizing a header screen at the top of every display. when we open a new page we abort the...
Replies
0
Views
77
Hi all, I am having an issue with FT View Studio ME when I try to open the propoerties of any object, the size of it is very big and doesn't let...
Replies
0
Views
96
ewrong aka the censored brand of remote access this thing is kicking my butt and im not sure if i am just irritated enough that i am missing...
Replies
5
Views
592
Back
Top Bottom