
On Sun, Sep 4, 2016 at 8:20 PM, Diogo Mildenberger <diogo.milde@gmail.com> wrote:Has someone any experience to share about implementing a system that deals with currency values? I have already been bitten by the problems described in http://floatingpointgui.de/ and I want to find a better way.The two common approaches are fixed point, as you mentioned, and General Decimal Arithmetic, which is basically base10 floating point. See: http://speleotrove.com/decimal/ Ten years ago I made a Lua binding for IBM's General Decimal Arithmetic library decNumber called ldecNumberIt does what you need, but is stuck at Lua 5.1. It depends on some Lua 5.1 features that were removed in 5.2, and would be a bit of work to redo. There have also been some updates to decNumber that ought to be incorporated if ldecNumber is updated. If you work on the library you might consider using decQuad (decimal128) if you can get by with 34 digits of precision; the present version of ldecNumber uses arbitrary precision decNumber set to 69 digits of precision.