clickhouse-docs icon indicating copy to clipboard operation
clickhouse-docs copied to clipboard

round and ceil - unexpected result with negative N argument

Open oyediyildiz opened this issue 1 year ago • 4 comments

Describe the unexpected behaviour round function doesn't work as expected when I call round(255, -1). Similarly, ceil(255, -1) also returns unexpected result.

How to reproduce

  • Which ClickHouse server version to use
SELECT version()

Query id: fdc9acb0-2dbd-4a21-adaa-816632a5e2e6

   ┌─version()─┐
1. │ 24.3.5.46 │
   └───────────┘
  • Which interface to use, if matters I use clickhouse-client binary in clickhouse/clickhouse-server:24.3.5 docker image

  • Queries to run that lead to unexpected result

I expect both round(255, -1) and ceil(255, -1) to return 260

SELECT round(255, -1)

Query id: 5314d9e8-5307-41e7-bb60-4d9a5f9920cb

   ┌─round(255, -1)─┐
1. │              4 │
   └────────────────┘

---

SELECT ceil(255, -1)

Query id: 9e190c3c-ff3b-4237-a7b5-d4853ab4ab84

   ┌─ceil(255, -1)─┐
1. │             0 │
   └───────────────┘

This works as expected:

SELECT round(256, -1)

Query id: 6e5d5dd6-a2d5-4027-9d02-414ef27c4bc7

   ┌─round(256, -1)─┐
1. │            260 │
   └────────────────┘

Expected behavior The only problem I encountered so far is the value 255 when called with negative N arguments.

Additional context floor(255, -1) works as expected.

oyediyildiz avatar Sep 19 '24 12:09 oyediyildiz