Jump to content
Registration disabled at the moment Read more... ×
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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×