1#ifndef TATAMI_ARITHMETIC_UTILS_HPP
2#define TATAMI_ARITHMETIC_UTILS_HPP
41template<ArithmeticOperation op_,
bool right_,
typename Value_,
typename Scalar_>
42auto delayed_arithmetic(
const Value_ val,
const Scalar_ scalar) {
44 if constexpr(right_) {
52 if constexpr(right_) {
59 if constexpr(op_ == ArithmeticOperation::ADD) {
62 }
else if constexpr(op_ == ArithmeticOperation::MULTIPLY) {
65 }
else if constexpr(op_ == ArithmeticOperation::SUBTRACT) {
68 }
else if constexpr(op_ == ArithmeticOperation::DIVIDE) {
76 }
else if constexpr(op_ == ArithmeticOperation::POWER) {
77 return std::pow(left, right);
79 }
else if constexpr(op_ == ArithmeticOperation::MODULO) {
82 const auto quo = left / right;
83 if constexpr(std::numeric_limits<I<
decltype(quo)> >::is_integer) {
84 auto rem = left % right;
85 return rem + (quo < 0 && rem != 0 ? right : 0);
87 auto rem = std::fmod(left, right);
88 return rem + (quo < 0 && rem != 0 ? right : 0);
91 }
else if constexpr(op_ == ArithmeticOperation::INTEGER_DIVIDE) {
92 const auto out = left / right;
93 if constexpr(std::numeric_limits<I<
decltype(out)> >::is_integer) {
96 return out - (out < 0 ? (left % right != 0) : 0);
98 return std::floor(out);
108template<ArithmeticOperation op_,
bool right_,
typename Value_,
typename Scalar_>
109constexpr bool has_unsafe_divide_by_zero() {
110 typedef I<decltype(delayed_arithmetic<op_, right_>(std::declval<Value_>(), std::declval<Scalar_>()))> Product;
111 if constexpr(std::numeric_limits<Product>::is_iec559) {
119 if constexpr(op_ == ArithmeticOperation::DIVIDE) {
122 if constexpr(op_ == ArithmeticOperation::MODULO) {
125 if constexpr(op_ == ArithmeticOperation::INTEGER_DIVIDE) {
Copy data from one buffer to another.
Flexible representations for matrix data.
Definition Extractor.hpp:15
ArithmeticOperation
Definition arithmetic_utils.hpp:26