View Single Post
Old January 5th, 2020, 04:11 PM   #10
Lifetime Supporting Member
United States

drbitboy is offline
drbitboy's Avatar
Join Date: Dec 2019
Location: Rochester, NY
Posts: 790
Originally Posted by GaryS View Post
This may sound strange but try it using all real numbers
I remember reading someplace a while back that you should never mix int and real numbers math functions in a plc
It has to do with the they are handled in a plc it is different then in a computer or calculator
The original calculation used only integers, no mixing, but the result was off: the MUL of two ODD 16-bit INTEGERs was an EVEN INTEGER product.

The problem appears to be that it is not the program, but it is the EMULATOR that is MOVing INTEGERs into REALs, doing the multiply in REALs, and MOVing the REAL product back the an INTEGER result, which MOVe drops any LSBits after the first 24 MSBits, when in fact the most important part of the result is the 15 LSBITs.

The odd thing is that I cannot imagine that the emulator, whether written in C, Fortran, assembler or anything else, would have any trouble whatsoever multiplying two 16-bit integers and getting the correct result, so this is a design decision, perhaps to keep the freely-available emulator from being of any commercial use.

Hah, it would be funny, and not incredibly difficult, to go in and modify the binary emulator .EXE file to do it correctly.

Last edited by drbitboy; January 5th, 2020 at 04:57 PM.
  Reply With Quote