```
SELECT toDecimal32(12345.6789, 0) AS x, round(x, round(round(9223372036854775807), -1))



2020.08.04 20:38:52.457074 [ 245722 ] {} <Trace> BaseDaemon: Received signal 8
2020.08.04 20:38:52.457409 [ 245778 ] {} <Fatal> BaseDaemon: ########################################
2020.08.04 20:38:52.457986 [ 245778 ] {} <Fatal> BaseDaemon: (version 20.7.1.1, build id: 21B0DCC47427FD8E) (from thread 245763) (query_id: 5f16b804-4183-4c2a-b1bd-28b2b135311d) Received signal Floating point exception (8)
2020.08.04 20:38:52.458117 [ 245778 ] {} <Fatal> BaseDaemon: Integer divide by zero.
2020.08.04 20:38:52.458306 [ 245778 ] {} <Fatal> BaseDaemon: Stack trace: 0x7f26ad712f4f 0x7f26ad712cdf 0x7f26ad712c10 0x7f26ad6eb1e9 0x7f26ad6eacb4 0x7f26ad6ea0e3 0x7f26acfe9581 0x7f26acfe8a8f 0x7f26ad8186f3 0x7f26ad8182ce 0x7f26ad818670 0x7f26ad8197fd 0x7f26a60b7b26 0x7f26a60bb3a7 0x7f26a60bacd3 0x7f26a5cd20c2 0x7f26a5cdd986 0x7f26a5cd54d6 0x7f26a5cd24c7 0x7f26a60da08d 0x7f26a60e7726 0x7f26a60da09f 0x7f26a60d122d 0x7f26a60d43db 0x7f26a60d7044 0x7f26a6517a8b 0x7f26a6514e2c 0x7f26a6511a45
2020.08.04 20:38:52.462314 [ 245778 ] {} <Fatal> BaseDaemon: 4. /home/akuzm/ch4/ch/src/Functions/FunctionsRound.h:127: DB::DecimalRoundingImpl<DB::Decimal<int>, (DB::RoundingMode)8, (DB::TieBreakingMode)0>::apply(DB::DecimalPaddedPODArray<DB::Decimal<int> > const&, DB::DecimalPaddedPODArray<DB::Decimal<int> >&, long) @ 0x2fd5f4f in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.466302 [ 245778 ] {} <Fatal> BaseDaemon: 5. /home/akuzm/ch4/ch/src/Functions/FunctionsRound.h:483: DB::Dispatcher<DB::Decimal<int>, (DB::RoundingMode)8, (DB::TieBreakingMode)0>::apply(DB::Block&, DB::ColumnDecimal<DB::Decimal<int> > const*, long, unsigned long) @ 0x2fd5cdf in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.470338 [ 245778 ] {} <Fatal> BaseDaemon: 6. /home/akuzm/ch4/ch/src/Functions/FunctionsRound.h:495: DB::Dispatcher<DB::Decimal<int>, (DB::RoundingMode)8, (DB::TieBreakingMode)0>::apply(DB::Block&, DB::IColumn const*, long, unsigned long) @ 0x2fd5c10 in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.471807 [ 245778 ] {} <Fatal> BaseDaemon: 7. /home/akuzm/ch4/ch/src/Functions/FunctionsRound.h:568: bool DB::FunctionRounding<DB::NameRound, (DB::RoundingMode)8, (DB::TieBreakingMode)0>::executeImpl(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long) const::'lambda'(auto const&)::operator()<DB::TypePair<DB::DataTypeDecimal<DB::Decimal<int> >, void> >(auto const&) const @ 0x2fae1e9 in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.473263 [ 245778 ] {} <Fatal> BaseDaemon: 8. /home/akuzm/ch4/ch/src/Core/callOnTypeIndex.h:177: bool DB::callOnIndexAndDataType<void, DB::FunctionRounding<DB::NameRound, (DB::RoundingMode)8, (DB::TieBreakingMode)0>::executeImpl(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long) const::'lambda'(DB::NameRound const&)&>(DB::TypeIndex, (DB::RoundingMode)8&&) @ 0x2fadcb4 in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.474613 [ 245778 ] {} <Fatal> BaseDaemon: 9. /home/akuzm/ch4/ch/src/Functions/FunctionsRound.h:573: DB::FunctionRounding<DB::NameRound, (DB::RoundingMode)8, (DB::TieBreakingMode)0>::executeImpl(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long) const @ 0x2fad0e3 in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.475098 [ 245778 ] {} <Fatal> BaseDaemon: 10. /home/akuzm/ch4/ch/src/Functions/IFunctionImpl.h:202: DB::IFunction::executeImplDryRun(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long) const @ 0x28ac581 in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.475461 [ 245778 ] {} <Fatal> BaseDaemon: 11. /home/akuzm/ch4/ch/src/Functions/IFunctionAdaptors.h:156: DB::DefaultExecutable::executeDryRun(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long) @ 0x28aba8f in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.476790 [ 245778 ] {} <Fatal> BaseDaemon: 12. /home/akuzm/ch4/ch/src/Functions/IFunction.cpp:323: DB::ExecutableFunctionAdaptor::executeWithoutLowCardinalityColumns(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0x30db6f3 in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.478148 [ 245778 ] {} <Fatal> BaseDaemon: 13. /home/akuzm/ch4/ch/src/Functions/IFunction.cpp:266: DB::ExecutableFunctionAdaptor::defaultImplementationForConstantArguments(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0x30db2ce in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.479580 [ 245778 ] {} <Fatal> BaseDaemon: 14. /home/akuzm/ch4/ch/src/Functions/IFunction.cpp:316: DB::ExecutableFunctionAdaptor::executeWithoutLowCardinalityColumns(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0x30db670 in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.481063 [ 245778 ] {} <Fatal> BaseDaemon: 15. /home/akuzm/ch4/ch/src/Functions/IFunction.cpp:486: DB::ExecutableFunctionAdaptor::execute(DB::Block&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> > const&, unsigned long, unsigned long, bool) @ 0x30dc7fd in /home/akuzm/ch4/build-clang10/src/Functions/libclickhouse_functionsd.so
2020.08.04 20:38:52.481973 [ 245778 ] {} <Fatal> BaseDaemon: 16. /home/akuzm/ch4/ch/src/Interpreters/ExpressionActions.cpp:206: DB::ExpressionAction::prepare(DB::Block&, DB::Settings const&, std::__1::unordered_set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&) @ 0x11d8b26 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.482914 [ 245778 ] {} <Fatal> BaseDaemon: 17. /home/akuzm/ch4/ch/src/Interpreters/ExpressionActions.cpp:625: DB::ExpressionActions::addImpl(DB::ExpressionAction, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&) @ 0x11dc3a7 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.483817 [ 245778 ] {} <Fatal> BaseDaemon: 18. /home/akuzm/ch4/ch/src/Interpreters/ExpressionActions.cpp:586: DB::ExpressionActions::add(DB::ExpressionAction const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&) @ 0x11dbcd3 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.484031 [ 245778 ] {} <Fatal> BaseDaemon: 19. /home/akuzm/ch4/ch/src/Interpreters/ActionsVisitor.cpp:441: DB::ScopeStack::addAction(DB::ExpressionAction const&) @ 0xdf30c2 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.484452 [ 245778 ] {} <Fatal> BaseDaemon: 20. /home/akuzm/ch4/ch/src/Interpreters/ActionsVisitor.h:117: DB::ActionsMatcher::Data::addAction(DB::ExpressionAction const&) @ 0xdfe986 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.484744 [ 245778 ] {} <Fatal> BaseDaemon: 21. /home/akuzm/ch4/ch/src/Interpreters/ActionsVisitor.cpp:781: DB::ActionsMatcher::visit(DB::ASTFunction const&, std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0xdf64d6 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.484942 [ 245778 ] {} <Fatal> BaseDaemon: 22. /home/akuzm/ch4/ch/src/Interpreters/ActionsVisitor.cpp:498: DB::ActionsMatcher::visit(std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0xdf34c7 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.486073 [ 245778 ] {} <Fatal> BaseDaemon: 23. /home/akuzm/ch4/ch/src/Interpreters/InDepthNodeVisitor.h:32: DB::InDepthNodeVisitor<DB::ActionsMatcher, true, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0x11fb08d in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.489511 [ 245778 ] {} <Fatal> BaseDaemon: 24. /home/akuzm/ch4/ch/src/Interpreters/InDepthNodeVisitor.h:45: DB::InDepthNodeVisitor<DB::ActionsMatcher, true, std::__1::shared_ptr<DB::IAST> const>::visitChildren(std::__1::shared_ptr<DB::IAST> const&) @ 0x1208726 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.491265 [ 245778 ] {} <Fatal> BaseDaemon: 25. /home/akuzm/ch4/ch/src/Interpreters/InDepthNodeVisitor.h:35: DB::InDepthNodeVisitor<DB::ActionsMatcher, true, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0x11fb09f in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.492635 [ 245778 ] {} <Fatal> BaseDaemon: 26. /home/akuzm/ch4/ch/src/Interpreters/ExpressionAnalyzer.cpp:396: DB::ExpressionAnalyzer::getRootActions(std::__1::shared_ptr<DB::IAST> const&, bool, std::__1::shared_ptr<DB::ExpressionActions>&, bool) @ 0x11f222d in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.493941 [ 245778 ] {} <Fatal> BaseDaemon: 27. /home/akuzm/ch4/ch/src/Interpreters/ExpressionAnalyzer.cpp:818: DB::SelectQueryExpressionAnalyzer::appendSelect(DB::ExpressionActionsChain&, bool) @ 0x11f53db in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.495140 [ 245778 ] {} <Fatal> BaseDaemon: 28. /home/akuzm/ch4/ch/src/Interpreters/ExpressionAnalyzer.cpp:1174: DB::ExpressionAnalysisResult::ExpressionAnalysisResult(DB::SelectQueryExpressionAnalyzer&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, bool, bool, bool, std::__1::shared_ptr<DB::FilterInfo> const&, DB::Block const&) @ 0x11f8044 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.497180 [ 245778 ] {} <Fatal> BaseDaemon: 29. /home/akuzm/ch4/ch/src/Interpreters/InterpreterSelectQuery.cpp:505: DB::InterpreterSelectQuery::getSampleBlockImpl() @ 0x1638a8b in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.499254 [ 245778 ] {} <Fatal> BaseDaemon: 30. /home/akuzm/ch4/ch/src/Interpreters/InterpreterSelectQuery.cpp:402: DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, std::__1::shared_ptr<DB::IStorage> const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&)::$_2::operator()(bool) const @ 0x1635e2c in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
2020.08.04 20:38:52.501342 [ 245778 ] {} <Fatal> BaseDaemon: 31. /home/akuzm/ch4/ch/src/Interpreters/InterpreterSelectQuery.cpp:405: DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, std::__1::shared_ptr<DB::IStorage> const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&) @ 0x1632a45 in /home/akuzm/ch4/build-clang10/src/libclickhouse_interpretersd.so
```
{
public:
    using ScalarType = T;
    using VectorType = T;
    static const size_t data_count = 1;
    static VectorType load(const ScalarType * in) { return *in; }
    static VectorType load1(const ScalarType in) { return in; }
    static VectorType store(ScalarType * out, ScalarType val) { return *out = val;}
    static VectorType multiply(VectorType val, VectorType scale) { return val * scale; }
    static VectorType divide(VectorType val, VectorType scale) { return val / scale; }
    template <RoundingMode mode> static VectorType apply(VectorType val) { return roundWithMode(val, mode); }
    static VectorType prepare(size_t scale)
    {
        return load1(scale);
    }
};
#endif
/** Implementation of low-level round-off functions for floating-point values.
  */
template <typename T, RoundingMode rounding_mode, ScaleMode scale_mode>
class FloatRoundingComputation : public BaseFloatRoundingComputation<T>
{
    using Base = BaseFloatRoundingComputation<T>;
public:
    static inline void compute(const T * __restrict in, const typename Base::VectorType & scale, T * __restrict out)