AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Error in Round() after using DllCall

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Icarus



Joined: 24 Nov 2005
Posts: 433

PostPosted: Mon Aug 20, 2007 5:44 pm    Post subject: Error in Round() after using DllCall Reply with quote

Hello,

I posted this in a different thread and was referred to this thread instead.
There seems to be a problem with Round() that happens after loading rmchart.dll.

The original thread is here
The rmchart homepage is here

The following code demonstrates the problem.

The Round() function returns a different value after the DllCall

Code:
myNumber  := 1043.22
myRounded := Round( myNumber, -1 )
msgbox 32,,Before: %myRounded%
   
ChartModule := DllCall("LoadLibrary", "str", "rmchart.dll")

myNumber  := 1043.22
myRounded := Round( myNumber, -1 )
msgbox 32,,After %myRounded%



The first call generates 1040 as expected, the second call - 1039...

The developer, Rainer Morgen is very friendly and I am guessing the problem is with his DLL, but I am not sure how to report this to him.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Fri Aug 24, 2007 2:03 am    Post subject: Reply with quote

I think this is similar to the Floor/Ceil bug fixed in v1.0.40.05. Apparently its caused by some kind of variation in floating point precision or mode.

Adding a small value (arbitrarily 0.2) to the rounded value before truncating the portion to the right of the decimal point seems to fix it:
Code:
aResultToken.value_int64 = (__int64)(aResultToken.value_double + (aResultToken.value_double > 0 ? 0.2 : -0.2));

This fix will be in the next release. Thanks for the example and DLL link.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group