| |

VerySource

 Forgot password?
 Register
Search
Author: 无风无尘

The problem of using double type variables in if. . .

[Copy link]

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-7 16:00:01
| Show all posts
==There is still processing for float, you can do an experiment
Change the value of double ff=1.0;
Change to
double ff=1.0000001;
with
double ff=1.00000001;

The other code remains unchanged. Run the program. The result of the previous modification is Cancel, and the latter is OK.
So == is only accurate to 7 digits after the decimal point, and it is lost after 7 digits

As for the case of ff=1.0 mentioned by LZ, the compiler should treat all the following as 0
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list