Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the reason for the inaccuracy of float and double operations?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

The main content of this article is to explain "what are the reasons for the inaccuracy of float and double calculation". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the reasons for the inaccuracy of float and double calculations?"

Why is there a problem with floating-point precision operations?

Most of the programming languages we use usually have a problem-floating-point precision operations can be inaccurate. such as

Double num = 0. 1 + 0. 1 + 0. 1 umbrellas / output is 0.30000000000000004double num2 = 0. 65-0. 6; the output is 0. 050000000000004.

During the test, the author found that this kind of problem would not occur in CCompact +. At first, I thought it was compiler optimization to solve this problem. But if it can solve other languages, why not follow up? According to the cause of this problem, it is illogical for compiler optimization to solve this problem. It was later found that there was something wrong with the printing method, and the printout method would be rounded. Use printf ("% 0.17f\ n", num); and cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report