henrik / progress_bar

Command-line progress bars and spinners for Elixir.
MIT License
329 stars 20 forks source link

Fix compatibility with newer versions of decimal library #22

Closed tsutsu closed 5 years ago

tsutsu commented 5 years ago

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.

henrik commented 5 years ago

Very neat, thank you!