Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: float incompatibility between Windows and UNIX? (http://www.velocityreviews.com/forums/t276390-re-float-incompatibility-between-windows-and-unix.html)

Alan Sung 08-05-2003 04:59 AM

Re: float incompatibility between Windows and UNIX?
 
Both are using IEEE double floating point format. Windows, Intel 32-bit
chips use little endian. Sun and IBM Unix boxes typically use big endian.
You need some byte swapping if you want to be able to transfer binary
floating point in a file.

-al sung
Rapid Realm Technology, Inc.
Hopkinton, MA

"Victor Bazarov" <v.Abazarov@attAbi.com> wrote in message
news:visp1lb7sial02@corp.supernews.com...
> "Geert Verdoolaege" <Geert.Verdoolaege@rug.ac.be> wrote...
> > I have an application that runs under MS Windows that writes some values

> of
> > type double to a file (using a TFileStream in Borland C++ Builder). This
> > file is then sent via FTP to a UNIX machine (actually AIX), where I'm

> trying
> > to read it as a file of double using fread.
> >
> > On both systems a double is 8 bytes long, but still the values read on

the
> > AIX don't match the original ones from the Windows machine. What can be
> > wrong here?

>
> It could be the endian-ness, it could be the floating point value
> format difference. It could be an error in your code. Most likely
> the former two. The solution is to send data in text form. There
> are no guaranteed binary compatibilities between C++ programs.
>
> Victor
>
>




Geert Verdoolaege 08-05-2003 12:09 PM

Re: float incompatibility between Windows and UNIX?
 
> Both are using IEEE double floating point format. Windows, Intel 32-bit
> chips use little endian. Sun and IBM Unix boxes typically use big endian.
> You need some byte swapping if you want to be able to transfer binary
> floating point in a file.


ok, I swapped the bytes and everything comes out ok now. Except for a number
that is zero, which is converted to some very small number (something of the
order E-322), but not quite zero. Of course this is not a big problem
because 1E-322 is as good as zero, but why was it written as 0.00..E+000 on
the little endian machine, while on the IBM it's something else?

Thanks,
Geert





Victor Bazarov 08-06-2003 04:12 AM

Re: float incompatibility between Windows and UNIX?
 
"Geert Verdoolaege" <Geert.Verdoolaege@rug.ac.be> wrote...
> > Both are using IEEE double floating point format. Windows, Intel 32-bit
> > chips use little endian. Sun and IBM Unix boxes typically use big

endian.
> > You need some byte swapping if you want to be able to transfer binary
> > floating point in a file.

>
> ok, I swapped the bytes and everything comes out ok now. Except for a

number
> that is zero, which is converted to some very small number (something of

the
> order E-322), but not quite zero. Of course this is not a big problem
> because 1E-322 is as good as zero, but why was it written as 0.00..E+000

on
> the little endian machine, while on the IBM it's something else?


AFAIK, IEEE floating point values are defined that their 0 is
"all bits cleared". Flipping its bytes around should give the
same number (bit pattern). I say, print out the value before you
pass it onto the other machine, make sure it's "all zeroes".

Victor



visage 08-06-2003 12:31 PM

Re: float incompatibility between Windows and UNIX?
 
"Victor Bazarov" <v.Abazarov@attAbi.com> wrote in message news:<me%Xa.74955$uu5.8272@sccrnsc04>...
> "Geert Verdoolaege" <Geert.Verdoolaege@rug.ac.be> wrote...
> > > Both are using IEEE double floating point format. Windows, Intel 32-bit
> > > chips use little endian. Sun and IBM Unix boxes typically use big

> endian.
> > > You need some byte swapping if you want to be able to transfer binary
> > > floating point in a file.

> >
> > ok, I swapped the bytes and everything comes out ok now. Except for a

> number
> > that is zero, which is converted to some very small number (something of

> the
> > order E-322), but not quite zero. Of course this is not a big problem
> > because 1E-322 is as good as zero, but why was it written as 0.00..E+000

> on
> > the little endian machine, while on the IBM it's something else?

>
> AFAIK, IEEE floating point values are defined that their 0 is
> "all bits cleared". Flipping its bytes around should give the
> same number (bit pattern). I say, print out the value before you
> pass it onto the other machine, make sure it's "all zeroes".
>
> Victor


Yes...thats true

Another issue is that, for certain bit patterns, the swapped pattern
is not a valid float value. Certainly on windows, if you have a
function called like this:

float swapped_float = SwapAFloat(unswapped_float) ;

Where SwapAFloat is a function that rearranges the bits, then upon
assignment of the result to swapped_float, windows steps in and
assigns the value NaN (not a number) to swapped_float, due to the
return value not being a valid representation of a float. In this case
you need to pass swapped_float as a reference parameter.


All times are GMT. The time now is 08:00 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.