summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2018-02-24 14:02:18 +0100
committerEugen Wissner <belka@caraus.de>2018-02-25 05:38:21 +0100
commit464a0fecbb078f07a148c48d317ad6317cdb6236 (patch)
treec4cf18a9e2f0cdab30a808235eb410a4c3fa48fa
parent84d6e207c5440ab42fd86077a59eb41ed67536aa (diff)
downloadtanya-464a0fecbb078f07a148c48d317ad6317cdb6236.tar.gz
Make math.nbtheory.ln to a template function
-rw-r--r--arch/x64/linux/math/log.S18
-rw-r--r--source/tanya/math/nbtheory.d53
2 files changed, 32 insertions, 39 deletions
diff --git a/arch/x64/linux/math/log.S b/arch/x64/linux/math/log.S
index 7f23703..941e399 100644
--- a/arch/x64/linux/math/log.S
+++ b/arch/x64/linux/math/log.S
@@ -2,10 +2,10 @@
// logl.
- .globl _D5tanya4math8nbtheory2lnFNaNbNiNfeZe
- .type _D5tanya4math8nbtheory2lnFNaNbNiNfeZe, @function
+ .globl _D5tanya4math8nbtheory9__T2lnTeZ2lnFNaNbNiNfeZe
+ .type _D5tanya4math8nbtheory9__T2lnTeZ2lnFNaNbNiNfeZe, @function
-_D5tanya4math8nbtheory2lnFNaNbNiNfeZe:
+_D5tanya4math8nbtheory9__T2lnTeZ2lnFNaNbNiNfeZe:
fldln2 // Put lb(e) onto the FPU stack
fldt 8(%rsp) // Put the argument onto the FPU stack
fyl2x // %st1 * lb(%st0)
@@ -13,10 +13,10 @@ _D5tanya4math8nbtheory2lnFNaNbNiNfeZe:
// log.
- .globl _D5tanya4math8nbtheory2lnFNaNbNiNfdZd
- .type _D5tanya4math8nbtheory2lnFNaNbNiNfdZd, @function
+ .globl _D5tanya4math8nbtheory9__T2lnTdZ2lnFNaNbNiNfdZd
+ .type _D5tanya4math8nbtheory9__T2lnTdZ2lnFNaNbNiNfdZd, @function
-_D5tanya4math8nbtheory2lnFNaNbNiNfdZd:
+_D5tanya4math8nbtheory9__T2lnTdZ2lnFNaNbNiNfdZd:
movsd %xmm0, -8(%rsp) // Put the argument onto the stack
fldln2 // Put lb(e) onto the FPU stack
@@ -31,10 +31,10 @@ _D5tanya4math8nbtheory2lnFNaNbNiNfdZd:
// logf.
- .globl _D5tanya4math8nbtheory2lnFNaNbNiNffZf
- .type _D5tanya4math8nbtheory2lnFNaNbNiNffZf, @function
+ .globl _D5tanya4math8nbtheory9__T2lnTfZ2lnFNaNbNiNffZf
+ .type _D5tanya4math8nbtheory9__T2lnTfZ2lnFNaNbNiNffZf, @function
-_D5tanya4math8nbtheory2lnFNaNbNiNffZf:
+_D5tanya4math8nbtheory9__T2lnTfZ2lnFNaNbNiNffZf:
movss %xmm0, -4(%rsp) // Put the argument onto the stack
fldln2 // Put lb(e) onto the FPU stack
diff --git a/source/tanya/math/nbtheory.d b/source/tanya/math/nbtheory.d
index 4c94550..6f8bfbd 100644
--- a/source/tanya/math/nbtheory.d
+++ b/source/tanya/math/nbtheory.d
@@ -30,15 +30,15 @@ else
* Calculates the absolute value of a number.
*
* Params:
- * I = Value type.
- * x = Value.
+ * T = Argument type.
+ * x = Argument.
*
* Returns: Absolute value of $(D_PARAM x).
*/
-I abs(I)(I x)
-if (isIntegral!I)
+T abs(T)(T x)
+if (isIntegral!T)
{
- static if (isSigned!I)
+ static if (isSigned!T)
{
return x >= 0 ? x : -x;
}
@@ -49,7 +49,7 @@ if (isIntegral!I)
}
///
-pure nothrow @safe @nogc unittest
+@nogc nothrow pure @safe unittest
{
int i = -1;
assert(i.abs == 1);
@@ -63,25 +63,25 @@ pure nothrow @safe @nogc unittest
version (D_Ddoc)
{
/// ditto
- I abs(I)(I x)
- if (isFloatingPoint!I);
+ T abs(T)(T x)
+ if (isFloatingPoint!T);
}
else version (TanyaNative)
{
- extern I abs(I)(I number) pure nothrow @safe @nogc
- if (isFloatingPoint!I);
+ extern T abs(T)(T number) @nogc nothrow pure @safe
+ if (isFloatingPoint!T);
}
else
{
- I abs(I)(I x)
- if (isFloatingPoint!I)
+ T abs(T)(T x)
+ if (isFloatingPoint!T)
{
return fabs(cast(real) x);
}
}
///
-pure nothrow @safe @nogc unittest
+@nogc nothrow pure @safe unittest
{
float f = -1.64;
assert(f.abs == 1.64F);
@@ -97,7 +97,7 @@ pure nothrow @safe @nogc unittest
}
/// ditto
-I abs(I : Integer)(const auto ref I x)
+T abs(T : Integer)(const auto ref T x)
{
auto result = Integer(x, x.allocator);
result.sign = Sign.positive;
@@ -105,7 +105,7 @@ I abs(I : Integer)(const auto ref I x)
}
/// ditto
-I abs(I : Integer)(I x)
+T abs(T : Integer)(T x)
{
x.sign = Sign.positive;
return x;
@@ -117,37 +117,30 @@ version (D_Ddoc)
* Calculates natural logarithm of $(D_PARAM x).
*
* Params:
+ * T = Argument type.
* x = Argument.
*
* Returns: Natural logarithm of $(D_PARAM x).
*/
- float ln(float x) pure nothrow @safe @nogc;
- /// ditto
- double ln(double x) pure nothrow @safe @nogc;
- /// ditto
- real ln(real x) pure nothrow @safe @nogc;
+ T ln(T)(T x)
+ if (isFloatingPoint!T);
}
else version (TanyaNative)
{
- extern float ln(float x) pure nothrow @safe @nogc;
- extern double ln(double x) pure nothrow @safe @nogc;
- extern real ln(real x) pure nothrow @safe @nogc;
+ extern T ln(T)(T x) @nogc nothrow pure @safe
+ if (isFloatingPoint!T);
}
else
{
- float ln(float x) pure nothrow @safe @nogc
- {
- return log(x);
- }
- double ln(double x) pure nothrow @safe @nogc
+ T ln(T)(T x)
+ if (isFloatingPoint!T)
{
return log(x);
}
- alias ln = log;
}
///
-pure nothrow @safe @nogc unittest
+@nogc nothrow pure @safe unittest
{
import tanya.math;