Oleg-N-Cher/OfrontPlus

SHORT(longreal): conversion does not occur.

Closed this issue · 3 comments

MODULE Test; (* Oberon-2 mode *)
  VAR r: LONGREAL;
BEGIN
  r := SHORT(r)
END Test.
...
	Test_r = Test_r;
...

Must be:

	Test_r = (SHORTREAL)Test_r;

I found this problem in Ofront 1.2 for BlackBox, too. But it has already been fixed in CPfront.

The fix is simple. I don't know why Josef did not implement this converting. It would be great if he could explain it to us himself.

The corresponding section of code in CPfront looks like this:

image

Perhaps Josef thought it would be impractical to move on to lower-precision calculations. Although if a user wants to, then we need to too - after all, a user prescribes SHORT in this case manually.

This problem is found by Mykhaylo Puzanov with help of PVS-Studio.

OfrontOPB.c | 699 | err | V570 The 'x->realval' variable is assigned to itself.

Before fixing:

	} else if ((INTEGER)f == 7) {
		x->realval = x->realval; // <-- 'x->realval' variable is assigned to itself.
	}

After fixing:

	} else if ((INTEGER)f == 7) {
		x->realval = (SHORTREAL)x->realval;

Thank you, Mykhaylo!

I don't remember any specific reason for the implementation of this special kind of conversion.