Skip to content

power(decimal, integer) overflow for moderate exponents #22480

@neilconway

Description

@neilconway

Describe the bug

power(decimal, integer) computes base ^ exp on the unscaled integer representation and then normalizes, which leads to overflows before normalization for reasonably sized inputs.

To Reproduce

SELECT power(2.5::decimal(20, 4), 10);
-- Arrow error: Arithmetic overflow: Cannot raise base 25000 to exp 10

Expected behavior

DuckDB:

memory D SELECT power(2.5::decimal(20, 4), 10);
┌────────────────────────────────────────┐
│ power(CAST(2.5 AS DECIMAL(20, 4)), 10) │
│                 double                 │
├────────────────────────────────────────┤
│                        9536.7431640625 │
└────────────────────────────────────────┘

Postgres returns the same.

Additional context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions