News:



  • February 13, 2025, 04:50:40 AM

Login with username, password and session length

Author Topic: EXCEL and atan2/atan2d  (Read 735 times)

Offline Brett Buck

  • Trade Count: (0)
  • Admiral
  • ******
  • Posts: 14226
EXCEL and atan2/atan2d
« on: January 15, 2025, 01:33:47 AM »
This is something kind of nasty we recently discovered - in EXCEL, the arguments for atan2 and atan2d (4-quadrant arctangent) are backwards from almost every other implmentation. atan2 is a function that returns the angle from two arguments, the "rise" and the "run", or Y and X. atan2 returns the angle in radians, and atan2d returns the angle in radians.

    Every computer language aside from EXCEL has these arguments in this order -  alpha = atan2(y,x), logically, Y is the "rise" and X is the "run" For some unknown reason (no doubt associated with Bill Gates close personal relationship to Satan)  the same function in EXCEL expects the first argument to be the "run"/X and the second argument to be the "rise"/Y.  If you don't know this and assume the standard function, of course you get the wrong answer.

      Programmer beware, my recommendation remains to never use EXCEL for anything outside accounting. You can get a home version of MATLAB for something like $175, fully functional, it never expires (although you only get updates for two years) and has it right, using close-to-standard C syntax, or use GNU FORTRAN, Python, or any other language. Or spend days on something and getting the wrong results until you find what this and other f-ups Microsoft has in store for you. Also note taht because this is backwards in EXCEL, it is also backwards in NUMBERS, for compatibility reasons.

      Brett
 
 
« Last Edit: January 15, 2025, 06:19:09 PM by Brett Buck »

Offline Ken Culbertson

  • 25 supporter
  • Trade Count: (0)
  • Admiral
  • *
  • Posts: 6767
Re: EXCEL and atan2/atan2d
« Reply #1 on: January 15, 2025, 07:43:53 AM »
This is something kind of nasty we recently discovered - in EXCEL, the arguments for atan2 and atan2d (4-quadrant arctangent) are backwards from almost every other implmentation. atan2 is a function that returns the angle from two arguments, the "rise" and the "run", or Y and X. atan2 returns the angle in radians, and atan2d returns the angle in radians.

    Every computer language aside from EXCEL has these arguments in this order -  alpha = atan2(y,x), logically, Y is the "rise" and X is the "run" For some unknown reason (no doubt associated with Bill Gates close personal relationship to Satan)  the same function in EXCEL expects the first argument to be the "run"/X and the second argument to be the "run"/Y.  If you don't know this and assume the standard function, of course you get the wrong answer.

      Programmer beware, my recommendation remains to never use EXCEL for anything outside accounting. You can get a home version of MATLAB for something like $175, fully functional, it never expires (although you only get updates for two years) and has it right, using close-to-standard C syntax, or use GNU FORTRAN, Python, or any other language. Or spend days on something and getting the wrong results until you find what this and other f-ups Microsoft has in store for you. Also note taht because this is backwards in EXCEL, it is also backwards in NUMBERS, for compatibility reasons.

      Brett
 
 
This is the reason an accountant has to manually foot anything they get from excel if they use formulae. 
AMA 15382
If it is not broke you are not trying hard enough.
USAF 1968-1974 TAC


Advertise Here
Tags: