Mitsubishi Truncate Instruction

baboon

Member
Join Date
May 2009
Location
rotherham
Posts
7
Hi,

Can anyone tell me if there is an equivalent 'truncate' function in Mitsubishi GX Works 2.

Ive worked with Rockwell and Siemens for years and this instruction, which both have a 'truncate' function but I cant seem to find one in GXWorks

Pleeeeease help
 
DIV(dividend - MOD(dividend,divisor),divisor)


If there is no division and you want integer part of A_FLOAT_VALUE, then you want



A_FLOAT_VALUE - MOD(A_FLOAT)VALUE)



?
 
Last edited:
Hi,

Ive tried the MOD instruction, but get an error when using it with a floating point number.

Its fine on a word etc
 
It's a little convoluted, but something like this should work.

Assume F32 is 32-bit IEEE-754 floating point, and we want TRN(F32).

  • COPy F32 bits to 32-bit integer I32
  • Bit-wise AND I32 with 0x7f800000, divide by 0x800000, subtract 127, call result E (32-bit integer)
  • If E is less than 0, then TRN(F32) is 0.0
  • If E is greater than 24, then TRN(F32) is F32 (no fractional part)
  • calculate integer (2^(23-E))-1, call result MASK (32-bit integer)
  • Bit-wise AND I32 with MASK, call result I32TRN (32-bit integer)
  • COPy I32TRN bits to 32-bit IEEE-754 floating point F32TRN

Those numbers near 24 may be off by +/-1.


Cf. here
 
Either:

Round down a floating point number.

(REAL_TO_INT or INT dont work as these round up)

OR

Get the decimal part of the floating point.

Basically i want to know if the floating point has ANY decimal part to it.

I.e.
31.123 = False
31.000 = True
 
Why do you want to truncate a float? for example how many decimal places and why ? The idea of floating point is the accuracy to x number of decimal places
 
Why do you want to truncate a float? for example how many decimal places and why ? The idea of floating point is the accuracy to x number of decimal places

He explained why in post #6

Truncate a float and see if result is equal to the float gives him what he is after ...
 
If you want say 3 decimal places then multiply the float by 1000 then convert it to an integer (or double integer if you think it is going to be above 32767). Convert it back to a real then divide by 1000.
So 3.141593 as a float multiply by 1000
= 3141.593
Convert it to an integer
= 3142
convert it back to a real
= 3142.0
Divide by 1000
= 3.142 (Note: this has increased the 3rd place from 1 to 2 as 593 (the decimal part will truncate to 2.
You could just check the decimal part and sub 0.1 from the original float to stop the rounding up of the float when converting it to an integer

Trunc.png
 
Hi, There in NO TRN function

I do not know how big your float can be, but you might be able to perform a manual MOD function on it and test the final result ....

Keep subtracting 1.0 until the result is less than 1, if result = 0, then the float had no decimal part.

Obviously if the floating point value can be large, this will be detrimental to your scan time ...

You could speed things up (if you know the largest value your float can be) by doing this in "decimal chunks"...

e.g. Largest float = 5000.000

:loop
If {float} > 1000, sub 1000 : jump :loop
If {float} > 100, sub 100 : jump :loop
If {float} > 10, sub 10 : jump :loop
If {float} > 1, sub 1 : jump :loop

If {float} = 0 ......

Sorry I don't know the syntax for your PLC, but the idea should work ...
 

Similar Topics

I'm been deciphering a program for a press here. I've gotten most of it deciphered using the manual to understand the instructions (first mitsu...
Replies
1
Views
8
hi all i am new here i have a mitsubishi smart touch hmi i.e ms-60t-pe but i cannot find a software to edit and download a program in it any help...
Replies
3
Views
94
I have Toyopuc PLC PC10G-CPU and some communication modules of it. With this modules I'm able to connect with Ethernet, Ethernet/IP, FLnet, FRMT...
Replies
0
Views
54
In this sample programming, what does U4 mean? Any assistance would be greatly appreciated.
Replies
8
Views
170
Hi, I have a project with a R04CPU, RD77GF16 and a RJ71PN92 modules. The cell is given to me to change the program since the previous integrator...
Replies
2
Views
93
Back
Top Bottom