系统交易论坛 - 开拓者期货自动交易平台's Archiver

brucecolvin 发表于 2010-6-4 08:53

intpart函数bug!

intpart函数bug![code]Params

Vars

        Numeric Status(-1.2);
        Numeric tmp;

Begin

        tmp = abs(Status);       //应等于1.2
       
        tmp = tmp-intpart(tmp); //应等于0.2
               
        tmp = tmp*10;            //应等于2
       
        Commentary(text(tmp)); //应等于2
       
        tmp = intpart(tmp);     //应等于2
       
        Commentary(text(tmp)); //应等于2,实际却等于1
       
        tmp = tmp/10;                          //应等于0.2,实际却等于0.1
       
        Commentary(text(tmp)); //应等于0.2,实际却等于0.1
       
        Commentary(text(IntPart(2))); //应该=2,实际也等于2;

End
[/code]

lh948 发表于 2010-6-4 09:41

这个是数据底层浮点数的内部存储机制导致的。
尝试使用Floor等其他的函数来避免

brucecolvin 发表于 2010-6-4 10:46

[quote]原帖由 [i]lh948[/i] 于 2010-6-4 09:41 发表 [url=http://www.tradeblazer.net/forum/redirect.php?goto=findpost&pid=49862&ptid=8559][img]http://www.tradeblazer.net/forum/images/common/back.gif[/img][/url]
测试确实有这个问题,是底层浮点数的内部存储机制导致的。
尝试使用Floor等其他的函数来避免 [/quote]


:L :L :L ,还有好几个问题,我至少帮你们测出明确问题3个以上,你们测试部的要感谢我才对。
我说我的程序为什么常常放错,我一点点排查,花了很长时间,才定位到这个地方,真的很费劲。

[[i] 本帖最后由 brucecolvin 于 2010-6-4 11:05 编辑 [/i]]

paozi84 发表于 2010-6-5 00:57

工程部应该请brucecolvin吃饭~~:lol

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.