      program rwfp
************************************************************************
*     (Read/write floating-point numbers)
*     Program to read floating-point numbers, and display them as
*     single-, double-, and quadruple-precision values in hexadecimal
*     and decimal.
*     (30-Nov-2001)
************************************************************************
      real*4 s
      real*8 d
      real*16 q
      integer i, unset
      integer id(2)
      integer iq(4)
      logical bigend
      equivalence (d,id)
      equivalence (q,iq)
      data unset /z'deadbeef'/

      d = 1.0
      bigend = (id(1) .ne. 0)

      do 5 i = 1,4
        iq(i) = unset
    5 continue

   10 read (5,*,end=20) q
        s = q
        d = q
        write (6,'('' 32-bit: '', z8.8,   24x, 3x, 1pe45.7e4)') s, s
        if (bigend) then
          write (6,'('' 64-bit: '', z16.16, 16x, 3x, 1pe45.16e4)') d, d
          write (6,'(''128-bit: '', z32.32,      3x, 1pe45.34e4)') q, q
        else
          write (6,'('' 64-bit: '', 2z8.8, 16x, 3x, 1pe45.16e4)')
     x        id(2), id(1), d
          write (6,'(''128-bit: '', 4z8.8,      3x, 1pe45.34e4)')
     x        iq(4), iq(3), iq(2), iq(1), q
        endif
        go to 10
   20 continue
      end

