delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/24/23:00:22

From: buers AT gmx DOT de (Dieter Buerssner)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: binary to float
Date: 25 Feb 2000 03:14:40 GMT
Lines: 37
Message-ID: <894s30$1vrk7$1@fu-berlin.de>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1000224184303 DOT 16581A-100000 AT is>
NNTP-Posting-Host: pec-44-52.tnt3.s2.uunet.de (149.225.44.52)
Mime-Version: 1.0
X-Trace: fu-berlin.de 951448480 2092679 149.225.44.52 (16 [17104])
X-Posting-Agent: Hamster/1.3.13.0
User-Agent: Xnews/03.02.04
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Eli Zaretskii wrote:
>On Thu, 24 Feb 2000, Dieter Buerssner wrote:
>
>> unsigned long l;
>> float x;
>> fread(&l, sizeof l, 1, fp);
>> l = ntohl(l);
>> x = *(float *)&l;
>> 
>> My question, is this really more portable? In the libc info for ntohl 
>> under Portability I read: not ANSI, not POSIX. Is this function 
>> generally available?
>
>I've seen them on every Unix box I had access to.

I have no doubt on what you are saying. But in the context of the 
original problem, there seems to be the need, to be able to access 
the exact same floating point values on different platforms. If this
is true, the portability to IEEE compatible floating point platforms
may be more important, than the portability to Unix platforms.

>> Also, one other problem might arise when 
>> unsigned long is 64bit (i.e. Alpha, which uses IEEE floating point).
>
>I don't have access to an Alpha to check.  Anybody?

Right now, I do not have access to an Alpha either. But I can 
guarantee, that there was a mode, where unsigned long was 64 bit,
when I last used this platform (I cannot remember, whether 64 bit
unisgned long was the default. It may have needed some special
compiler switches.)

>I don't know.  In general, I usually advise to stay away of passing FP 
>numbers between different machines.

Yes, the most portable way to transform floating point values between
different platforms pobably is printf vs scanf/atof/strtod.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019