Board index » delphi » value typecasts

value typecasts

How does FreePascal 1.0.4 determine when to use value typecast
and the (Turbo Pascal-style) internal representation typecast ?

For example,
    type   signed_quad_byte = longint ;

    var r : single ;
        b : signed_quad_byte ;
...
    r := 4.0;
    b := signed_quad_byte(r);

Should b get
(1) the value of a signed dword formed by the first 4 bytes
    of the internal representation of the float point number,
(2) the truncated value of r (that is, 4, using the value typecast), or
(3) give an error ?

How do I change the behavior away from the default setting ?

Thanks.
rdtsc

 

Re:value typecasts


Quote
In article <9bnkuj$qi...@news.doit.wisc.edu>, rdtsc wrote:
> How does FreePascal 1.0.4 determine when to use value typecast
> and the (Turbo Pascal-style) internal representation typecast ?

Simply on the size of the argument. Probably also if you try to convert an
equally sized double and integer type.

Quote
> How do I change the behavior away from the default setting ?

Not.

Re:value typecasts


Quote
In article <9bnkuj$qi...@news.doit.wisc.edu>, rdtsc wrote:
> How do I change the behavior away from the default setting ?

Grrr, I remembered how I did it last time:
Typecast to the equivalent array of byte first.

type bla= array[0..sizeof(int64)-1] of byte;

var a:double;
    b:int64;

begin
  a:=1.0;
  b:=int64(bla(b));
end.

No beauty price, but it works, and is universal for these kind of problems.

I will have a talk with Michael about this, maybe it is something good for
the docs.

Other Threads