1 #ifndef __DUNE_ACFEM_EXPRESSIONS_INTCONSTOPERATIONS_HH__
2 #define __DUNE_ACFEM_EXPRESSIONS_INTCONSTOPERATIONS_HH__
4 #include "../common/types.hh"
5 #include "../common/fractionconstant.hh"
6 #include "../common/namedconstant.hh"
7 #include "expressiontraits.hh"
14 template<
class I, I N, I D>
15 struct FieldTraits<ACFem::TypedValue::FractionConstant<I, N, D> >
16 : FieldTraits<ACFem::ConditionalType<D == 1, I, ACFem::FloatingPointClosure<I> > >
19 template<
class T,
char... Name>
20 struct FieldTraits<ACFem::TypedValue::NamedConstant<T, Name...> >
28 using TypedValue::FractionConstant;
29 using TypedValue::Fraction;
30 using TypedValue::IntFraction;
31 using TypedValue::intFraction;
32 using TypedValue::numerator;
33 using TypedValue::denominator;
34 using TypedValue::Sign;
35 using TypedValue::sign;
36 using TypedValue::IsSign;
49 template<
class I, I N, I D>
55 template<
class T,
char... Name>
56 struct IsScalar<TypedValue::NamedConstant<T, Name...> >
61 template<
class I, I N>
69 template<
class T,
bool Exclusive = true>
74 && !IsExpression<T>::value
79 template<class T, std::enable_if_t<IsFractionOperand<T, false>::value,
int> = 0>
82 return IntFraction<0, 1>{};
87 template<class T, std::enable_if_t<IsFractionOperand<T, false>::value,
int> = 0>
88 constexpr
auto one(T&& t)
90 return IntFraction<1, 1>{};
94 template<
class Int, Int N, Int D>
98 static constexpr ssize_t nSign = (N == 0 ? 0 : (N > 0 ? 1 : -1));
99 static constexpr ssize_t dSign = (D == 0 ? 0 : (D > 0 ? 1 : -1));
101 static constexpr
bool isSemiPositive = nSign * dSign >= 0;
102 static constexpr
bool isSemiNegative = nSign * dSign <= 0;
103 static constexpr
bool isZero = N == 0;
104 static constexpr
bool isOne = N*D == 1;
105 static constexpr
bool isMinusOne = N*D == -1;
106 static constexpr
bool isNonZero = !isZero;
107 static constexpr
bool isNonSingular = !isZero && D != 0;
108 static constexpr
bool isPositive = nSign * dSign > 0;
109 static constexpr
bool isNegaive = nSign * dSign < 0;
111 static constexpr
bool isVolatile =
false;
112 static constexpr
bool isIndependent =
true;
114 static constexpr
bool isTypedValue =
true;
120 template<
class T,
char... Name>
124 static constexpr
bool isVolatile =
false;
125 static constexpr
bool isIndependent =
true;
127 static constexpr
bool isTypedValue =
true;
134 namespace Expressions {
136 template<
class T,
char... Name>
139 template<
class Int, Int N, Int D>
140 constexpr
inline std::size_t WeightV<FractionConstant<Int, N, D> > = 1UL;
146 namespace TypedValue {
159 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
162 return zero(std::forward<T>(t));
166 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
169 return (t =
zero(t));
173 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
180 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
187 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
194 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
201 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
208 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
215 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
222 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
229 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
232 return zero(std::forward<T>(t));
236 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
243 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
250 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
257 template<class I, class T, std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
273 class I, I N,
class T,
274 std::enable_if_t<(N*N > 1
282 class I, I N, I D,
class T,
283 std::enable_if_t<(N*N > 1
285 && IsFractionOperand<T>::value),
int> = 0>
286 constexpr
auto&
operator*=(T& t, FractionConstant<I, N, D>)
292 class I, I N, I D,
class T,
293 std::enable_if_t<(N != 0
295 && IsFractionOperand<T>::value),
int> = 0>
296 constexpr
auto operator+(FractionConstant<I, N, D>, T&& t)
302 class I, I N, I D,
class T,
303 std::enable_if_t<(N != 0
305 && IsFractionOperand<T>::value),
int> = 0>
306 constexpr
auto&
operator+=(T& t, FractionConstant<I, N, D>)
312 class I, I N, I D,
class T,
313 std::enable_if_t<(N != 0
315 && IsFractionOperand<T>::value),
int> = 0>
316 constexpr
auto operator-(FractionConstant<I, N, D>, T&& t)
322 class I, I N, I D,
class T,
323 std::enable_if_t<(N != 0
325 && IsFractionOperand<T>::value),
int> = 0>
326 constexpr
auto operator/(FractionConstant<I, N, D>, T&& t)
328 using FType = FieldPromotionType<T, I>;
329 return (FType)N / (FType)t;
333 class I, I N, I D,
class T,
334 std::enable_if_t<(N != 0
336 && IsFractionOperand<T>::value),
int> = 0>
337 constexpr
auto&
operator/=(T& t, FractionConstant<I, N, D>)
343 class I, I N, I D,
class T,
344 std::enable_if_t<(D == 1
345 && IsFractionOperand<T>::value),
int> = 0>
346 constexpr
bool operator==(FractionConstant<I, N, D>, T&& t)
352 class I, I N, I D,
class T,
353 std::enable_if_t<(D == 1
354 && IsFractionOperand<T>::value),
int> = 0>
355 constexpr
bool operator!=(FractionConstant<I, N, D>, T&& t)
361 class I, I N, I D,
class T,
362 std::enable_if_t<(D == 1
363 && IsFractionOperand<T>::value),
int> = 0>
364 constexpr
bool operator<=(FractionConstant<I, N, D>, T&& t)
370 class I, I N, I D,
class T,
371 std::enable_if_t<(D == 1
372 && IsFractionOperand<T>::value),
int> = 0>
373 constexpr
bool operator<(FractionConstant<I, N, D>, T&& t)
379 class I, I N, I D,
class T,
380 std::enable_if_t<(D == 1
381 && IsFractionOperand<T>::value),
int> = 0>
382 constexpr
bool operator>=(FractionConstant<I, N, D>, T&& t)
388 class I, I N, I D,
class T,
389 std::enable_if_t<(D == 1
390 && IsFractionOperand<T>::value),
int> = 0>
391 constexpr
bool operator>(FractionConstant<I, N, D>, T&& t)
406 class I, I N, I D,
class T,
407 std::enable_if_t<(N != 0
409 && IsFractionOperand<T>::value),
int> = 0>
410 constexpr
auto operator*(FractionConstant<I, N, D>, T&& t)
412 using FType = FieldPromotionType<T, I>;
413 return (FType)N/(FType)D*t;
417 class I, I N, I D,
class T,
418 std::enable_if_t<(N != 0
420 && IsFractionOperand<T>::value),
int> = 0>
421 constexpr
auto&
operator*=(T& t, FractionConstant<I, N, D>)
423 using FType = FieldPromotionType<T, I>;
424 return t *= (FType)N/(FType)D;
428 class I, I N, I D,
class T,
429 std::enable_if_t<(N != 0
431 && IsFractionOperand<T>::value),
int> = 0>
432 constexpr
auto operator+(FractionConstant<I, N, D>, T&& t)
434 using FType = FieldPromotionType<T, I>;
435 return (FType)N/(FType)D+t;
439 class I, I N, I D,
class T,
440 std::enable_if_t<(N != 0
442 && IsFractionOperand<T>::value),
int> = 0>
443 constexpr
auto&
operator+=(T& t, FractionConstant<I, N, D>)
445 using FType = FieldPromotionType<T, I>;
446 return t += (FType)N/(FType)D;
450 class I, I N, I D,
class T,
451 std::enable_if_t<(N != 0
453 && IsFractionOperand<T>::value),
int> = 0>
454 constexpr
auto operator-(FractionConstant<I, N, D>, T&& t)
456 using FType = FieldPromotionType<T, I>;
457 return (FType)N/(FType)D-t;
461 class I, I N, I D,
class T,
462 std::enable_if_t<(N != 0
464 && IsFractionOperand<T>::value),
int> = 0>
465 constexpr
auto&
operator-(T& t, FractionConstant<I, N, D>)
467 using FType = FieldPromotionType<T, I>;
468 return t -= (FType)N/(FType)D;
472 class I, I N, I D,
class T,
473 std::enable_if_t<(N != 0
475 && IsFractionOperand<T>::value),
int> = 0>
476 constexpr
auto operator/(FractionConstant<I, N, D>, T&& t)
478 using FType = FieldPromotionType<T, I>;
479 return (FType)N / (FType)D / (FType)t;
483 class I, I N, I D,
class T,
484 std::enable_if_t<(N != 0
486 && IsFractionOperand<T>::value),
int> = 0>
487 constexpr
auto&
operator/(T& t, FractionConstant<I, N, D>)
489 using FType = FieldPromotionType<T, I>;
490 return t /= (FType)N / (FType)D;
494 class I, I N, I D,
class T,
495 std::enable_if_t<(D != 1
496 && IsFractionOperand<T>::value),
int> = 0>
497 constexpr
bool operator==(FractionConstant<I, N, D>, T&& t)
503 class I, I N, I D,
class T,
504 std::enable_if_t<(D != 1
505 && IsFractionOperand<T>::value),
int> = 0>
506 constexpr
bool operator!=(FractionConstant<I, N, D>, T&& t)
512 class I, I N, I D,
class T,
513 std::enable_if_t<(D != 1
514 && IsFractionOperand<T>::value),
int> = 0>
515 constexpr
bool operator<=(FractionConstant<I, N, D>, T&& t)
521 class I, I N, I D,
class T,
522 std::enable_if_t<(D != 1
523 && IsFractionOperand<T>::value),
int> = 0>
524 constexpr
bool operator<(FractionConstant<I, N, D>, T&& t)
530 class I, I N, I D,
class T,
531 std::enable_if_t<(D != 1
532 && IsFractionOperand<T>::value),
int> = 0>
533 constexpr
bool operator>=(FractionConstant<I, N, D>, T&& t)
539 class I, I N, I D,
class T,
540 std::enable_if_t<(D != 1
541 && IsFractionOperand<T>::value),
int> = 0>
542 constexpr
bool operator>(FractionConstant<I, N, D>, T&& t)
548 class I, I N, I D,
class T,
549 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
550 constexpr
auto min(FractionConstant<I, N, D> f, T&& t)
552 using FType = FieldPromotionType<T, I>;
553 return f <= t ? (FType)f : (FType)t;
557 class I, I N, I D,
class T,
558 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
559 constexpr
auto max(FractionConstant<I, N, D> f, T&& t)
561 using FType = FieldPromotionType<T, I>;
562 return f >= t ? (FType)f : (FType)t;
574 class I, I N, I D,
class T,
575 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
583 class I, I N, I D,
class T,
584 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
592 class I, I N, I D,
class T,
593 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
601 class I, I N, I D,
class T,
602 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
610 class I, I N, I D,
class T,
611 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
619 class I, I N, I D,
class T,
620 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
628 class I, I N, I D,
class T,
629 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
637 class I, I N, I D,
class T,
638 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
646 class I, I N, I D,
class T,
647 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
655 class I, I N, I D,
class T,
656 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
664 class I, I N, I D,
class T,
665 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
673 class I, I N, I D,
class T,
674 std::enable_if_t<IsFractionOperand<T>::value,
int> = 0>
constexpr auto & operator*=(T &t, FractionConstant< I, 0, 1 >)
t*=0
Definition: constantoperations.hh:167
constexpr auto operator/(T &&t, FractionConstant< I, N, D > f)
t / fraction -> (1/fraction) * t.
Definition: constantoperations.hh:585
constexpr auto operator+(T &&t, FractionConstant< I, N, D > f)
t + fraction -> fraction + t.
Definition: constantoperations.hh:594
constexpr auto & operator+=(T &t, FractionConstant< I, 0, 1 >)
t+=0.
Definition: constantoperations.hh:209
constexpr auto operator-(T &&t, FractionConstant< I, N, D > f)
t - fraction -> -fraction + t.
Definition: constantoperations.hh:603
constexpr auto & operator-=(T &t, FractionConstant< I, 0, 1 >)
t-=0.
Definition: constantoperations.hh:223
constexpr std::size_t WeightV
Provide an overridable weight for expressions which defaults to their depth.
Definition: weight.hh:14
constexpr auto one(T &&t)
Use the one fraction as canonical zero element for scalars.
Definition: constantoperations.hh:88
BoolConstant<(IsScalar< T >::value &&!(Exclusive &&IsFractionConstant< T >::value) &&!IsIntegralConstant< T >::value &&!IsExpression< T >::value)> IsFractionOperand
Allow scalars to mate with FractionConstants, but do not interfere with std::integral_constant and ex...
Definition: constantoperations.hh:75
constexpr auto zero(T &&t)
Use the zero fraction as canonical zero element for scalars.
Definition: constantoperations.hh:80
auto toString(Sequence< T, I0 >)
Generate a compact string representation as a comma separated list of the values, without spaces.
Definition: tostring.hh:28
constexpr bool isConstant(Sequence< T, T0, Ts... >)
Definition: compare.hh:285
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
Default expression traits definition is a recursion in order to ease disambiguation.
Definition: expressiontraits.hh:54
A class mainting the sign of an expression during operations.
Definition: sign.hh:30
FalseType by default.
Definition: types.hh:313
TrueType if I is an integral type.
Definition: typetraits.hh:29
std::true_type if F is an "elementary" scalar.
Definition: typetraits.hh:35
A class implementing compile-time constant fractions of integers.
Definition: fractionconstant.hh:27
Definition: fractionconstant.hh:75
A named constant wraps a constant of the given type T tagging it with the given character sequence.
Definition: namedconstant.hh:21