- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
double a = 135.24; // a is set to 135.24000000000001 actually
double b = Math.Round(a, 0); // set to 135.0
double c = Math.Round(a, 1); // set to 135.19999999999999
double d = Math.Round(a, 2); // set to 135.24000000000001
double e = Math.Round(a, 3); // set to 135.24000000000001
double f = Math.Round(a, 4); // set to 135.24000000000001
double g = Math.Round(a, 5); // set to 135.24000000000001
double h = Math.Round(a, 10); // set to 135.24000000000001
double i = Math.Round(a, 14); // set to 135.24000000000001
double j = Math.Round(a, 2
, MidpointRounding.AwayFromZero ); // set to 135.24000000000001
double k = Math.Round(a, 2
, MidpointRounding.ToEven ); // set to 135.24000000000001
Sooooo,这意味着 135.24 不能用 double 表示,对吧?
最佳答案
是的,135.24 不能用 double 表示,因为 double 使用二进制指数表示法。
即:135.24 可以以 2 为底指数表示为 1.0565625 * 128 = ( 1 + 1/32 + 1/64 + 1/128 + 1/1024 + ... ) * (2**7) .
表示不能完全做到,因为13524不能除以5,我们看:
135.24 = 13524/(10**2)
representation is finite
<=>
exist whole x and n satisfying135.24 = x/(2**n)
135.24 = x/(2**n)
13524 / (10**2) = x / (2**n)
13524 * (2**n) = (10**2) * x
13524 * (2**n) = 2*2*5*5 * xthere is no "5" on the left side, so it cannot be done (known as the Fundamental Theorem of Arithmetic)
一般来说,只有在十进制数的质因数分解中有足够多的“五”时,有限二进制表示才是准确的。
现在是有趣的部分:
double delta = 0.5;
while( 1 + delta > 1 )
delta /= 2;
Console.WriteLine( delta );
double 的精度在 1 附近不同,在 0 附近不同,对于一些大数字也不同。维基百科上的一些二进制表示示例:Double precision floating point format
但最重要的是,内部处理器浮点堆栈可能比 8 字节( double )精度更高。如果不必将数字传输到 RAM 并将其剥离到 8 个字节,我们可以获得非常好的精度。
在不同的处理器(AMD、Intel)、语言(C、C++、C#、Java)或编译器优化级别上测试类似的东西可以得到大约 1e-16、1e-20 甚至 1e-320 的结果
查看 CIL/汇编程序/jasmin 代码以了解到底发生了什么(例如:对于 C++ g++ -S test.cpp
创建 test.s
文件,其中包含汇编代码)
关于c# - 双重和舍入很难,但这太疯狂了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19833420/
在我们的服务出现一些预期的增长之后,突然间一些更新花费了非常长的时间,这些过去非常快,直到表达到大约 2MM 记录,现在它们每个需要大约 40-60 秒。 update table1 set fiel
我在服务中实现了一个传感器事件监听器,只要采样周期和最大报告延迟低于 1 秒,该监听器就可以正常工作,但一旦我将采样周期增加到超过 1 秒,传感器就根本不会更新。 我希望采样周期为 10 秒(可能是
我使用 Tkinter GUI 来启动测量和分析过程,基本上只需单击一个按钮即可开始。由于这些测量可能需要一段时间,我尝试添加一个进度条,即这个: http://tkinter.unpythonic.
我正在尝试使用套接字发送数据包,但出现错误。 invalid conversion from ‘omnetpp::cPacket*’ to ‘inet::Packet*’ [-fpermissive]
我刚刚发现 String#split 有以下奇怪的行为: "a\tb c\nd".split => ["a", "b", "c", "d"] "a\tb c\nd".split(' ') => ["a
您好,我正在尝试 ClojureScript,我正在使用 Klipse作为我的 REPL 差不多。这可能不是它的预期用途,但因为我没有做任何太复杂的事情,所以现在没问题。 我遇到的一个问题是尝试设置计
根据下面的数据,ClockKit 会生成一次 future 的 CLKComplicationTimelineEntry 项,但对于过去的时间点,会进行 24 次调用!这是为什么? 更多详情: 我注意
我有一个 MySQL 表,这个表有一个名为 datetime_utc 的 DATETIME 列。如您所料,它是 UTC 日期和时间。在我的 Bookshelf 模型中,我定义了一个虚拟 getter,
大家好,我是二哥呀! 昨天,一位球友问我能不能给他解释一下 @SpringBootApplication 注解是什么意思,还有 Spring Boot 的运行原理,于是我就带着他扒拉了一下这个注解的源
我是一名优秀的程序员,十分优秀!