pingcap / pingcap/tidb

Wrong Execution Result in Float Comparison

Open
#58,732 2 comments 0 reactions 0 assignees View on GitHub
affects-8.5 severity/moderate sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

```sql
DROP TABLE IF EXISTS t0;
CREATE TABLE IF NOT EXISTS t0(c0 DOUBLE) ;
INSERT INTO t0(c0) VALUES(0.48419657580314157);
SELECT (NOT (CAST(t0.c0 AS DOUBLE) <= (CAST(t0.c0 AS FLOAT)))) from t0;
```

### 2. What did you expect to see? (Required)

see the following case:

### 3. What did you see instead (Required)

```sql
// MySQL 8.4.1
MySQL [test]> SELECT (NOT (CAST(t0.c0 AS DOUBLE) <= (CAST(t0.c0 AS FLOAT)))) from t0;
+---------------------------------------------------------+
| (NOT (CAST(t0.c0 AS DOUBLE) <= (CAST(t0.c0 AS FLOAT)))) |
+---------------------------------------------------------+
| 1 |
+---------------------------------------------------------+
1 row in set (0.00 sec)

// TiDB
mysql> SELECT (NOT (CAST(t0.c0 AS DOUBLE) <= (CAST(t0.c0 AS FLOAT)))) from t0;
+---------------------------------------------------------+
| (NOT (CAST(t0.c0 AS DOUBLE) <= (CAST(t0.c0 AS FLOAT)))) |
+---------------------------------------------------------+
| 0 |
+---------------------------------------------------------+
1 row in set (0.04 sec)
```

### 4. What is your TiDB version? (Required)

TiDB v8.5.0

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.