Jump to content
Eugine Savin

Is it bug? (type inference)

Recommended Posts

Current output is 'ne', I think, it's a bug. If I explicitly set type of variable B to Currency - output will be 'eq' as expected. I use Delphi 10.4 (also please check this code in Delphi 11)

program Project3;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

  function GetCurrency: Currency;
  begin
    Result := 8.52;
  end;

var
  A: Currency;
begin
  A := GetCurrency;
  //var B: Currency := GetCurrency();  // 1
  var B := GetCurrency(); // 2
  if A = B then WriteLn('eq') else WriteLn('ne');
  ReadLn;
end.

 

Share this post


Link to post
1 hour ago, Stefan Glienke said:

all float types

Currency isn't a floating point type, it's a fixed point type. Sorry to be so pedantic, but you know me on this topic......

  • Like 1

Share this post


Link to post
1 hour ago, David Heffernan said:

Currency isn't a floating point type, it's a fixed point type. Sorry to be so pedantic, but you know me on this topic......

I don't know what you mean 😉 Yes, I meant decimal type

Share this post


Link to post
24 minutes ago, Stefan Glienke said:

I meant decimal type

That's even worse! Currency is decimal fixed, but Single, Double and Extended are all binary float! Probably you are trolling me now for fun!

Share this post


Link to post
1 hour ago, David Heffernan said:

Probably you are trolling me now for fun!

You can test it for yourself:

 

  function GetCurrency: Currency;
  begin
    Result := 8.52;
  end;


var
  A: Currency;
  C: double;
  D: extended;
begin
  A := GetCurrency;
  var B := GetCurrency(); // 2
  C:=GetCurrency;
  D:=GetCurrency;

  if A = B then
    WriteLn('A = B')
  else
    WriteLn('A <> B');

  if B = C then
    WriteLn('B = C')
  else
    WriteLn('B <> C');

  if B = D then
    WriteLn('B = D')
  else
    WriteLn('B <> D');


  ReadLn;
end.

The result is:

A <> B
B <> C
B = D

Share this post


Link to post
2 hours ago, Lajos Juhász said:

You can test it for yourself:

You missed the point. I'm not disputing that the variable is Extended. I'm discussing the terminology decimal, binary, floating point and fixed point. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×