No.MachineCode wrote:let Fred swap the order of parameters to match the majority of other languages (C, Java, Ruby, Python, PHP, JavaScript)?
[Solved][4.60 RC1] ATan2() parameters are switched
-
- Addict
- Posts: 2345
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: [Solved][4.60 RC1] ATan2() parameters are switched
bye,
Daniel
Daniel
Re: [Solved][4.60 RC1] ATan2() parameters are switched
I actually put some thought into the parameter order here. This was not an accident, so it won't change.
quidquid Latine dictum sit altum videtur
Re: [Solved][4.60 RC1] ATan2() parameters are switched
Well to me, it actually makes more sense.
I'm not a math god so I'd need to look it up anyway, but:
it's really hard to find another situation where the y argument comes before the x...it just doesn't happen.
I'm not a math god so I'd need to look it up anyway, but:
it's really hard to find another situation where the y argument comes before the x...it just doesn't happen.

Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
-
- Addict
- Posts: 2345
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: [Solved][4.60 RC1] ATan2() parameters are switched
I'm sure the first intention of the atan2(y, x) command was to stay consistent with atan(y / x)Shield wrote:Well to me, it actually makes more sense.
I'm not a math god so I'd need to look it up anyway, but:
it's really hard to find another situation where the y argument comes before the x...it just doesn't happen.

+1 -1 = 0, neutral position = don't do anything, as it wouldn't be worth to.
But there are already codes which use atan2(x, y), so the reasons to keep it this way are more.
bye,
Daniel
Daniel
Re: [Solved][4.60 RC1] ATan2() parameters are switched
Hi,
in general it is no problem.
If I write a new program I'm so unsure, that I look into the help.
But... as it happens to me:
If you translate a program from an other language to PB I'm 100% sure that 90% runs in this trouble.
(like me
)
And to find a fault in a mathematical program is really hard.
Bernd
in general it is no problem.
If I write a new program I'm so unsure, that I look into the help.
But... as it happens to me:
If you translate a program from an other language to PB I'm 100% sure that 90% runs in this trouble.
(like me

And to find a fault in a mathematical program is really hard.
Bernd
Re: [Solved][4.60 RC1] ATan2() parameters are switched
I think, it should be like it is now.
Tangens is definde Y divided by X in the
unit circle, so it is logically for ATAN2()
to first get Y and then X as argument.
By the way: if you look at Wikipedia, there
ist always ATN2(y,x) used and also Excel
demands (y,x)-order.
Tangens is definde Y divided by X in the
unit circle, so it is logically for ATAN2()
to first get Y and then X as argument.
By the way: if you look at Wikipedia, there
ist always ATN2(y,x) used and also Excel
demands (y,x)-order.

-
- Addict
- Posts: 1676
- Joined: Sun Dec 12, 2010 12:36 am
- Location: Somewhere in the midwest
- Contact:
Re: [Solved][4.60 RC1] ATan2() parameters are switched
Just be careful when translating programs or starting new ones of your own..
The context help should clearly lay out the parameter order as well, if you look at the status bar while typing.
If it really bugs people, they can always just write a Macro that takes the parameter order they are used to, and then reverses it internally.
The context help should clearly lay out the parameter order as well, if you look at the status bar while typing.
If it really bugs people, they can always just write a Macro that takes the parameter order they are used to, and then reverses it internally.
Re: [Solved][4.60 RC1] ATan2() parameters are switched
@Zach
Yes, you see the parameters in the status line. That's correct.
But if you have a code like thiswhich you only translate to PB, I'm sure you don't know what is x and what is y.
Bernd
Yes, you see the parameters in the status line. That's correct.
But if you have a code like this
Code: Select all
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
Bernd
-
- Addict
- Posts: 1676
- Joined: Sun Dec 12, 2010 12:36 am
- Location: Somewhere in the midwest
- Contact:
Re: [Solved][4.60 RC1] ATan2() parameters are switched
I would posit that is the fault of the original coder for not properly commenting 

Re: [Solved][4.60 RC1] ATan2() parameters are switched
Then you're basically guessing anywayinfratec wrote:@Zach
Yes, you see the parameters in the status line. That's correct.
But if you have a code like thiswhich you only translate to PB, I'm sure you don't know what is x and what is y.Code: Select all
var R = 6371; // km var dLat = (lat2-lat1).toRad(); var dLon = (lon2-lon1).toRad(); var lat1 = lat1.toRad(); var lat2 = lat2.toRad(); var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2); var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); var d = R * c;
Bernd

Re: [Solved][4.60 RC1] ATan2() parameters are switched
MachineCode wrote:So easily fixed with a quick macro:infratec wrote:ATan2(0.0705, 0.9975) should return something arround 0.070559
But the current implementation results in 1.500237
Then, when Fred changes it, just delete the macro and search/replace your source and all is well.Code: Select all
Macro MyATan2(y,x) ATan2(x,y) EndMacro Debug ATan2(0.0705, 0.9975) ; Returns 1.50023696... Debug MyATan2(0.0705, 0.9975) ; Returns 0.070559...
Another way:
Code: Select all
; Atan2_inverted.pb
Procedure.f _Atan2(x.f,y.f)
ProcedureReturn ATan2(x,y)
EndProcedure
Macro ATan2 (y,x)
_ATan2 (x,y)
EndMacro
Code: Select all
IncludeFile "Atan2_inverted.pb"
Debug ATan2 (0.0705, 0.9975) ; Returns 0.070559...
If PB change the params order, just remove the include and you are set.
The advantage is there is no need to do a search and replace.
Especially useful if you redefine many PB commands at once and to quickly switch back and forth between the different command sets.
I posted this only as an example of a technique that can be useful in some other case, since Freak already stated this probably will not change.
"Have you tried turning it off and on again ?"