trunc(x) on a column turns -0.0 into 0.0
Maintainers usually reply within 1 day
@1fanwang is already working on this.
Since Sep 25, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
Research direction
Look for the trunc function implementation in the DataFusion codebase, likely in a file like expr/scalar.rs or expr/builtin.rs. The bug is in the columnar path where x == 0_f64 is used. Replace that condition with a check that preserves the sign, perhaps using x.trunc() directly. Write a test in the corresponding test module to verify trunc(-0.0) returns -0.0 for a column. Run the existing SQL function tests to ensure no regressions.
Written by the indexing model from the issue text.
Description
trunc(x) drops the sign of -0.0, but only when it runs on a column. On a scalar, and for trunc(x, 0), the sign is kept.
SELECT trunc(column1), trunc(column1, 0) FROM (VALUES (CAST(-0.0 AS DOUBLE)));
-- got: 0.0, -0.0
-- expected: -0.0, -0.0
The column code path returns 0.0 for either zero:
if x == 0_f64 { 0_f64 } else { x.trunc() }
-0.0 == 0.0 is true, so -0.0 becomes 0.0. f64::trunc already keeps the sign, so plain x.trunc() would be enough.
Seen through Lance (pylance 12.0.0): trunc(x, 0) on a -0.0 column returns -0.0. This line is the same on main and in 55.1.0. I found no existing issue or PR for it.
- Dominant language
- Rust
- Stars
- 9.4k
- Forks
- 2.5k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 383
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/datafusion
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
apache/datafusion#25960 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
apache/datafusion#25913 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
apache/datafusion#25266 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
apache/datafusion#25213 · 1 comment ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
apache/datafusion#25168 · 1 comment ·
Maintainers usually reply within 1 day
All issues in apache/datafusion
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day