View Issue Details

IDProjectCategoryView StatusLast Update
0038715FPCCompilerpublic2021-04-09 10:46
ReporterOndrej Pokorny Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status feedbackResolutionopen 
Platformi386-win32OSWindows 
Product Version3.3.1 
Summary0038715: Wrong result from an explicit cast Double()
DescriptionWhen I use an explicit cast to Double, I get a wrong result.
Steps To ReproduceExecute

procedure Test_OtherUnit(const aValue: Currency);
begin
  Writeln('Test_OtherUnit');
  Writeln('aValue: ', aValue); // writes correct value
  Writeln('Double(): ', Double(aValue)); // writes incorrect value
end;

from a different unit. The cast returns a wrong value.

Full project is attached.
Additional InformationInterestingly, if the same code is called from the same unit, the cast works fine.

I also tested ARM Linux and there it seems to work just fine.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Ondrej Pokorny

2021-04-07 17:31

developer  

RoundTo.zip (711 bytes)

Ondrej Pokorny

2021-04-07 17:41

developer   ~0130156

It is not a regression - I just tested FPC 2.6.4 and it has the bug as well.

Ondrej Pokorny

2021-04-07 17:47

developer   ~0130157

It is not bound only to Currency, also Int64 returns wrong results:

procedure Test_OtherUnit(const aValue: Int64);
begin
  Writeln('Test_OtherUnit');
  Writeln('aValue: ', aValue); // writes correct value
  Writeln('Double(): ', Double(aValue)); // writes incorrect value
end;

Florian

2021-04-08 16:26

administrator   ~0130176

I think it depends on the language mode (delphi and non-delphi, to be honest I do not remember which way around), if an explicit type cast is really a cast or a conversion.

Florian

2021-04-09 10:46

administrator   ~0130190

Can you please test if you have different language modes active?

Issue History

Date Modified Username Field Change
2021-04-07 17:31 Ondrej Pokorny New Issue
2021-04-07 17:31 Ondrej Pokorny File Added: RoundTo.zip
2021-04-07 17:39 Ondrej Pokorny Summary Regression in explicit cast Double(Currency) => Wrong result from an explicit cast Double(Currency)
2021-04-07 17:39 Ondrej Pokorny Description Updated View Revisions
2021-04-07 17:39 Ondrej Pokorny Steps to Reproduce Updated View Revisions
2021-04-07 17:39 Ondrej Pokorny Additional Information Updated View Revisions
2021-04-07 17:39 Ondrej Pokorny FPCTarget => -
2021-04-07 17:41 Ondrej Pokorny Note Added: 0130156
2021-04-07 17:47 Ondrej Pokorny Summary Wrong result from an explicit cast Double(Currency) => Wrong result from an explicit cast Double()
2021-04-07 17:47 Ondrej Pokorny Description Updated View Revisions
2021-04-07 17:47 Ondrej Pokorny Note Added: 0130157
2021-04-08 16:26 Florian Note Added: 0130176
2021-04-09 10:46 Florian Assigned To => Florian
2021-04-09 10:46 Florian Status new => feedback
2021-04-09 10:46 Florian Note Added: 0130190