summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2022-06-01 12:55:03 +0200
committerEugen Wissner <belka@caraus.de>2022-06-01 12:55:03 +0200
commit7dd4c4414001729129745f087ff9c80a6c1d81ac (patch)
treecfa2aed320865390c7f8225693f676aad823bc82
parent81b4fb88f597db05be06fb727ae1c45e8148439c (diff)
downloadtanya-7dd4c4414001729129745f087ff9c80a6c1d81ac.tar.gz
Remove math function wrappers
-rw-r--r--source/tanya/math/nbtheory.d111
-rw-r--r--source/tanya/math/package.d74
-rw-r--r--source/tanya/math/random.d2
3 files changed, 3 insertions, 184 deletions
diff --git a/source/tanya/math/nbtheory.d b/source/tanya/math/nbtheory.d
deleted file mode 100644
index 25c4517..0000000
--- a/source/tanya/math/nbtheory.d
+++ /dev/null
@@ -1,111 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/**
- * Number theory.
- *
- * Copyright: Eugene Wissner 2017-2020.
- * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
- * Mozilla Public License, v. 2.0).
- * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
- * Source: $(LINK2 https://github.com/caraus-ecms/tanya/blob/master/source/tanya/math/nbtheory.d,
- * tanya/math/nbtheory.d)
- */
-module tanya.math.nbtheory;
-
-import tanya.meta.trait;
-import tanya.meta.transform;
-
-import core.math : fabs;
-import std.math : log;
-
-/**
- * Calculates the absolute value of a number.
- *
- * Params:
- * T = Argument type.
- * x = Argument.
- *
- * Returns: Absolute value of $(D_PARAM x).
- */
-Unqual!T abs(T)(T x)
-if (isIntegral!T)
-{
- static if (isSigned!T)
- {
- return x >= 0 ? x : -x;
- }
- else
- {
- return x;
- }
-}
-
-///
-@nogc nothrow pure @safe unittest
-{
- int i = -1;
- assert(i.abs == 1);
- static assert(is(typeof(i.abs) == int));
-
- uint u = 1;
- assert(u.abs == 1);
- static assert(is(typeof(u.abs) == uint));
-}
-
-/// ditto
-Unqual!T abs(T)(T x)
-if (isFloatingPoint!T)
-{
- return fabs(x);
-}
-
-///
-@nogc nothrow pure @safe unittest
-{
- float f = -1.64;
- assert(f.abs == 1.64F);
- static assert(is(typeof(f.abs) == float));
-
- double d = -1.64;
- assert(d.abs == 1.64);
- static assert(is(typeof(d.abs) == double));
-
- real r = -1.64;
- assert(r.abs == 1.64L);
- static assert(is(typeof(r.abs) == real));
-}
-
-/**
- * Calculates natural logarithm of $(D_PARAM x).
- *
- * Params:
- * T = Argument type.
- * x = Argument.
- *
- * Returns: Natural logarithm of $(D_PARAM x).
- */
-Unqual!T ln(T)(T x)
-if (isFloatingPoint!T)
-{
- return log(x);
-}
-
-///
-@nogc nothrow pure @safe unittest
-{
- import tanya.math;
-
- assert(isNaN(ln(-7.389f)));
- assert(isNaN(ln(-7.389)));
- assert(isNaN(ln(-7.389L)));
-
- assert(isInfinity(ln(0.0f)));
- assert(isInfinity(ln(0.0)));
- assert(isInfinity(ln(0.0L)));
-
- assert(ln(1.0f) == 0.0f);
- assert(ln(1.0) == 0.0);
- assert(ln(1.0L) == 0.0L);
-}
diff --git a/source/tanya/math/package.d b/source/tanya/math/package.d
index f47f723..c632bba 100644
--- a/source/tanya/math/package.d
+++ b/source/tanya/math/package.d
@@ -12,7 +12,7 @@
* be found in its submodules. $(D_PSYMBOL tanya.math) doesn't import any
* submodules publically, they should be imported explicitly.
*
- * Copyright: Eugene Wissner 2016-2020.
+ * Copyright: Eugene Wissner 2016-2022.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
@@ -21,7 +21,7 @@
*/
module tanya.math;
-import tanya.math.nbtheory;
+import std.math;
import tanya.meta.trait;
import tanya.meta.transform;
@@ -543,73 +543,3 @@ if (isFloatingPoint!F)
assert(signBit(-1.0L));
assert(!signBit(1.0L));
}
-
-/**
- * Computes $(D_PARAM x) to the power $(D_PARAM y) modulo $(D_PARAM z).
- *
- * Params:
- * I = Base type.
- * G = Exponent type.
- * H = Divisor type:
- * x = Base.
- * y = Exponent.
- * z = Divisor.
- *
- * Returns: Reminder of the division of $(D_PARAM x) to the power $(D_PARAM y)
- * by $(D_PARAM z).
- *
- * Precondition: $(D_INLINECODE z > 0)
- */
-H pow(I, G, H)(in auto ref I x, in auto ref G y, in auto ref H z)
-if (isIntegral!I && isIntegral!G && isIntegral!H)
-in
-{
- assert(z > 0, "Division by zero");
-}
-do
-{
- G mask = G.max / 2 + 1;
- H result;
-
- if (y == 0)
- {
- return 1 % z;
- }
- else if (y == 1)
- {
- return x % z;
- }
- do
- {
- immutable bit = y & mask;
- if (!result && bit)
- {
- result = x;
- continue;
- }
-
- result *= result;
- if (bit)
- {
- result *= x;
- }
- result %= z;
- }
- while (mask >>= 1);
-
- return result;
-}
-
-///
-@nogc nothrow pure @safe unittest
-{
- assert(pow(3, 5, 7) == 5);
- assert(pow(2, 2, 1) == 0);
- assert(pow(3, 3, 3) == 0);
- assert(pow(7, 4, 2) == 1);
- assert(pow(53, 0, 2) == 1);
- assert(pow(53, 1, 3) == 2);
- assert(pow(53, 2, 5) == 4);
- assert(pow(0, 0, 5) == 1);
- assert(pow(0, 5, 5) == 0);
-}
diff --git a/source/tanya/math/random.d b/source/tanya/math/random.d
index 6ee4300..68ec317 100644
--- a/source/tanya/math/random.d
+++ b/source/tanya/math/random.d
@@ -5,7 +5,7 @@
/**
* Random number generator.
*
- * Copyright: Eugene Wissner 2016-2020.
+ * Copyright: Eugene Wissner 2016-2022.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)