Odd result from Distributions quantile

I am experiencing inconsistent results using the Distributions package. When I run the following code, I get two different results on different machines

Distributions.quantile(Distributions.Normal(), 0.3631592166130919)

a> -0.3500270020514903
b> -0.3500270020514902

Which looks very little difference, but because of some ripple effect it turns causing issues with my roll-ups :confused:

Digging into it, I figured that the issue hides into the Base.Math library, in the @horner macro that, following the code, is called with the parameters:

@horner(-0.4875984000082292, 0.14780_64707_15138_316110e2, -0.91374_16702_42603_13936e2, 0.21015_79048_62053_17714e3, -0.22210_25412_18551_32366e3, 0.10760_45391_60551_23830e3, -0.20601_07303_28265_443e2, 0.1e1)

Which results in
a> 141.71157435331995
b> 141.71157435331997

Looking into the macro I can’t really figure out what’s going on!

macro horner(x, p...)
    ex = esc(p[end])
    for i = length(p)-1:-1:1
        ex = :(muladd(t, $ex, $(esc(p[i]))))
    ex = quote local r = $ex end 
    return Expr(:block, :(local t = $(esc(x))), ex, :r)

What can possibly cause the issue? Thanks

muladd does a “fused multiply-add” operation using SIMD instructions if possible. This will give slightly different results depending on instructions which are available on the machine (SSE, AVX, etc.). Anyway in general with floating point better be tolerant to small differences, e.g. using isapprox.


That is the issue - one of the machines has FMA support, the other one does not! Thanks for you help :slight_smile:

Just in case anyone else stumble on my same issue - it is possible to exclude specific CPU features as described here, so in my case I had to use the following arguments:

julia --cpu-target=native,-fma

Moreover, since I am using workers for parallel operations, I had to add exeflags when starting new processes

addprocs(n, exeflags="–cpu-target=native,-fma")