Both Cardinal
and Single
are 4 byte / 32 bit datatypes, but when I typecast them to each other I get an Invalid Typecast
error in Delphi 10.1 (Berlin).
lSingleVar := Single(lCardinalVar);
I am NOT talking about converting between the two types, as that will only store 23 bits of the cardinal data (the fraction part of the Single datatype). I need to store minimum 30 bits of data into a Single
variable. I have good reasons for that (the type cannot be changed), which I will be pleased to elaborate on.
How do I typecast a Single
variable?
lSingleVar := TConverter(lCardinalVar).s;
and the compiler will emit a simple mov operation, just the same as it would emit for the code in my answer – Flabby