Math with Float and Integer

chetezen

Member
Join Date
May 2003
Posts
13
Can I use a math expression (such as cpt) with a mix of integers and floats in RSLogix500? I'm trying to do the following:
F8:15=F8:14/(N27:122*20)
 
Short and simple answer is Yes you can, no problem.

One 'gotcha' though, is it's best to specify all of your constants as floats if you do that, or it will perform some parts of the computation in integer math, and some in float, casting the result value to the target variable type.

In your case it wouldn't matter much, but I'd still use:
F8:15=F8:14/(N27:122*20.0)
instead of
F8:15=F8:14/(N27:122*20)

Oh, and the divide sign is a pipe symbol I think (Vertical bar) '|'

The making constants all floats doesn't matter much, as I said with adds and multiplies, but assuming N27:122 was 8, if you had:
(N27:122 | 10)
the answer would be 0 (integer divide).
If you had
(N27:122 | 10.0)
the answer would be 0.8
 
Your SLC must be 'floating point' capable, but yes, you can mix integers and floats.

rdrast- RSLogix500 made the integer constants into floats as soon as I accepted the rung.

int_float_2.gif
 
Last edited:
93lt1 - Thanks for the screenshot, I use both AI and Logix, so I always make sure to check that my constants are right. I wasn't aware that logix did an auto-cast
 
Hey,
Just wanted to let you know that it wors - just as you said it would. Just be carefull whit the integer being 0 - RSLogix does not like to divide anything by 0!! So, I just added a GEQ for the integer to be "1" or more before to the math.
 

Similar Topics

Jees... Continuing from this thread... http://www.plctalk.net/qanda/showthread.php?t=85341 I now have the correct pressure in Torr and mBar...
Replies
24
Views
7,414
I have an expression in a structured text routine of a Logix controller that looks more or less like the following: ResultInteger := Integer1 *...
Replies
13
Views
374
This application has a motor with encoder feedback that drives a linear actuator that moves in/out, and is at roughly 45 degs from horiz. As the...
Replies
19
Views
1,356
Hi all. First time programming a machine of this type. A center driven unwind feeding to a center driven rewind. No dancers or load cells, just...
Replies
37
Views
4,859
Hello, Been a while since I posted , Still sucking air been a interesting 3.5 years the dreaded health with old age scenario. Back at it and had a...
Replies
11
Views
2,054
Back
Top Bottom