Skip to content

Commit

Permalink
Merge pull request apple#81 from stephentyrone/lgamma-shims-linux
Browse files Browse the repository at this point in the history
Add inline decls of lgamma_r and friends on Linux, too.
  • Loading branch information
stephentyrone authored Nov 22, 2019
2 parents 2b63fc8 + 5e978d8 commit 55f33b7
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Sources/NumericsShims/include/NumericsShims.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@

#define HEADER_SHIM static inline __attribute__((__always_inline__))

// MARK: - math functions for float
// This header uses most of the libm functions, but we don't want to end up
// exporting the libm declarations to modules that include NumericsShims, so
// we don't want to actually #include <math.h>.
//
// For most of the functions, we can get around this by using __builtin_func
// instead of func, since the compiler knows about these operations, but for
// the non-standard extensions, we need to include our own declarations. This
// is a little bit risky, in that we might end up missing an attribute that
// gets added and effects calling conventions, etc, but that's expected to be
// exceedingly rare.
//
// Still, we'll eventually want to find a better solution to this problem,
// especially if people start using this package on systems that are not
// Darwin or Ubuntu.

// MARK: - math functions for float
HEADER_SHIM float libm_cosf(float x) {
return __builtin_cosf(x);
}
Expand Down Expand Up @@ -131,9 +145,7 @@ HEADER_SHIM float libm_log10f(float x) {

#if !defined _WIN32
HEADER_SHIM float libm_lgammaf(float x, int *signp) {
#if __APPLE__
extern float lgammaf_r(float, int *);
#endif
return lgammaf_r(x, signp);
}
#endif
Expand Down Expand Up @@ -253,9 +265,7 @@ HEADER_SHIM double libm_log10(double x) {

#if !defined _WIN32
HEADER_SHIM double libm_lgamma(double x, int *signp) {
#if __APPLE__
extern double lgamma_r(double, int *);
#endif
return lgamma_r(x, signp);
}
#endif
Expand Down

0 comments on commit 55f33b7

Please sign in to comment.