Skip to content

[VL] result mismatch found in round #6827

@jiangjiangtian

Description

@jiangjiangtian

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<TNum>(std::round(std::nextafter(static_cast<long double>(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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions