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 

Addition with 17+ digits

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



Joined: 15 Dec 2004
Posts: 303
Location: United States

PostPosted: Mon May 02, 2005 8:26 pm    Post subject: Addition with 17+ digits Reply with quote

Try the following code (make sure the editor window accepts 83 characters minimum). The highlighted sum is the first instance where the sum is incorrect. This may also have something to do with subsequent lines where there are trailing zeros.
Code:
^+f::
SetKeyDelay 0
;SetFormat, Float, 0.1
SetFormat, Float, 080.1
SetTimer, TimerFibonacci, 100
a0=0.
a1=1.
Run, Notepad
sleep 300
WinWaitActive Untitled - Notepad
Loop
{
   GetKeyState, ksCtrl, Ctrl, p
   if ksCtrl=D
      BREAK
   aT:=a1
   a1+=a0
   a0=%aT%
   ControlSend, Edit1, % a1 ", ", Untitled - Notepad
}
ControlSend, Edit1, ^{home}{down 77}{shiftdown}{end}{left 3}{shiftup}, Untitled - Notepad
SetTimer, TimerFibonacci, off
Tooltip
return

TimerFibonacci:
Tooltip, hold Ctrl to stop
return

_________________
1) The Open Source Definition http://www.opensource.org/docs/definition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <<AutoHotkey>>
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Mon May 02, 2005 9:54 pm    Post subject: Reply with quote

If you mean that 14472334024676220.0 should be one greater, this is caused by the fact floating point values are limited to 16 digits of precision. This is because AutoHotkey internally uses doubles, which are 64-bit floating point values.

Although I realize you're using floating point math to take advantage of SetFormat's ability to provide leading zeros, you can work around this by using integer math instead. Integers are 64-bit and can range between -9223372036854775808 and 9223372036854775807 (19 digits). If you go beyond that range, it will probably wrap around back to zero.

To use integer math, ensure each operand lacks a decimal portion. You can provide leading zeros with something like:

Padded = 000000000000000000000000%a1% ; Add more zeros to make a total of 80 zeros.
StringRight, Padded, Padded, 80
Back to top
View user's profile Send private message Send e-mail
Decarlo110



Joined: 15 Dec 2004
Posts: 303
Location: United States

PostPosted: Mon May 02, 2005 10:35 pm    Post subject: Reply with quote

Thank you for the explanation, and useful tip.

I noticed that Microsoft Calculator is able to work with 32 digits of accuracy. I'm wondering what method it uses since it doesnt seem to have the 64-bit limitation, and whether AutoHotkey can adopt it also, if it doesnt slow performance? possibly with no upper limit, if that is possible?
_________________
1) The Open Source Definition http://www.opensource.org/docs/definition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <<AutoHotkey>>
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Tue May 03, 2005 8:17 pm    Post subject: Reply with quote

It would definitely reduce performance in many aspects of the program to increase the limit. This is because modern CPUs and compilers are optimized for 32-bit and 64-bit math.

An alternative would be to selectively apply the slow method when numbers larger than the limit are detected. However, such detection would incur performance overhead that doesn't seem justified given how rarely such enormous numbers are needed.

In any case, the suggestion is appreciated. I wish there were a way to do it without giving up so much.
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