Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-09

Variants and Extended

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Torsten Bonde Christiansen

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.

Reply by email

Torsten Bonde Christiansen
to Torsten Bonde Christiansen

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 28 lines
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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Michael Van Canneyt
to Torsten Bonde Christiansen: Dear list. Over the last couple of days i've been trying out different things with…
Torsten Bonde Christiansen wrote 18 lines
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?

The extended type does not work inside TVarData. Variants were implemented by Microsoft, and they did not include support for extended.

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt

In our previous episode, Michael Van Canneyt said:

Show quoted text 7 lines
> 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? The extended type does not work inside TVarData. Variants were implemented by Microsoft, and they did not include support for extended.

Note that extended is x86 specific, and windows has been multi-architecture since the early nineties.

Reply by email

Vincent Snijders
to Torsten Bonde Christiansen
Torsten Bonde Christiansen wrote 8 lines
Marco van de Voort wrote: > Note that extended is x86 specific, and windows has been > multi-architecture > since the early nineties. > Does this also mean that Extended does not work on MAC PowerPC?

It compiles, but it is only 64 bits, like a double.

type
   extended = double;
You can check this at compile time by doing
{$IFDEF FPC_HAS_TYPE_EXTENDED}

Vincent

Reply by email