As of Decimal 1.6.0, Decimal.new(n) when is_float(n) will emit a deprecation warning, recommending to use Decimal.from_float(n) instead.
If Decimal.from_float/1 always existed, the code could just be updated to use it. However, even as of Decimal 1.4.0, Decimal.from_float/1 didn't exist. Therefore, if compatibility with older versions of Decimal is desired, it is best to do "feature detection" and use from_float/1 only if it is available.
This PR does so, with the feature detection happening at compile-time for no added runtime cost.
As of Decimal 1.6.0,
Decimal.new(n) when is_float(n)
will emit a deprecation warning, recommending to useDecimal.from_float(n)
instead.If
Decimal.from_float/1
always existed, the code could just be updated to use it. However, even as of Decimal 1.4.0,Decimal.from_float/1
didn't exist. Therefore, if compatibility with older versions of Decimal is desired, it is best to do "feature detection" and usefrom_float/1
only if it is available.This PR does so, with the feature detection happening at compile-time for no added runtime cost.