1 /*This program is free software: you can redistribute it and/or modify 2 it under the terms of the GNU General Public License as published by 3 the Free Software Foundation, either version 3 of the License, or 4 (at your option) any later version. 5 6 This program is distributed in the hope that it will be useful, 7 but WITHOUT ANY WARRANTY; without even the implied warranty of 8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 GNU General Public License for more details. 10 11 You should have received a copy of the GNU General Public License 12 along with this program. If not, see <http://www.gnu.org/licenses/>.*/ 13 /** Copyright: 2022.2023, Ruby The Roobster*/ 14 /**Author: Ruby The Roobster, <michaeleverestc79@gmail.com>*/ 15 /**Date: January 16, 2023*/ 16 /** License: GPL-3.0*/ 17 18 /// Definitions for dutils.math.core so as to not clog up the whole file. 19 module dutils.math.def; 20 21 version(DLL) 22 { 23 export: 24 } 25 26 version(Standard) 27 { 28 public: 29 } 30 private alias Unshared(T) = T; 31 private alias Unshared(T: shared U, U) = U; 32 33 /// Base class for all math types. 34 abstract class Mtype(T) if(__traits(hasMember, T, "precision")) 35 { 36 /// Converts the Mtype to a dstring. 37 abstract dstring toDstring() const @property pure @safe; 38 /// Converts a dstring to an Mtype. 39 abstract void fromDstring(dstring from) pure @safe; 40 /// Apply an operation to an Mtype. 41 abstract bool applyOp(W)(dstring op, in Mtype!W rhs) pure @safe; 42 /// Apply an operation from the right side. 43 bool applyOpRight(W)(dstring op, ref Mtype!W lhs) pure @safe 44 { 45 return lhs.applyOp(op, this); 46 } 47 /// Return the value stored in the Mtype. 48 final T val() const pure @safe @property 49 { 50 return this.contained; 51 } 52 /// Return the type if the value contained. 53 final auto containedType() const pure @safe @property 54 { 55 return T.stringof; 56 } 57 /// Precision Constructor 58 this(ulong precision) pure @safe nothrow 59 { 60 this.contained = T(); 61 this.contained.precision = precision; 62 } 63 /// Normal Constructor 64 this(in T num = T()) pure @safe nothrow 65 { 66 this.contained = num; 67 } 68 protected: 69 T contained; 70 } 71 72 /// Define an Operator as used by dutils.math. 73 alias Operator = dstring function(dstring[]) @safe; 74 75 /// Container for the list of all operators. 76 struct Oplist 77 { 78 Operator opIndex(dstring op) pure @safe const shared 79 { 80 return this.ops[op]; 81 } 82 auto opBinaryRight(string op)(dstring key) pure @safe const shared if(op == "in" || op == "!in") 83 { 84 mixin("return key " ~ op ~ " ops;"); 85 } 86 auto keys() @safe 87 { 88 return this.ops.keys; 89 } 90 package: 91 Operator[dstring] ops; 92 } 93 94 /// The list of all operators. 95 package shared Oplist opList; 96 97 /// Container for the function list. 98 struct Funclist 99 { 100 dstring opIndex(dstring func) pure const @safe shared 101 { 102 return this.funcs[func]; 103 } 104 auto opBinaryRight(string op)(inout(dchar)[] key) pure const @trusted shared if(op == "in" || op == "!in") 105 { 106 mixin("return cast(dstring)key " ~ op ~ " funcs;"); 107 } 108 auto keys() 109 { 110 return this.funcs.keys; 111 } 112 package: 113 dstring[dstring] funcs; 114 } 115 116 /// The list of all functions. 117 package shared Funclist funcList; 118 119 package import dutils.math.number; // I'm not sure why this line is here, but I'm too scared to touch it. 120 121 /// The list of all types, that has to be kept here and continously updated. 122 enum dstring[] typel = ["Number"]; // Too bad that complete modular programming is impossible in D.