#721 closed Bug (No Bug)
_Atan2() returns wrong
Reported by: | trancexx | Owned by: | |
---|---|---|---|
Milestone: | Component: | AutoIt | |
Version: | 3.2.12.1 | Severity: | None |
Keywords: | Cc: |
Description
It's function from Math.au3
Returns wrong for points located in third quadrant.
#include <Math.au3> ConsoleWrite(_Atan2(-1, -3) & @CRLF)
The result should be -2.8198420991932 but it's returning 3.46334320798644
Link to one online calculator to verify result:
http://ostermiller.org/calc/calculator.html
Attachments (0)
Change History (7)
comment:1 Changed 16 years ago by Valik
- Resolution set to No Bug
- Status changed from new to closed
comment:2 Changed 16 years ago by anonymous
The whole point of function atan2 in mathematics is to be able to return negative.
Range of results should be between -pi and pi, othervise it cannot be called atan2 (_Atan2() in this case).
Check C function.
Deceptive function name.
comment:3 Changed 16 years ago by trancexx
sorry for anonymous thing
trancexx wrote that
comment:4 Changed 16 years ago by Valik
I don't think you are correct in stating that it can not be called Atan2 just because it doesn't return what you want. The range can either be -π,π or 0,2π. It's the same thing expressed two different ways. The choice David made was to express the values as 0,2π and you want to express them as -π,π. So convert - subtract 2π from any value > π and you have what you are looking for.
comment:5 Changed 16 years ago by trancexx
Definition of atan2 is very precise, like any other math function.
atan2(-1, -3) is -2.8198420991932
That would be like you said "If adding two numbers returns their difference its wrong to say that that is not adding" (this is obviously taking it to the edge).
Definition of atan2 , wiki link:
http://en.wikipedia.org/wiki/Atan2
And The Open Group thing:
http://www.opengroup.org/onlinepubs/000095399/functions/atan2.html
Check latter please
Consult the author of the function. He would have to agree if _Atan2() is atan2.
comment:6 Changed 16 years ago by Valik
Did you bother to read the part on the Wikipedia page where it mentions how to convert from the range -π,π to 0,2π? I can see uses for both ranges and I don't think that either range is wrong. What I do think is that you are so accustomed to using one range that you fail to accept that just maybe other people use another range. And you seem so stuck on this point that you refuse to acknowledge that both values represent the same angle.
Here's a thought. Shut the fuck up because I'm tired of arguing with you. Your hyperbolic example makes no sense. You ignore the little blurb on Wikipedia which seems to imply that 0,2π is a valid and normal range and your other link is to something that's completely irrelevant to AutoIt. Comparing AutoIt to anything else is inviting me to flame the living shit out of you for not realizing that we did things our way and not some other way just because.
Lastly, as for David and the choice he made, I'm fairly inclined to think a C++ professor is well aware of a conscious decision to deviate his version of Atan2 from the behavior in C\C++ and most other languages. And even if it wasn't intentional, guess what, it's not getting changed. You are the only person who has complained. The value's returned are equivalent and if you need them converted to something else, convert them. I'm certainly not going to let scripts get broken just because one person can't accept that a function doesn't behave how he wants it to.
comment:7 Changed 16 years ago by trancexx
It's ok. I can live with that explanation.
_Atan2() is "real" atan2 mapped to range 0 to 2pi
I'll shut the fuck up.
And sorry for tiring you. If I find something that I think is maybe wrong, will try to make more meaningful, less hyperbolic example(s). Of course, will not give you links that have anything to do with ISO standard.
Thanks again for that DLL structure explanation you provided earlier.
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
The code is correct. The angles returned are always going to be positive. If you'll notice, the value you get from _Atan2() - 360 = the value you are after. So, you need to write a thin wrapper that determines the direction and re-calculates the value since _Atan2() will always return the positive angle.