Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* Re: Representation of float on DEC-ALPHA
       [not found] <45thnl$klu@galadriel.iwb.mw.tu-muenchen.de>
@ 1995-10-16  4:00 ` Dan Pop
  1995-10-16  4:00   ` Ron Natalie
  1995-10-17  4:00   ` Ulrich Rossgoderer
  1995-10-17  4:00 ` Steve Lionel
  1 sibling, 2 replies; 8+ messages in thread
From: Dan Pop @ 1995-10-16  4:00 UTC (permalink / raw)


In <45thnl$klu@galadriel.iwb.mw.tu-muenchen.de> rossgod@eowyn.iwb.mw.tu-muenchen.de (Ulrich Rossgoderer) writes:

>I've to read a binary file generated on a SGI or a HP workstation. The
>binary contains float numbers (single precision)?
>
>How do I read (convert) them on a DEC-ALPHA workstation? It can't be
>only done by byte swapping, because the following program

It _can_ be done only by byte swapping.

>------------------8<------------------8<------------------8<---------
>#include <stdio.h>
>
>int main (void)
>{
>   char  *cptr, abbruch;
>   float  f;
>
>   abbruch = 0;
>   do
>   {
>      printf ("Please enter float number: ");
>      if (scanf  ("%f", &f) == 1)
>      {
>         cptr = (char*)&f;
>         printf ("Byte 0: %4d, Byte 1: %4d, Byte 2: %4d, Byte 4: %4d\n",
>                 (int)cptr[0], (int)cptr[1], (int)cptr[2], (int)cptr[3]);
>      }
>      else
>         abbruch = 1;
>
>   } while (!abbruch);
>
>   return (0);
>}
>------------------8<------------------8<------------------8<---------

Classical programming error!  Replace "char" by "unsigned char" in your
program and you'll get the same results, except for the byte order, of
course, on both SGI and Alpha.

On SGI, char is unsigned, while on Alpha, char is signed (the "signedness"
of char is undefined by the language).  

All the workstations (I know of) use IEEE-754 floating point.  Only the
byte sex is different between little endian and big endian platforms.

BTW, you don't have to cast the char arguments of printf.  The compiler
will do it for you, because printf is a variadic function and the 
default argument promotions are performed automatically on all the
arguments following the format string.

Dan
--
Dan Pop
CERN, CN Division
Email: Dan.Pop@mail.cern.ch 
Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Representation of float on DEC-ALPHA
  1995-10-16  4:00 ` Representation of float on DEC-ALPHA Dan Pop
@ 1995-10-16  4:00   ` Ron Natalie
  1995-10-18  4:00     ` Dan Pop
  1995-10-17  4:00   ` Ulrich Rossgoderer
  1 sibling, 1 reply; 8+ messages in thread
From: Ron Natalie @ 1995-10-16  4:00 UTC (permalink / raw)


Dan Pop (Dan.Pop@mail.cern.ch) wrote:

: All the workstations (I know of) use IEEE-754 floating point.  Only the
: byte sex is different between little endian and big endian platforms.

Everything but VAX's.

-Ron



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Representation of float on DEC-ALPHA
@ 1995-10-16  4:00 Ulrich Rossgoderer
  0 siblings, 0 replies; 8+ messages in thread
From: Ulrich Rossgoderer @ 1995-10-16  4:00 UTC (permalink / raw)




--
Ulrich Rossgoderer                | Phone: +49-89-90994-104
Institute for Machine Tools and   | Fax:   +49-89-90994-118
Production Management             | Email: rg@iwb.mw.tu-muenchen.de
Technical University of Munich    | http://www.iwb.mw.tu-muenchen.de/~rossgod/



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Representation of float on DEC-ALPHA
  1995-10-16  4:00 ` Representation of float on DEC-ALPHA Dan Pop
  1995-10-16  4:00   ` Ron Natalie
@ 1995-10-17  4:00   ` Ulrich Rossgoderer
  1 sibling, 0 replies; 8+ messages in thread
From: Ulrich Rossgoderer @ 1995-10-17  4:00 UTC (permalink / raw)


Thanx for all your precious help. I got the bug fixed and everything
works fine now.

Thank you,

Uli

--
Ulrich Rossgoderer                | Phone: +49-89-90994-104
Institute for Machine Tools and   | Fax:   +49-89-90994-118
Production Management             | Email: rg@iwb.mw.tu-muenchen.de
Technical University of Munich    | http://www.iwb.mw.tu-muenchen.de/~rossgod/



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Representation of float on DEC-ALPHA
       [not found] <45thnl$klu@galadriel.iwb.mw.tu-muenchen.de>
  1995-10-16  4:00 ` Representation of float on DEC-ALPHA Dan Pop
