Bug #111142 | Float calculate result changes when adding brakets | ||
---|---|---|---|
Submitted: | 24 May 2023 15:03 | Modified: | 25 May 2023 14:21 |
Reporter: | Siyang Weng | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 8.0.18 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | bug;float;calculation |
[24 May 2023 15:03]
Siyang Weng
[25 May 2023 12:31]
MySQL Verification Team
Hi MR. Weng, Thank you for your bug report. However, it is not a bug. First of all, you are using an ancient release of MySQL. Current release is 8.0.33. But, the crux of your problem is that your data domain is DECIMAL, while you are using the constants from the FLOAT / DOUBLE domain. Try using just 0.001 ....... Also, leave the blanks between the numbers and operations in your arithmetics ........ Not a bug.
[25 May 2023 13:30]
Siyang Weng
Thanks for your reply and advice! So is it expected that adding brakets to FLOAT / DOUBLE expression may change its result? If so, I will avoid using float and double in the future.
[25 May 2023 13:37]
MySQL Verification Team
Hi, You may use FLOAT and DOUBLE as much as you wish, but don't mix them with DECIMAL. Those are two totally different data types. Also, write expressions differently. Instead of: a=0.001+1e-1-1e-1; do the following: a=0.001 + 1e-1 - 1e-1; // when 'a' is FLOAT or DOUBLE and a=0.001 + 0.1 - 0.1; // when 'a' is DECIMAL Simply, DECIMAL do not use scientific notation. This is all described in our Reference Manual.
[25 May 2023 14:21]
Siyang Weng
Got it. Thanks a lot!
[25 May 2023 14:25]
MySQL Verification Team
You are truly welcome .....