Reading and writing doubles

From: Chris Cowley (ccowley_at_swenA-fodder.grok.co.uk)
Date: 10/16/03


Date: Thu, 16 Oct 2003 17:22:19 +0100

What is the most efficient way to set and read the value of 'double'
floating point values in Delphi (v5 in case that matters) using the
internal 8-byte exponent+manstissa representation?

At the moment I am using a TMemoryStream to convert between a double and
an array of bytes, like this:-

        var
         ms: TMemoryStream;
         z: double;
         b: array[0..7] of byte;
        egin
         z := 3.141592;
        
         ms := TMemoryStream.Create;
         ms.Write(z,8);
         ms.Seek(0,soFromBeginning);
         ms.Read(b,8);
         ms.Free;

This works, but I can't help but feel there must be a much more
efficient way of doing it, using a pointer to the double or something.
Any ideas?

Thanks.

-- 
Chris Cowley
 ccowley @ grok.co.uk


Relevant Pages

  • Re: Reading and writing doubles
    ... >> floating point values in Delphi using the ... Chris Cowley ... ccowley @ grok.co.uk ...
    (borland.public.delphi.language.objectpascal)
  • Re: Delphi 8 info
    ... not floating like in Delphi. ... I like the floating window. ... > loudly to Borland about this. ... > you have to not only ship the .NET runtime, ...
    (borland.public.delphi.non-technical)
  • Re: Borland is neglecting Delphi for Win32 badly
    ... Hey Borland, are you listening? ... >outperform the native versions in Delphi. ... and have come to the conclusion that you don't need good floating ...
    (borland.public.delphi.non-technical)
  • Re: Bug in Delphi SimpleRoundTo function?
    ... Delphi code to extended seems to help. ... was that the Delphi routine seems to have a bug. ... trying to round a floating point number by using ... decimal fraction numbers to Delphi. ...
    (borland.public.delphi.non-technical)
  • Re: Reading and writing doubles
    ... > floating point values in Delphi using the ... Yikes. ... Why the backbreaking cartwheels? ...
    (borland.public.delphi.language.objectpascal)