This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Hi Lazar!
> Thank you Pedro for your reply, but I realized I was not clear.
> double is an 8-byte quantity (at least on intel) so I need
> 64-bit-swapping routines not 32-bit ones which are available.
Exactly! That's why you have to call "htonl" twice :) What is an unknown
(to me, at least) is if the byte-swapping is done 32-bit wise or 64-bit wise.
The code I sent you worked for moving data from a Power4-architecture to
a Pentium-based machine.
Cheers
Pedro
On Tue, 2003-09-30 at 16:58, Z F wrote:
> Hello,
>
> Thank you Pedro for your reply, but I realized I was not clear.
> double is an 8-byte quantity (at least on intel) so I need
> 64-bit-swapping routines not 32-bit ones which are available.
> Also, htonl() and ntohl() are for ints. I could cast double to int but
> this would require splitting the double into two parts mantissa and
> exponent and applying 32-bit swaps independently. Is this the way to
> go?
>
> Need more input :-)
>
> Lazar
>
> --- Pedro Gonnet <pedro@vis.ethz.ch> wrote:
> >
> > Hello Lazar,
> >
> > I think the functions you're looking for are
> >
> > uint32_t htonl(uint32_t hostlong);
> > uint32_t ntohl(uint32_t netlong);
> >
> > These operate on 32-bit values, so you have to do something like
> >
> > double hton_double ( double in ) {
> >
> > double res;
> > unsigned int *in , *out = (unsigned int *)(&res);
> >
> > out[0] = htonl(in[0]);
> > out[1] = htonl(in[1]);
> >
> > return res;
> >
> > }
> >
> > Beware that on some machines (or with data dumped by programs
> > compiled
> > with Portland's byte-swapping fortran compiler), the 32-bit values
> > are
> > also swapped, in which case you would have to write:
> >
> > out[0] = htonl(in[1]);
> > out[1] = htonl(in[0]);
> >
> > Hope this helps...
> >
> > Pedro
> >
> >
> >
> >
> > On Tue, 2003-09-30 at 16:41, Z F wrote:
> > > Hello everybody,
> > >
> > >
> > > Even though this question is not directly related to GSL,
> > indirectly
> > > --- it is.
> > >
> > > I have a scientific calculation program (which uses GSL) but most
> > > importantly it uses doubles. I need to transfer those data to
> > another
> > > computer. The problem is that if the two computers have different
> > byte
> > > ordering, I have to do something special about the data. I
> > understand
> > > that there is a network standard for shorts and for ints to serve
> > this
> > > purpose. I could not find any standards to transfer doubles/floats
> > over
> > > net. I the past I could live with printf()-type things and convert
> > all
> > > doubles to strings and pass strings since ASCII is more universal.
> > > This, however, increases the data size by a factor of three.
> > >
> > > The current problem I am working on has data output rate of about
> > > 5-15MBytes/sec and increasing it by factor of three is not
> > feasible.
> > >
> > > Could someone, please, point me in the right direction? Should I
> > > give-up on portability of my code and assume/hope that both ends
> > use
> > > the same
> > > byte ordering?
> > >
> > > I know that this is not directly related to GSL, but all the
> > network
> > > people do not seem to care about doubles so I have to turn to
> > > "scientific" network programming....
> > >
> > > Thank you very much for your input,
> > >
> > > Lazar
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > The New Yahoo! Shopping - with improved product search
> > > http://shopping.yahoo.com
> >
>
> > ATTACHMENT part 2 application/pgp-signature name=signature.asc
>
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search
> http://shopping.yahoo.com
Attachment:
signature.asc
Description: This is a digitally signed message part
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |