As I understand a thumb rule for allowing expressions in Delphi constants is that the expression should be able to get evaluated in complile time.
So it's greatly unclear for me why the following is not allowed ([dcc64 Error] E2026 Constant expression expected):
const
SCAPEGOATALHPA = 2.0 / 3;
SCAPEGOATCONST = 1.0 / ln(SCAPEGOATALHPA);
Is something that would prevent Delphi compute the natural logarithm of a constant float number? Or just a Delphi bug, as usual?
Ln
is a normal function, just like one you'd write yourself. Hence it can only be executed at runtime. If you Ctrl-clickLn
, you will see its source code. The same thing applies toSqrt
, for instance. But if you ctrl-clickRount
, you will not see its source code. That's because that is a "magic" function, and it can be used at compile time.ln()
is a function with a result, not a literal. Don't confuse this with typecasting, which looks the same (i.e.Double(5)
) and still is a literal.Double(5)
isn't a literal, but it is still a constant expression.high
is also accepted:const XXX = high(integer);
Thoughhigh
is also a normal function, in system unit. So I still cannot see lots of logic in that.