comp.lang.ada
 help / color / mirror / Atom feed
* Q: type matching with IEEE 754 double and Intel endianess
@ 2012-12-07  8:54 gautier_niouzes
  2012-12-08  6:31 ` J-P. Rosen
  0 siblings, 1 reply; 3+ messages in thread
From: gautier_niouzes @ 2012-12-07  8:54 UTC (permalink / raw)


Hello,

For a software component (Excel Writer), I have a portable way of getting a binary output for a Long_Float, by using Dmitry's IEEE_754 package.
It is working perfectly fine (see IEEE_Double_Intel_Portable function below).

Now, assume the program is running on a machine where Long_Float is actually IEEE_754, and endianess is the Intel one.
Is there a "solid" way to prove with some check that it is the case ?
Then a rough type conversion would be sufficient (e.g. IEEE_Double_Intel_Native below). The only advantage of the latter is that it is faster.

Cheers
G.


  function IEEE_Double_Intel_Portable(x: Long_Float) return Byte_buffer is
    pragma Inline(IEEE_Double_Intel_Portable);
    d : Byte_buffer(1..8);
    --
    use IEEE_754.Long_Floats;
    f64: constant Float_64:= To_IEEE(x);
  begin
    for i in d'Range loop
      d(i):= f64(9-i); -- Order is reversed
    end loop;
    return d;
  end IEEE_Double_Intel_Portable;

  function IEEE_Double_Intel_Native(x: Long_Float) return Byte_buffer is
    pragma Inline(IEEE_Double_Intel_Native);
    d : Byte_buffer(1..8);
    for d'Address use x'Address;
    pragma Import (Ada, d);
  begin
    return d;
  end IEEE_Double_Intel_Native;



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

end of thread, other threads:[~2012-12-08 20:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-07  8:54 Q: type matching with IEEE 754 double and Intel endianess gautier_niouzes
2012-12-08  6:31 ` J-P. Rosen
2012-12-08 20:17   ` gautier_niouzes

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