v.1.1.54292New Feature

Added trunc function and improved rounding performance and logic

Added the trunc function. Improved performance of the rounding functions (round, floor, ceil, roundToExp2) and corrected the logic of how they work. Changed the logic of the roundToExp2 function for fractions and negative numbers.
Introduced the trunc function and enhanced the performance and accuracy of rounding functions including round, floor, ceil, and roundToExp2, with updated logic especially for fractions and negative numbers.

Why it matters

The addition of the trunc function and improvements to rounding functions address the need for more efficient and logically correct numeric rounding operations in ClickHouse. This enables users to perform truncation and rounding with better performance and more consistent results, particularly in edge cases like fractional values and negatives, thereby improving data processing accuracy and speed.

How to use it

Use the trunc function to truncate decimal numbers to their integer part or specified precision. The rounding functions round, floor, ceil, and roundToExp2 can be used as before but now perform faster and with corrected logic. For example:
SELECT trunc(12.345) -- returns 12
SELECT round(-3.7) -- applies corrected rounding logic
SELECT roundToExp2(10.75, -1) -- rounding adjusted for fractions/negative inputs