[fpc-pascal] Variants and Extended

Torsten Bonde Christiansen tc at epidata.dk
Thu Sep 17 09:08:27 CEST 2009


DOH! Forgot the example:

procedure TForm1.Button1Click(Sender: TObject);             
var                                                         
  v: variant;                                               
  x, y: extended;                                           
begin                                                       
  x := 1.23456789;                                          
  v := x;                                                   
  y := v;                                                   
  Label1.Caption := BoolToStr(x = y, 'Same', 'Different');  
end;                                                        


Torsten Bonde Christiansen wrote:
> Dear list.
>
> Over the last couple of days i've been trying out different things 
> with variants, but I always seem to end up in the same situation: When 
> working with conversion between Extended and Variant, a small part of 
> the precision in the Extended is lost.
>
> This would normally not pose an issue, except for the fact that 
> comparing two Extended variables after one was converted to a variant 
> and back, the two numbers are NOT equal. (I've posted a small example 
> at the bottom of the mail).
>
> I did some digging down the FPC code and found that in the TVarData 
> type has not extended type. Although the assignment operator for 
> variants does include a specific extended version, data is copied into 
> a double type.
>
> Not knowing much about the inner working of variants I don't know the 
> reason for this, is it a bug or does the extended type not work inside 
> the TVarData?
>
> I would be glad if someone could give me some feedback on this.
>
> Kind regards,
> Torsten Bonde Christiansen.
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list