ENTIER Trap

Post Reply
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

ENTIER Trap

Post 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
User avatar
DGDanforth
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA
Contact:

Re: ENTIER Trap

Post 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.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: ENTIER Trap

Post 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
Post Reply