Re: Reading and writing doubles
From: Perry Way (no.delphipro.spam_at_no.spam.earthlink.net)
Date: 10/16/03
- Next message: Chris Cowley: "Re: Reading and writing doubles"
- Previous message: Perry Way: "Re: Rewrite last line in text file"
- In reply to: Chris Cowley: "Reading and writing doubles"
- Next in thread: Chris Cowley: "Re: Reading and writing doubles"
- Reply: Chris Cowley: "Re: Reading and writing doubles"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 16 Oct 2003 09:18:47 -0700
"Chris Cowley" wrote in message
> 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?
By using a double. :)
> At the moment I am using a TMemoryStream to convert between a double and
> an array of bytes, like this:-
Yikes. Why the backbreaking cartwheels?
> 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?
You're already writing the double in your example above. To read it back
again, just call .Read.
By the way, I would not make constant value references for size in Read and
Write calls. A less error prone method would be to pass SizeOf() for simple
types and Length() for string buffers.
PW
- Next message: Chris Cowley: "Re: Reading and writing doubles"
- Previous message: Perry Way: "Re: Rewrite last line in text file"
- In reply to: Chris Cowley: "Reading and writing doubles"
- Next in thread: Chris Cowley: "Re: Reading and writing doubles"
- Reply: Chris Cowley: "Re: Reading and writing doubles"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|