Port-vax archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Thoughts about IEEE floating point (-ish) on vax



> At first; here is a brief overview what differs between vax and ieee
> floating point:

> 	* +NaN/-NaN:  vax do have "illegal number" which traps.
> 		Not really NaN.

Are IEEE NaNs signed?

> 	* Vax exponent bias is (for F-float) 128, IEEE (for single) 127.
> 	* Vax hidden bit is 0.5, IEEE is 1.

I'm not entirely sure what you mean here.  By the value of the hidden
bit, you mean that (say) if the exponent bits are eee and the mantissa
bits are mmmm, the value is .1mmmm * 2^eee versus 1.mmmm * 2^eee?

If so, that's the same thing as shifting the exponent bias by 1.

But the *effective* exponent bias is diffrent.

I wrote a simple program, to check memory layout, exponent bias, and
behaviour on underflow:

	#include <stdio.h>
	
	int main(void);
	int main(void)
	{
	 volatile float f;
	
	 f = 1;
	 while (f != 0)
	  { printf("%08x %g\n",*(volatile int *)&f,f);
	    f /= 2;
	  }
	 return(0);
	}

I then ran this on (a) SPARC, (b) i386, and (c) VAX.  (I actually did
(c1) real-iron VAX and (c2) my simulator, thinking I may have made a
mistake, but the output is the same on both.)

The output:

(a) SPARC

3f800000 1
3f000000 0.5
3e800000 0.25
3e000000 0.125
...
02800000 1.88079e-37
02000000 9.40395e-38
01800000 4.70198e-38
01000000 2.35099e-38
00800000 1.17549e-38
00400000 5.87747e-39
00200000 2.93874e-39
...
00000004 5.60519e-45
00000002 2.8026e-45
00000001 1.4013e-45

(b) i386

Same as SPARC.

(c) VAX

00004080 1
00004000 0.5
00003f80 0.25
00003f00 0.125
...
00000200 2.35099e-38
00000180 1.17549e-38
00000100 5.87747e-39
00000080 2.93874e-39

To match up the VAX with the IEEE, it needs byteswapping something like
PDP-endian (swap words-within-long but not bytes-within-words) and then
an exponent bias difference of 1.

IEEE may allow for layout variations, but I suspect some test suites
don't.  Yes, that would mean the test suites are broken, but then,
except for things that really do require IEEE for some reason, they're
broken anyway for demanding IEEE.

> We note that the difference in bias and mantissa is a factor of 4.0.

Looks like a factor of 2 to me.  After bit rearrangement, 1 is biased
exponent 7f for IEEE (printing as 3f8 because the sign bit shifts it
over by one) and 80 for VAX (400, ditto).

> So; what happens if we just consider a vax float to be an IEEE float?
> 	* For add and sub it works just as well; since there is no
> 	  dependency in these ops what the bias is.

Well, I'd have to check; I'm not sure - but I *think* IEEE reserves two
biased-exponent field values for unusual purposes whereas the VAX
reserves only one.  If so, this means that either overflow or
underflow, possibly both, must happen differently.

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse%rodents-montreal.org@localhost
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index