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.smartop;
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.smartop : cmp;
16 
17 N unary(string op, bool throws, N)(const N num)
18     if(isIntegral!N && op == "~")
19 {
20     import checkedint.smartop : impl = unary;
21     return impl!(op, throws)(num);
22 }
23 N unary(string op, N)(const N num) nothrow @nogc
24     if(isIntegral!N && op == "~")
25 {
26     import checkedint.smartop : impl = unary;
27     return impl!(op, false)(num);
28 }
29 IntFromChar!N unary(string op, bool throws, N)(const N num)
30     if(isSomeChar!N && op == "~")
31 {
32     import checkedint.smartop : impl = unary;
33     return impl!(op, throws)(num);
34 }
35 IntFromChar!N unary(string op, N)(const N num) nothrow @nogc
36     if(isSomeChar!N && op == "~")
37 {
38     import checkedint.smartop : impl = unary;
39     return impl!(op, false)(num);
40 }
41 Signed!(Promoted!N) unary(string op, bool throws, N)(const N num)
42     if(isFixedPoint!N && op.among!("-", "+"))
43 {
44     import checkedint.smartop : impl = unary;
45     return impl!(op, throws)(num);
46 }
47 Signed!(Promoted!N) unary(string op, N)(const N num) nothrow @nogc
48     if(isFixedPoint!N && op.among!("-", "+"))
49 {
50     import checkedint.smartop : impl = unary;
51     return impl!(op, false)(num);
52 }
53 /+ref+/ N unary(string op, bool throws, N)(/+return+/ ref N num)
54     if(isIntegral!N && op.among!("++", "--"))
55 {
56     import checkedint.smartop : impl = unary;
57     return impl!(op, throws)(num);
58 }
59 /+ref+/ N unary(string op, N)(/+return+/ ref N num) nothrow @nogc
60     if(isIntegral!N && op.among!("++", "--"))
61 {
62     import checkedint.smartop : impl = unary;
63     return impl!(op, false)(num);
64 }
65 
66 public import checkedint.smartop : abs;
67 
68 ubyte bsf(bool throws, N)(const N num)
69     if(isFixedPoint!N)
70 {
71     return cast(ubyte) bsfImpl!throws(num);
72 }
73 ubyte bsf(N)(const N num) nothrow @nogc
74     if(isFixedPoint!N)
75 {
76     return bsf!false(num);
77 }
78 ubyte bsr(bool throws, N)(const N num)
79     if(isFixedPoint!N)
80 {
81     return cast(ubyte) bsrImpl!throws(num);
82 }
83 ubyte bsr(N)(const N num) nothrow @nogc
84     if(isFixedPoint!N)
85 {
86     return bsr!false(num);
87 }
88 
89 ubyte ilogb(bool throws, N)(const N num)
90     if(isFixedPoint!N)
91 {
92     import checkedint.smartop : impl = ilogb;
93     return impl!throws(abs(num));
94 }
95 ubyte ilogb(N)(const N num) nothrow @nogc
96     if(isFixedPoint!N)
97 {
98     import checkedint.smartop : impl = ilogb;
99     return ilogb!false(num);
100 }
101 
102 auto binary(string op, bool throws, N, M)(const N left, const M right)
103     if(isIntegral!N && isIntegral!M)
104 {
105     import checkedint.smartop : impl = binary;
106     return impl!(op, throws)(left, right);
107 }
108 auto binary(string op, N, M)(const N left, const M right) nothrow @nogc
109     if(isIntegral!N && isIntegral!M)
110 {
111     import checkedint.smartop : impl = binary;
112     return impl!(op, false)(left, right);
113 }
114 
115 auto mulPow2(N, M)(const N coef, const M exp) pure nothrow @nogc
116     if((isFloatingPoint!N && isScalarType!M) || (isScalarType!N && isFloatingPoint!M))
117 {
118     import checkedint.smartop : impl = mulPow2;
119     return impl(coef, exp);
120 }
121 auto mulPow2(bool throws, N, M)(const N coef, const M exp)
122     if(isFixedPoint!N && isFixedPoint!M)
123 {
124     import checkedint.smartop : impl = mulPow2;
125     return impl!throws(coef, exp);
126 }
127 auto mulPow2(N, M)(const N coef, const M exp) nothrow @nogc
128     if(isFixedPoint!N && isFixedPoint!M)
129 {
130     import checkedint.smartop : impl = mulPow2;
131     return impl!false(coef, exp);
132 }
133 auto divPow2(N, M)(const N coef, const M exp) pure nothrow @nogc
134     if((isFloatingPoint!N && isScalarType!M) || (isScalarType!N && isFloatingPoint!M))
135 {
136     import checkedint.smartop : impl = divPow2;
137     return impl(coef, exp);
138 }
139 auto divPow2(bool throws, N, M)(const N coef, const M exp)
140     if(isFixedPoint!N && isFixedPoint!M)
141 {
142     import checkedint.smartop : impl = divPow2;
143     return impl!throws(coef, exp);
144 }
145 auto divPow2(N, M)(const N coef, const M exp) nothrow @nogc
146     if(isFixedPoint!N && isFixedPoint!M)
147 {
148     import checkedint.smartop : impl = divPow2;
149     return impl!false(coef, exp);
150 }
151 
152 auto pow(N, M)(const N base, const M exp) pure nothrow @nogc
153     if((isFloatingPoint!N && isScalarType!M) || (isScalarType!N && isFloatingPoint!M))
154 {
155     import checkedint.smartop : impl = pow;
156     return impl(base, exp);
157 }
158 auto pow(bool throws, N, M)(const N base, const M exp)
159     if(isFixedPoint!N && isFixedPoint!M)
160 {
161     import checkedint.smartop : impl = pow;
162     return impl!throws(base, exp);
163 }
164 auto pow(N, M)(const N base, const M exp) nothrow @nogc
165     if(isFixedPoint!N && isFixedPoint!M)
166 {
167     import checkedint.smartop : impl = pow;
168     return impl!false(base, exp);
169 }