1 /** 2 Copyright: Copyright Thomas Stuart Bockman 2015 3 License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. 4 Authors: Thomas Stuart Bockman 5 */ 6 7 module checkedint.noex.safeop; 8 import checkedint.internal; 9 public import checkedint.flags; 10 11 import std.algorithm, future.traits; 12 13 @safe: /+pragma(inline, true):+/ 14 15 public import checkedint.safeop : cmp; 16 17 N unary(string op, bool throws, N)(const N num) 18 if((isIntegral!N || isSomeChar!N) && op.among!("-", "+", "~")) 19 { 20 import checkedint.safeop : impl = unary; 21 return impl!(op, throws)(num); 22 } 23 N unary(string op, N)(const N num) nothrow @nogc 24 if((isIntegral!N || isSomeChar!N) && op.among!("-", "+", "~")) 25 { 26 import checkedint.safeop : impl = unary; 27 return impl!(op, false)(num); 28 } 29 /+ref+/ N unary(string op, bool throws, N)(/+return+/ ref N num) 30 if((isIntegral!N || isSomeChar!N) && op.among!("++", "--")) 31 { 32 import checkedint.safeop : impl = unary; 33 return impl!(op, throws)(num); 34 } 35 /+ref+/ N unary(string op, N)(/+return+/ ref N num) nothrow @nogc 36 if((isIntegral!N || isSomeChar!N) && op.among("++", "--")) 37 { 38 import checkedint.safeop : impl = unary; 39 return impl!(op, false)(num); 40 } 41 42 N abs(bool throws, N)(const N num) 43 if(isFixedPoint!N) 44 { 45 import checkedint.safeop : impl = abs; 46 return impl!throws(num); 47 } 48 N abs(N)(const N num) nothrow @nogc 49 if(isFixedPoint!N) 50 { 51 import checkedint.safeop : impl = abs; 52 return impl!false(num); 53 } 54 55 int bsf(bool throws, N)(const N num) 56 if(isFixedPoint!N) 57 { 58 return bsfImpl!throws(num); 59 } 60 int bsf(N)(const N num) nothrow @nogc 61 if(isFixedPoint!N) 62 { 63 return bsfImpl!false(num); 64 } 65 int bsr(bool throws, N)(const N num) 66 if(isFixedPoint!N) 67 { 68 return bsrImpl!throws(num); 69 } 70 int bsr(N)(const N num) nothrow @nogc 71 if(isFixedPoint!N) 72 { 73 return bsrImpl!false(num); 74 } 75 76 int ilogb(bool throws, N)(const N num) 77 if(isFixedPoint!N) 78 { 79 import checkedint.safeop : impl = ilogb; 80 return impl!throws(num); 81 } 82 int ilogb(N)(const N num) nothrow @nogc 83 if(isFixedPoint!N) 84 { 85 import checkedint.safeop : impl = ilogb; 86 return impl!false(num); 87 } 88 89 OpType!(N, op, M) binary(string op, bool throws, N, M)(const N left, const M right) 90 if(isFixedPoint!N && isFixedPoint!M && op.among!("+", "-", "*", "/", "%", "^^", "<<", ">>", ">>>", "&", "|", "^")) 91 { 92 import checkedint.safeop : impl = binary; 93 return impl!(op, throws)(left, right); 94 } 95 OpType!(N, op, M) binary(string op, N, M)(const N left, const M right) nothrow @nogc 96 if(isFixedPoint!N && isFixedPoint!M && op.among!("+", "-", "*", "/", "%", "^^", "<<", ">>", ">>>", "&", "|", "^")) 97 { 98 import checkedint.safeop : impl = binary; 99 return impl!(op, false)(left, right); 100 } 101 /+ref+/ N binary(string op, bool throws, N, M)(/+return+/ ref N left, const M right) 102 if((isIntegral!N || isSomeChar!N) && isFixedPoint!M && (op[$ - 1] == '=')) 103 { 104 import checkedint.safeop : impl = binary; 105 return impl!(op, throws)(left, right); 106 } 107 /+ref+/ N binary(string op, N, M)(/+return+/ ref N left, const M right) nothrow @nogc 108 if((isIntegral!N || isSomeChar!N) && isFixedPoint!M && (op[$ - 1] == '=')) 109 { 110 import checkedint.safeop : impl = binary; 111 return impl!(op, false)(left, right); 112 } 113 114 auto mulPow2(N, M)(const N coef, const M exp) pure nothrow @nogc 115 if((isFloatingPoint!N && isScalarType!M) || (isScalarType!N && isFloatingPoint!M)) 116 { 117 import checkedint.safeop : impl = mulPow2; 118 return impl(coef, exp); 119 } 120 auto mulPow2(bool throws, N, M)(const N coef, const M exp) 121 if(isFixedPoint!N && isFixedPoint!M) 122 { 123 import checkedint.safeop : impl = mulPow2; 124 return impl!throws(coef, exp); 125 } 126 auto mulPow2(N, M)(const N coef, const M exp) nothrow @nogc 127 if(isFixedPoint!N && isFixedPoint!M) 128 { 129 import checkedint.safeop : impl = mulPow2; 130 return impl!false(coef, exp); 131 } 132 auto divPow2(N, M)(const N coef, const M exp) pure nothrow @nogc 133 if((isFloatingPoint!N && isScalarType!M) || (isScalarType!N && isFloatingPoint!M)) 134 { 135 import checkedint.safeop : impl = divPow2; 136 return impl(coef, exp); 137 } 138 auto divPow2(bool throws, N, M)(const N coef, const M exp) 139 if(isFixedPoint!N && isFixedPoint!M) 140 { 141 import checkedint.safeop : impl = divPow2; 142 return impl!throws(coef, exp); 143 } 144 auto divPow2(N, M)(const N coef, const M exp) nothrow @nogc 145 if(isFixedPoint!N && isFixedPoint!M) 146 { 147 import checkedint.safeop : impl = divPow2; 148 return impl!false(coef, exp); 149 } 150 151 CallType!(std.math.pow, N, M) pow(bool throws, N, M)(const N base, const M exp) 152 if(isFixedPoint!N && isFixedPoint!M) 153 { 154 import checkedint.safeop : impl = pow; 155 return impl!throws(base, exp); 156 } 157 CallType!(std.math.pow, N, M) pow(N, M)(const N base, const M exp) nothrow @nogc 158 if(isFixedPoint!N && isFixedPoint!M) 159 { 160 import checkedint.safeop : impl = pow; 161 return impl!false(base, exp); 162 }