@ 1995-10-17  4:00 ` Steve Lionel
  1 sibling, 0 replies; 8+ messages in thread
From: Steve Lionel @ 1995-10-17  4:00 UTC (permalink / raw)



In article <45thnl$klu@galadriel.iwb.mw.tu-muenchen.de>, 
rossgod@eowyn.iwb.mw.tu-muenchen.de (Ulrich Rossgoderer) writes:

|>I've to read a binary file generated on a SGI or a HP workstation. The
|>binary contains float numbers (single precision)?
|>
|>How do I read (convert) them on a DEC-ALPHA workstation? It can't be
|>only done by byte swapping, because the following program
[snip]
|>
|>produces the following output on a SGI:
|>---------------------------------------
|>
|>Please enter float number: 1.0
|>Byte 0:   63, Byte 1:  128, Byte 2:    0, Byte 4:    0
|>
|>Please enter float number: -1.0
|>Byte 0:  191, Byte 1:  128, Byte 2:    0, Byte 4:    0
|>
|>and on a DEC-ALPHA:
|>-------------------
|>
|>Please enter float number: 1.0
|>Byte 0:    0, Byte 1:    0, Byte 2: -128, Byte 4:   63
|>
|>Please enter float number: -1.0
|>Byte 0:    0, Byte 1:    0, Byte 2: -128, Byte 4:  -65

If you look closer, you'd see that the Alpha values really are the "same"
(except for byte ordering) as the SGI - on SGI, you're getting the values
displayed as unsigned byte integers, whereas on Alpha they're signed bytes.
(%d is supposed to be signed decimal, so I think the SGI results are wrong.)
The bit patterns are the same (try using %x instead).
-- 

Steve Lionel                      Mail: lionel@quark.enet.dec.com
DEC Fortran Development           WWW:  http://www.digital.com/info/slionel.html
Digital Equipment Corporation     CompuServe: 75263,3001
110 Spit Brook Road, ZKO2-3/N30
Nashua, NH 03062-2698             "Free advice is worth every cent"

For information on DEC Fortran 90, see http://www.digital.com/info/hpc/f90/



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Representation of float on DEC-ALPHA
  1995-10-16  4:00   ` Ron Natalie
@ 1995-10-18  4:00     ` Dan Pop
  1995-10-20  4:00       ` Phillip Helbig
  0 siblings, 1 reply; 8+ messages in thread
From: Dan Pop @ 1995-10-18  4:00 UTC (permalink / raw)


In <45upsh$6pu@topaz.sensor.com> ron@topaz.sensor.com (Ron Natalie) writes:

>Dan Pop (Dan.Pop@mail.cern.ch) wrote:
>
>: All the workstations (I know of) use IEEE-754 floating point.  Only the
           ^^^^^^^^^^^^
>: byte sex is different between little endian and big endian platforms.
>
>Everything but VAX's.

For some obscure reason :-) I've never considered the VAX a "workstation"
even if a VAXstation flavour exists.

Dan
--
Dan Pop
CERN, CN Division
Email: Dan.Pop@mail.cern.ch 
Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Representation of float on DEC-ALPHA
  1995-10-18  4:00     ` Dan Pop
@ 1995-10-20  4:00       ` Phillip Helbig
  1995-10-20  4:00         ` Ron Natalie
  0 siblings, 1 reply; 8+ messages in thread
From: Phillip Helbig @ 1995-10-20  4:00 UTC (permalink / raw)


In <danpop.813976310@rscernix> Dan.Pop@mail.cern.ch (Dan Pop) writes:

>>: All the workstations (I know of) use IEEE-754 floating point.  Only the
>           ^^^^^^^^^^^^
[...]
>>Everything but VAX's.

>For some obscure reason :-) I've never considered the VAX a "workstation"
>even if a VAXstation flavour exists.

Right---it's a real computer.

Phillip Helbig               Tel. .............. +49 40 7252 4110   
Hamburger Sternwarte         Email .... phelbig@hs.uni-hamburg.de
Gojenbergsweg 112            Fax ............... +49 40 7252 4198   
D-21029 Hamburg              Telex ............... 217884 hamst d




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Representation of float on DEC-ALPHA
  1995-10-20  4:00       ` Phillip Helbig
@ 1995-10-20  4:00         ` Ron Natalie
  0 siblings, 0 replies; 8+ messages in thread
From: Ron Natalie @ 1995-10-20  4:00 UTC (permalink / raw)


Phillip Helbig (phelbig@hs.uni-hamburg.de) wrote:


: >For some obscure reason :-) I've never considered the VAX a "workstation"
: >even if a VAXstation flavour exists.

: Right---it's a real computer.

I always thought it was a virtual computer (not quite a real computer).

-Ron



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1995-10-20  4:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <45thnl$klu@galadriel.iwb.mw.tu-muenchen.de>
1995-10-16  4:00 ` Representation of float on DEC-ALPHA Dan Pop
1995-10-16  4:00   ` Ron Natalie
1995-10-18  4:00     ` Dan Pop
1995-10-20  4:00       ` Phillip Helbig
1995-10-20  4:00         ` Ron Natalie
1995-10-17  4:00   ` Ulrich Rossgoderer
1995-10-17  4:00 ` Steve Lionel
1995-10-16  4:00 Ulrich Rossgoderer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox