[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
VAX<>IEEE 32bit float conversion
From: 
John W. Eaton 
Subject: 
VAX<>IEEE 32bit float conversion 
Date: 
Thu, 22 Jul 2004 16:27:51 0400 
You are correct that there is just one 4byte VAX floating point
format. Octave should call this VAX_F, not VAX_D and VAX_G. OTOH, I
think the Matlab data file format only includes options for D and G.
In any case, I don't think the conversion can be as simple as your
code suggests. The format described here
http://h18009.www1.hp.com/fortran/docs/unixum/dfumcompat.htm#index_x_3983
looks like this:
31 16 15 14 7 6 0
 fraction  sign  exponent  fraction 
* Bit 15 is the sign bit (0 for positive numbers, 1 for negative numbers).
* Bits 14:7 are a binary exponent in excess 128 notation (binary
exponents from 127 to 127 are represented by binary 1 to 255).
* Bits 6:0 and 31:16 are a normalized 24bit fraction with the
redundant most significant fraction bit not represented.
It looks like your code does not account for the fact that there are
only 7 bits in the first part of the fraction. Or am I missing
something? Perhaps it worked for you because of the particular range
of values you used for testing?
Please note that I've moved this discussion to the maintainers list.
Thanks,
jwe
On 1Jun2004, Wolfgang Westphal <address@hidden> wrote:
 Hi!

 I had to read some data files containing float values in VAX notation,
 so I've implemented the conversion for 32bit VAX floats to IEEE little
 endian. AFAIK for the 32bit case there's no difference between "VAXD"
 and "VAXG", so the conversion is identical in both cases.

 The attached patch is tested in octave 2.1.50 as well as octave 2.1.57,
 and worksforme.

 Regards,
 Wolfgang Westphal
  liboctave/dataconv.cc 20020410 02:39:51.000000000 +0200
 +++ liboctave/dataconv.cc 20040531 13:10:14.000000000 +0200
 @@ 277,15 +277,26 @@
 }

 static void
 VAX_D_float_to_IEEE_little_float (float * /* d */, int /* len */)
 +VAX_D_float_to_IEEE_little_float (float * d, int len)
 {
  gripe_data_conversion ("VAX D float", "IEEE little endian format");
 + for (int i=0;i<len;i++) {
 + char* c = (char*)(&d[i]);
 + swap_bytes(c, 0, 2);
 + swap_bytes(c, 1, 3);
 + c[3];
 + }
 }

 static void
 VAX_G_float_to_IEEE_little_float (float * /* d */, int /* len */)
 {
  gripe_data_conversion ("VAX G float", "IEEE little endian format");
 +VAX_G_float_to_IEEE_little_float (float * d , int len )
 +{
 + char* c;
 + for (int i=0;i<len;i++) {
 + c = (char*)(&d[i]);
 + swap_bytes(c, 0, 2);
 + swap_bytes(c, 1, 3);
 + c[3];
 + }
 }

 static void
 @@ 367,9 +378,14 @@
 }

 static void
 IEEE_little_float_to_VAX_D_float (float * /* d */, int /* len */)
 +IEEE_little_float_to_VAX_D_float (float * d , int len)
 {
  gripe_data_conversion ("IEEE little endian", "VAX D");
 + for (int i=0;i<len;i++) {
 + char* c = (char*)(&d[i]);
 + c[3]++;
 + swap_bytes(c, 0, 2);
 + swap_bytes(c, 1, 3);
 + }
 }

 static void
 @@ 415,9 +431,14 @@
 }

 static void
 IEEE_little_float_to_VAX_G_float (float * /* d */, int /* len */)
 +IEEE_little_float_to_VAX_G_float (float * d , int len)
 {
  gripe_data_conversion ("IEEE little endian", "VAX G");
 + for (int i=0;i<len;i++) {
 + char* c = (char*)(&d[i]);
 + c[3]++;
 + swap_bytes(c, 0, 2);
 + swap_bytes(c, 1, 3);
 + }
 }

 static void
 VAX<>IEEE 32bit float conversion,
John W. Eaton <=