Skip to content

Latest commit

 

History

History
60 lines (38 loc) · 2.39 KB

index.md

File metadata and controls

60 lines (38 loc) · 2.39 KB
title description verification
What Every Programmer Should Know About Floating-Point Arithmetic
Aims to provide both short and simple answers to the common recurring questions of novice programmers about floating-point numbers not 'adding up' correctly, and more in-depth information about how IEEE 754 floats work, when and how to use them correctly, and what to use instead when they are not appropriate.
SoYmbsJEmSz2s1LmZk_cku4pKwhRsU6m0ZOTgGdnTL0

or

Why don't my numbers add up?

So you've written some absurdly simple code, say for example:

	0.1 + 0.2

and got a really unexpected result:

	0.30000000000000004

Maybe you asked for help on some forum and got pointed to a long article with lots of formulas that didn't seem to help with your problem.

Well, this site is here to:

  • Explain concisely why you get that unexpected result
  • Tell you how to deal with this problem
  • If you're interested, provide in-depth explanations of why floating-point numbers have to work like that and what other problems can arise

You should look at the Basic Answers first - but don't stop there!


title: 每个程序员应该知道关于浮点的代数 description: Aims to provide both short and simple answers to the common recurring questions of novice programmers about floating-point numbers not 'adding up' correctly, and more in-depth information about how IEEE 754 floats work, when and how to use them correctly, and what to use instead when they are not appropriate. verification: SoYmbsJEmSz2s1LmZk_cku4pKwhRsU6m0ZOTgGdnTL0

或者

为什么我的数字加起来不对?

比如你写了一些非常简单的代码,例如:

	0.1 + 0.2

得到了完全意外的结果:

	0.30000000000000004

你有可能在某个论坛寻求帮助,然后得到一个指向 有很多公式的长文章 ,但这个结果好像并不能帮你解决问题。

好吧,本网站就是:

  • 简明解释为什么你得到了意外的结果
  • 告诉你怎么处理这个问题
  • 如果你感兴趣,本站也提供了深入的解释来说明为什么浮点数要这样工作,还有其他一些可能出现的问题

你应该首先看 基础答案 - 但你不应该在那里停下来!