diff --git a/src/language/modules/BinaryOperatorRegisterForVh.cpp b/src/language/modules/BinaryOperatorRegisterForVh.cpp index 8d1dc7f354194adb266aeff16d412e755ffd1688..90f0c295a77578a59a7eae42706333d37d9084cc 100644 --- a/src/language/modules/BinaryOperatorRegisterForVh.cpp +++ b/src/language/modules/BinaryOperatorRegisterForVh.cpp @@ -216,6 +216,22 @@ BinaryOperatorRegisterForVh::_register_multiply() std::make_shared<BinaryOperatorProcessorBuilder<language::multiply_op, std::shared_ptr<const IDiscreteFunction>, double, std::shared_ptr<const IDiscreteFunction>>>()); + repository.addBinaryOperator<language::multiply_op>( + std::make_shared<BinaryOperatorProcessorBuilder<language::multiply_op, std::shared_ptr<const IDiscreteFunction>, + std::shared_ptr<const IDiscreteFunction>, bool>>()); + + repository.addBinaryOperator<language::multiply_op>( + std::make_shared<BinaryOperatorProcessorBuilder<language::multiply_op, std::shared_ptr<const IDiscreteFunction>, + std::shared_ptr<const IDiscreteFunction>, int64_t>>()); + + repository.addBinaryOperator<language::multiply_op>( + std::make_shared<BinaryOperatorProcessorBuilder<language::multiply_op, std::shared_ptr<const IDiscreteFunction>, + std::shared_ptr<const IDiscreteFunction>, uint64_t>>()); + + repository.addBinaryOperator<language::multiply_op>( + std::make_shared<BinaryOperatorProcessorBuilder<language::multiply_op, std::shared_ptr<const IDiscreteFunction>, + std::shared_ptr<const IDiscreteFunction>, double>>()); + repository.addBinaryOperator<language::multiply_op>( std::make_shared<BinaryOperatorProcessorBuilder<language::multiply_op, std::shared_ptr<const IDiscreteFunction>, TinyMatrix<1>, std::shared_ptr<const IDiscreteFunction>>>()); diff --git a/src/language/utils/EmbeddedIDiscreteFunctionOperators.cpp b/src/language/utils/EmbeddedIDiscreteFunctionOperators.cpp index 815436bb0d90d8ded91b66ee4e5f3d0e3345c558..0e5a789ce31e645b8ccdde6c48009eca4275d76b 100644 --- a/src/language/utils/EmbeddedIDiscreteFunctionOperators.cpp +++ b/src/language/utils/EmbeddedIDiscreteFunctionOperators.cpp @@ -702,7 +702,7 @@ template <typename BinOperatorT, typename DataType, typename DiscreteFunctionT> std::shared_ptr<const IDiscreteFunction> applyBinaryOperationWithRightConstant(const DiscreteFunctionT& f, const DataType& a) { - Assert(f.descriptor().type() != DiscreteFunctionType::P0); + Assert(f.descriptor().type() == DiscreteFunctionType::P0); using lhs_data_type = std::decay_t<typename DiscreteFunctionT::data_type>; using rhs_data_type = std::decay_t<DataType>; @@ -711,7 +711,16 @@ applyBinaryOperationWithRightConstant(const DiscreteFunctionT& f, const DataType if constexpr (is_tiny_matrix_v<lhs_data_type> and is_tiny_matrix_v<rhs_data_type>) { return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(f, a))>(BinOp<BinOperatorT>{}.eval(f, a)); } else if constexpr (std::is_same_v<lhs_data_type, double> and - (is_tiny_matrix_v<rhs_data_type> or is_tiny_vector_v<rhs_data_type>)) { + (is_tiny_matrix_v<rhs_data_type> or is_tiny_vector_v<rhs_data_type> or + std::is_arithmetic_v<rhs_data_type>)) { + return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(f, a))>(BinOp<BinOperatorT>{}.eval(f, a)); + } else { + throw NormalError(invalid_operands(f, a)); + } + } else if constexpr (std::is_same_v<language::plus_op, BinOperatorT> or + std::is_same_v<language::minus_op, BinOperatorT>) { + if constexpr ((std::is_same_v<lhs_data_type, rhs_data_type>) or + (std::is_arithmetic_v<lhs_data_type> and std::is_arithmetic_v<rhs_data_type>)) { return std::make_shared<decltype(BinOp<BinOperatorT>{}.eval(f, a))>(BinOp<BinOperatorT>{}.eval(f, a)); } else { throw NormalError(invalid_operands(f, a)); @@ -989,6 +998,12 @@ operator*(const double& a, const std::shared_ptr<const IDiscreteFunction>& f) return applyBinaryOperationWithLeftConstant<language::multiply_op>(a, f); } +std::shared_ptr<const IDiscreteFunction> +operator*(const std::shared_ptr<const IDiscreteFunction>& f, const double& a) +{ + return applyBinaryOperationWithRightConstant<language::multiply_op>(f, a); +} + std::shared_ptr<const IDiscreteFunction> operator*(const TinyMatrix<1>& A, const std::shared_ptr<const IDiscreteFunction>& B) {