From 2ec750ca05a87ebc20e358e73cb375a2c844ad59 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 8 May 2018 17:45:51 +0200 Subject: Fix math.nbtheory linkage to asm Don't use extern for templated functions. If the function argument is const, it gets a different mangling. So define a private function for each floatint point length and call it from template. --- source/tanya/math/nbtheory.d | 53 ++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'source') diff --git a/source/tanya/math/nbtheory.d b/source/tanya/math/nbtheory.d index 889e10f..c20cc67 100644 --- a/source/tanya/math/nbtheory.d +++ b/source/tanya/math/nbtheory.d @@ -16,9 +16,17 @@ module tanya.math.nbtheory; import tanya.math.mp; import tanya.meta.trait; +import tanya.meta.transform; version (TanyaNative) { + private extern float fabs(float) @nogc nothrow pure @safe; + private extern double fabs(double) @nogc nothrow pure @safe; + private extern real fabs(real) @nogc nothrow pure @safe; + + private extern double log(double) @nogc nothrow pure @safe; + private extern float logf(float) @nogc nothrow pure @safe; + private extern real logl(real) @nogc nothrow pure @safe; } else { @@ -35,7 +43,7 @@ else * * Returns: Absolute value of $(D_PARAM x). */ -T abs(T)(T x) +Unqual!T abs(T)(T x) if (isIntegral!T) { static if (isSigned!T) @@ -60,24 +68,11 @@ if (isIntegral!T) static assert(is(typeof(u.abs) == uint)); } -version (D_Ddoc) -{ - /// ditto - T abs(T)(T x) - if (isFloatingPoint!T); -} -else version (TanyaNative) -{ - extern T abs(T)(T number) @nogc nothrow pure @safe - if (isFloatingPoint!T); -} -else +/// ditto +Unqual!T abs(T)(T x) +if (isFloatingPoint!T) { - T abs(T)(T x) - if (isFloatingPoint!T) - { - return fabs(cast(real) x); - } + return fabs(x); } /// @@ -122,17 +117,31 @@ version (D_Ddoc) * * Returns: Natural logarithm of $(D_PARAM x). */ - T ln(T)(T x) + Unqual!T ln(T)(T x) if (isFloatingPoint!T); } else version (TanyaNative) { - extern T ln(T)(T x) @nogc nothrow pure @safe - if (isFloatingPoint!T); + Unqual!T ln(T)(T x) @nogc nothrow pure @safe + if (isFloatingPoint!T) + { + static if (is(Unqual!T == float)) + { + return logf(x); + } + else static if (is(Unqual!T == double)) + { + return log(x); + } + else + { + return logl(x); + } + } } else { - T ln(T)(T x) + Unqual!T ln(T)(T x) if (isFloatingPoint!T) { return log(x); -- cgit v1.2.3