apd
apd copied to clipboard
Ln func discrepancies across arch
Description
When using Context#Ln() func we can observe different results depending on the system's arch, for example with the sample code below:
var decCtx = &apd.Context{
Precision: 34,
MaxExponent: apd.MaxExponent,
MinExponent: apd.MinExponent,
Traps: apd.DefaultTraps,
Rounding: apd.RoundDown,
}
i, _, _ := apd.NewFromString("1.6285091944505809264504560045920167")
var r apd.Decimal
decCtx.Ln(&r, i)
fmt.Println(r.String())
The output on arm64 is 0.4876649916811116824516548471782886 and 0.4876649916811116824516548471782887 on amd64.
By investigating it seems the root cause is linked to the usage of math.Log() here which is dependent on the system arch.
Is this difference expected? Is there a mean to mitigate this and have consistent results across arch?