[erlang-questions] Where is fmod in Erlang?

Pierpaolo Bernardi olopierpa@REDACTED
Wed Oct 26 02:36:07 CEST 2016


So, the simplest method was to use a nif, after all.


On Tue, Oct 25, 2016 at 6:34 AM,  <ok@REDACTED> wrote:
>>> How to calculate fmod in Erlang ?
>>
>> fmod(a, b) ->
>>     a - trunc(a/b) * b.
>
> This is a bit like saying that you can implement fma(x, y, z)
> as x*y + z.  The point of fma() is that it does one rounding,
> not two.  In the same way we expect fmod(a, b) should NOT
> involve three roundings, as the code above does.  I've seen
> more than one implementation of fmod() for C, and they are
> not simple code.
>
> The Erlang function above *almost* computes the same results
> as C's fmod() but not quite.  The relative error in one run
> was within +/- 1e-12.  (Another run which I didn't
> capture got as far as 7e-12 away.)
>
> Isn't it time the Erlang 'math' module caught up with C89?
> (Or Unix V7, come to that.)



More information about the erlang-questions mailing list