Page 1 of 1

ENTIER Trap

Posted: Mon Jun 08, 2015 4:11 pm
by luowy
this code is wired:

Code: Select all

	PROCEDURE Test* ();
		VAR 
			i, i2: INTEGER;
			x: LONGINT;
			r: REAL;
	BEGIN
		r := MIN(LONGINT);
		 
		x := ENTIER(r); (* not trap *)
		i := SHORT(x);
		
		i2 := SHORT(ENTIER(r)); (*trap!!!*)
	END Test;
the i statement is ok,but i2 statement is trapped;
has anybody Known this question?

luowy

Re: ENTIER Trap

Posted: Tue Jun 09, 2015 7:34 am
by DGDanforth
It appears to come from the Kernel and the interpretation of

Code: Select all

excpRec: WinApi.PtrEXCEPTION_RECORD
So it is deep in the fpu and Microsoft code.

Re: ENTIER Trap

Posted: Tue Jun 09, 2015 8:29 am
by Josef Templ

Code: Select all

i := SHORT(x);
is an unchecked integer conversion that returns an undefined result.

Code: Select all

i2 := SHORT(ENTIER(r));
is a checked floating point conversion done inside the FPU which does a range check.

- Josef