apache / apache/gluten

[VL] result mismatch found in round

Open
#6,827 12 comments 0 reactions 0 assignees View on GitHub
bug triage
Dominant language
Scala
Stars
1.6k
Forks
657
Avg merge
2d 14h
Merged PRs (30d)
80

Description

### Backend

VL (Velox)

### Bug description

SQL:
```
SELECT round(cast(0.5549999999999999 as double), 2);
```
Gluten returns 0.56, but vanilla spark returns 0.55.
The reason of this mismatch is that the result of std::nextafter(0.5549999999999999) is 0.55500000000000005, which make std::round return 56.
Besides, the following SQL also can't produce the result result in gluten:
```
SELECT round(cast(0.19324999999999998 as double), 2);
```
Gluten returns 0.1933, spark returns 0.1922.

I have tried the following modification in round:
```
return static_cast(std::round(std::nextafter(static_cast(number), kInf) * factor) / factor);
```
I can fix the first example, but the second example still has a mismatch.
The modification will cause other mismatch:
```
SELECT round(cast(0.575 as double), 2);
```
Before the modification, gluten returns the right result, which is 0.58. After the modification, glutens returns 0.57.

### Spark version

3.0

### Spark configurations

_No response_

### System information

_No response_

### Relevant logs

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.