I tested these two approaches using a log()
implementation with a maximum error of <0.53 ulps, compared to a multi-point arithmetic library. Using this implementation of log()
as the building block for the two variants of log1p()
, I found that the maximum error in the Goldberg version is <1.51 ulps, while the maximum error in the GSL variant was <0.67 ulps. This indicates that the latter will be significantly more accurate.
In terms of handling special cases, the Goldberg variant showed one inconsistency in which it returns NaN for input + infinity, while the correct result is + infinity. For special cases with the GSL implementation, there were three inconsistencies: inputs -1 and + of infinity delivered NaN, and the correct results should be -infection and + infinity, respectively. In addition, for entering -0, this code returns +0, while the correct result is -0.
It is difficult to evaluate performance without knowledge of resource allocation. As others noted in the comments, the Goldberg version is potentially faster when many arguments are close to zero, as it misses the expensive log()
call for such arguments.
source share