Bug with ACos and ASin

Report problems with documented functionality
User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Bug with ACos and ASin

22 Jul 2017, 05:40

Please see the test code below.

C := A-B = 0.24

if C is calculated, both ACos and ASin are not working properly.

If C is given 0.24, the results are ok.

It looks like a serious bug for math functions. AHK.L 1.1.26.00

Code: Select all

A:=8.5
B:=8.26
C:= A-B
Ang1 :=ACos(C/0.240)
Ang2 :=ASin(C/0.240)
	      	
Msgbox % "c: " C "  Ang1:   " Ang1 "  Ang2:   " Ang2 


C:= 0.24
Ang1 :=ACos(C/0.240)
Ang2 :=ASin(C/0.240)
	      	
Msgbox % "c: " C "  Ang1:   " Ang1 "  Ang2:   " Ang2 
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Bug with ACos and ASin

22 Jul 2017, 06:01

I get blanks for the first MsgBox and correct answers for the second MsgBox.

If I add SetFormat, Float, 0.6, then I get the same answers for both.

So it might be related to this:
(var1 = var2) inconsistent on different scripts - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=34103
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Bug with ACos and ASin

22 Jul 2017, 07:33

Arcsin and arccos are only defined in the range [-1,1]. The float failing is probably 1.00...00x, x>0, due to float inaccuracy.
User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Re: Bug with ACos and ASin

22 Jul 2017, 08:33

l know the reason, and I know the ways walking round, but I just think these kinds of bugs are better be fixed at the bases.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Bug with ACos and ASin

22 Jul 2017, 09:09

Oldbrother, the bug is in your code, you are calling the function with invalid parameters.

Cheers. :xmas:

Personally, I think invalid paramters should throw an exception, it is much better to get notified directly when one has made a mistake, rather than getting blanks from unknown origin.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Bug with ACos and ASin

22 Jul 2017, 09:09

The base that causes the problem is binary logic. Have fun fixing that.

Code: Select all

SetFormat, FloatFast, 15.30
A:=8.5
B:=8.26
C:= A-B
Ang1 :=ACos(C/0.24)
Ang2 :=ASin(C/0.240)

Msgbox % "c: " C "  Ang1:   " Ang1 "  Ang2:   " Ang2 


C:= 0.24 + 0.0
Ang1 :=ACos(C/0.240)
Ang2 :=ASin(C/0.240)

Msgbox % "c: " C "  Ang1:   " Ang1 "  Ang2:   " Ang2
Recommends AHK Studio
User avatar
oldbrother
Posts: 273
Joined: 23 Oct 2013, 05:08

Re: Bug with ACos and ASin

22 Jul 2017, 09:44

SetFormat seems cannot solve the problem.

nnnik, with your modified code, the first msgbox still gets blank Ang1 and Ang2.

My working around is C:= Round(C,10)

The real reason is A-B = 8.5-8.26 = 0.2400000000000002100000
Helgef wrote:Oldbrother, the bug is in your code, you are calling the function with invalid parameters.
:?: :?: :?:
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Bug with ACos and ASin

22 Jul 2017, 12:03

ASin wrote:If Number is less than -1 or greater than 1, the function yields a blank result (empty string).

Code: Select all

A := 8.5
B := 8.26
C := A - B
N := C / 0.240
MsgBox, % "N > 1.0 = " . (N > 1.0 ? "True" : "False")
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Bug with ACos and ASin

22 Jul 2017, 12:46

@oldbrother I merely wanted to show the Problem not fix it.
Recommends AHK Studio

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 26 guests