Make math.nbtheory.ln to a template function

This commit is contained in:
Eugen Wissner 2018-02-24 14:02:18 +01:00
parent 84d6e207c5
commit 464a0fecbb
2 changed files with 32 additions and 39 deletions

View File

@ -2,10 +2,10 @@
// logl. // logl.
.globl _D5tanya4math8nbtheory2lnFNaNbNiNfeZe .globl _D5tanya4math8nbtheory9__T2lnTeZ2lnFNaNbNiNfeZe
.type _D5tanya4math8nbtheory2lnFNaNbNiNfeZe, @function .type _D5tanya4math8nbtheory9__T2lnTeZ2lnFNaNbNiNfeZe, @function
_D5tanya4math8nbtheory2lnFNaNbNiNfeZe: _D5tanya4math8nbtheory9__T2lnTeZ2lnFNaNbNiNfeZe:
fldln2 // Put lb(e) onto the FPU stack fldln2 // Put lb(e) onto the FPU stack
fldt 8(%rsp) // Put the argument onto the FPU stack fldt 8(%rsp) // Put the argument onto the FPU stack
fyl2x // %st1 * lb(%st0) fyl2x // %st1 * lb(%st0)
@ -13,10 +13,10 @@ _D5tanya4math8nbtheory2lnFNaNbNiNfeZe:
// log. // log.
.globl _D5tanya4math8nbtheory2lnFNaNbNiNfdZd .globl _D5tanya4math8nbtheory9__T2lnTdZ2lnFNaNbNiNfdZd
.type _D5tanya4math8nbtheory2lnFNaNbNiNfdZd, @function .type _D5tanya4math8nbtheory9__T2lnTdZ2lnFNaNbNiNfdZd, @function
_D5tanya4math8nbtheory2lnFNaNbNiNfdZd: _D5tanya4math8nbtheory9__T2lnTdZ2lnFNaNbNiNfdZd:
movsd %xmm0, -8(%rsp) // Put the argument onto the stack movsd %xmm0, -8(%rsp) // Put the argument onto the stack
fldln2 // Put lb(e) onto the FPU stack fldln2 // Put lb(e) onto the FPU stack
@ -31,10 +31,10 @@ _D5tanya4math8nbtheory2lnFNaNbNiNfdZd:
// logf. // logf.
.globl _D5tanya4math8nbtheory2lnFNaNbNiNffZf .globl _D5tanya4math8nbtheory9__T2lnTfZ2lnFNaNbNiNffZf
.type _D5tanya4math8nbtheory2lnFNaNbNiNffZf, @function .type _D5tanya4math8nbtheory9__T2lnTfZ2lnFNaNbNiNffZf, @function
_D5tanya4math8nbtheory2lnFNaNbNiNffZf: _D5tanya4math8nbtheory9__T2lnTfZ2lnFNaNbNiNffZf:
movss %xmm0, -4(%rsp) // Put the argument onto the stack movss %xmm0, -4(%rsp) // Put the argument onto the stack
fldln2 // Put lb(e) onto the FPU stack fldln2 // Put lb(e) onto the FPU stack

View File

@ -30,15 +30,15 @@ else
* Calculates the absolute value of a number. * Calculates the absolute value of a number.
* *
* Params: * Params:
* I = Value type. * T = Argument type.
* x = Value. * x = Argument.
* *
* Returns: Absolute value of $(D_PARAM x). * Returns: Absolute value of $(D_PARAM x).
*/ */
I abs(I)(I x) T abs(T)(T x)
if (isIntegral!I) if (isIntegral!T)
{ {
static if (isSigned!I) static if (isSigned!T)
{ {
return x >= 0 ? x : -x; 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; int i = -1;
assert(i.abs == 1); assert(i.abs == 1);
@ -63,25 +63,25 @@ pure nothrow @safe @nogc unittest
version (D_Ddoc) version (D_Ddoc)
{ {
/// ditto /// ditto
I abs(I)(I x) T abs(T)(T x)
if (isFloatingPoint!I); if (isFloatingPoint!T);
} }
else version (TanyaNative) else version (TanyaNative)
{ {
extern I abs(I)(I number) pure nothrow @safe @nogc extern T abs(T)(T number) @nogc nothrow pure @safe
if (isFloatingPoint!I); if (isFloatingPoint!T);
} }
else else
{ {
I abs(I)(I x) T abs(T)(T x)
if (isFloatingPoint!I) if (isFloatingPoint!T)
{ {
return fabs(cast(real) x); return fabs(cast(real) x);
} }
} }
/// ///
pure nothrow @safe @nogc unittest @nogc nothrow pure @safe unittest
{ {
float f = -1.64; float f = -1.64;
assert(f.abs == 1.64F); assert(f.abs == 1.64F);
@ -97,7 +97,7 @@ pure nothrow @safe @nogc unittest
} }
/// ditto /// 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); auto result = Integer(x, x.allocator);
result.sign = Sign.positive; result.sign = Sign.positive;
@ -105,7 +105,7 @@ I abs(I : Integer)(const auto ref I x)
} }
/// ditto /// ditto
I abs(I : Integer)(I x) T abs(T : Integer)(T x)
{ {
x.sign = Sign.positive; x.sign = Sign.positive;
return x; return x;
@ -117,37 +117,30 @@ version (D_Ddoc)
* Calculates natural logarithm of $(D_PARAM x). * Calculates natural logarithm of $(D_PARAM x).
* *
* Params: * Params:
* T = Argument type.
* x = Argument. * x = Argument.
* *
* Returns: Natural logarithm of $(D_PARAM x). * Returns: Natural logarithm of $(D_PARAM x).
*/ */
float ln(float x) pure nothrow @safe @nogc; T ln(T)(T x)
/// ditto if (isFloatingPoint!T);
double ln(double x) pure nothrow @safe @nogc;
/// ditto
real ln(real x) pure nothrow @safe @nogc;
} }
else version (TanyaNative) else version (TanyaNative)
{ {
extern float ln(float x) pure nothrow @safe @nogc; extern T ln(T)(T x) @nogc nothrow pure @safe
extern double ln(double x) pure nothrow @safe @nogc; if (isFloatingPoint!T);
extern real ln(real x) pure nothrow @safe @nogc;
} }
else else
{ {
float ln(float x) pure nothrow @safe @nogc T ln(T)(T x)
if (isFloatingPoint!T)
{ {
return log(x); return log(x);
} }
double ln(double x) pure nothrow @safe @nogc
{
return log(x);
}
alias ln = log;
} }
/// ///
pure nothrow @safe @nogc unittest @nogc nothrow pure @safe unittest
{ {
import tanya.math; import tanya.math;