Closed JeffBezanson closed 13 years ago
Are there implementations available for those five functions? IIRC you said they were all rounding functions. Maybe LLVM has trustworthy intrinsics for those operations — rounding is pretty unambiguous.
No, LLVM does not have those as intrinsics, and as far as I can tell the intrinsics LLVM does have just call libm. We can get implementations from BSD.
Oh, llvm-config has us linking with -lm, so we won't be able to remove it. Not a big deal.
Those two fixed, but we are also missing tgamma.
tgamma is called gamma — I added it the other day. We can make tgamma be an alias, but that seems like a historical accident due to a mistake that it would be fairly silly to inherit from C.
Sure, it's called gamma in julia, but what we're missing is the actual implementation of tgamma in fdlibm:
julia> gamma(2)
dlsym: /home/jeff/src/julia2/julia/lib/libfdm.so: undefined symbol: tgamma
That's weird. Mine work — I tested them before making that commit:
julia> gamma(4.5)
11.6317283965674498
julia> gamma(float32(4.5))
11.63172817
It must be finding the symbol from libm somehow. grep tgamma *
in fdlibm/ is empty. Maybe try ldd and nm on libfdm.dylib.
Ah, yeah, that's really strange. This would be found if we could force LLVM not to link against libm
since then there would be no tgamma
at all to link to.
My understanding is that gamma
is deprecated in favor of tgamma
because historically, on some systems gamma
was the log-gamma function whereas on other systems it was just the gamma function. The only way to guarantee that the implementation and the intended usage were in agreement was to deprecate gamma
and have tgamma
replace it as unambiguously meaning the non-log gamma function.
So as long as the fdlibm
we include has a gamma function that means tgamma
, we can just use its gamma function. But given the mislinking above, I'm a little afraid to do that. If we can get rid of the -lm
under llvm-config, that would work. Alternatively, we can just fork fdlibm's code and rename gamma
to tgamma
everywhere.
Let me know if 9d1009f9 fixes this for you, Jeff. I can't test since it was already working for me.
Stefan, that commit is shameful. You didn't even look at the code. fdlibm uses the old naming convention where "gamma" means log-gamma. Its "gamma" just calls lgamma.
Ugh. Sorry. That is really embarrassing. I was somehow still linking against the libm version, so I was getting apparently correct results. I'll endeavor to find a working tgamma implementation to plug in here...
fdlibm seems to be missing a few functions here and there. fdlibmf has log2f, but fdlibm does not have log2:
On the other hand, fdlibm has lgamma_r but fdlibmf does not. I found implementations of these from BSD sources by searching for e_log2.c and e_lgammaf_r.c.