Skip to content

Commit 55f33b7

Browse files
Merge pull request #81 from stephentyrone/lgamma-shims-linux
Add inline decls of lgamma_r and friends on Linux, too.
2 parents 2b63fc8 + 5e978d8 commit 55f33b7

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Sources/NumericsShims/include/NumericsShims.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,22 @@
1111

1212
#define HEADER_SHIM static inline __attribute__((__always_inline__))
1313

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

29+
// MARK: - math functions for float
1630
HEADER_SHIM float libm_cosf(float x) {
1731
return __builtin_cosf(x);
1832
}
@@ -131,9 +145,7 @@ HEADER_SHIM float libm_log10f(float x) {
131145

132146
#if !defined _WIN32
133147
HEADER_SHIM float libm_lgammaf(float x, int *signp) {
134-
#if __APPLE__
135148
extern float lgammaf_r(float, int *);
136-
#endif
137149
return lgammaf_r(x, signp);
138150
}
139151
#endif
@@ -253,9 +265,7 @@ HEADER_SHIM double libm_log10(double x) {
253265

254266
#if !defined _WIN32
255267
HEADER_SHIM double libm_lgamma(double x, int *signp) {
256-
#if __APPLE__
257268
extern double lgamma_r(double, int *);
258-
#endif
259269
return lgamma_r(x, signp);
260270
}
261271
#endif

0 commit comments

Comments
 (0)