Skip to content

round and ceil - unexpected result with negative N argument #3298

Open
@oyediyildiz

Description

@oyediyildiz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions