找回密码
 加入
搜索
查看: 2575|回复: 7

[AU3基础] 发现个奇怪现象

  [复制链接]
发表于 2011-6-20 04:07:52 | 显示全部楼层 |阅读模式
本帖最后由 happytc 于 2011-6-20 04:09 编辑


Do 
        $x += 0.1
        ConsoleWrite($x & " ")
Until $x > 10


看来au3内部是用Double类型在计算,所以上面的计算会出象:
..... 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.99999999999999 6.09999999999999 6.19999999999999.....
发表于 2011-6-20 04:57:00 | 显示全部楼层
double?这是双精度。应该是单精度float计算的。
发表于 2011-6-20 06:05:29 | 显示全部楼层
这样子没出错
$x = 5
Do 
        $x += 0.1
        ConsoleWrite($x & @CRLF)
Until $x > 6

这样子就晕了
$x = 4
Do 
        $x += 0.1
        ConsoleWrite($x & @CRLF)
Until $x > 6


为什么5.4 += 0.1 = 5.49999999999999
发表于 2011-6-20 08:35:59 | 显示全部楼层
1=0.9999999。。。。
 楼主| 发表于 2011-6-20 08:40:54 | 显示全部楼层
回复 2# pusofalse


    老大,怎么会是单精度呢?
在32位系统中:
double: 8字节,-10^308~~10^308,有效数字15~16位。
float:4字节,-10^38~~10^38,有效数字6~7位。
看看上面的数字,明显是15~16个数字呀
发表于 2011-6-20 08:44:48 | 显示全部楼层
测试了以下,确实挺奇怪;难道是误差?
发表于 2011-6-20 09:27:34 | 显示全部楼层
回复 5# happytc


   不是这样算的啊。 - -|||
精度越高误差越小,你用DllStructCreate测试一下就知道了。
发表于 2011-6-20 10:38:27 | 显示全部楼层
回复 7# pusofalse
遇到过这样的问题,让人费解啊.
http://www.autoitx.com/thread-18353-1-1.html
double()
Float()

Func double()
        local $str
Local $Double=DllStructCreate("double X;double Y")
DllStructSetData($Double,"X",4)
DllStructSetData($Double,"Y",0.1)
Do 
    DllStructSetData($Double,"X",DllStructGetData($Double,"X",1)+DllStructGetData($Double,2))
        $str&=DllStructGetData($Double,"X",1) & @CRLF
Until DllStructGetData($Double,"X",1) > 6
msgbox(0,"Double",$str)
EndFunc


Func Float()
        local $str
$float=DllStructCreate("float X;float Y")
DllStructSetData($float,"X",4)
DllStructSetData($float,"Y",0.1)
Do 
    DllStructSetData($float,"X",DllStructGetData($float,"X",1)+DllStructGetData($float,2))
    $str&=DllStructGetData($float,"X",1) & @CRLF
Until DllStructGetData($float,"X",1) > 6
msgbox(0,"Float",$str)
EndFunc
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-21 04:33 , Processed in 0.080007 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表