content icon indicating copy to clipboard operation
content copied to clipboard

atan2() calculation always returns an <angle> in degrees, not radians

Open Jollus174 opened this issue 2 weeks ago • 5 comments

MDN URL

https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/atan2

What specific section or headline is this issue about?

The introduction (and possibly other sections of page).

What information was incorrect, unhelpful, or incomplete?

I might be misunderstanding here, but it mentions.

The function accepts two arguments and returns the number of radians representing an between -180deg and 180deg.

I've tested this, and wouldn't this actually be the number of degrees between -180deg and 180deg? For example, applying a radians-to-degress conversion via:

  --angle-rad: atan2(3, 2);
  --angle-deg: calc(var(--angle-rad) * 180 / pi);

would end up with a wildly incorrect result for --angle-deg. In this example, I'd used CSS trigonmetry calculations to offset a gradient based off the position of the mouse relative to the centre of the screen: https://codepen.io/Jollus/pen/WbweZoX We can see in JS angle rad in the top-left what the radians is expected to be, calculated with JavaScript. However, this is not what ends up being applied to the --angle (the CSS calculation).

Image

To me, it seems clear that atan2() is returning the result in degrees, and not radians. This may be so for other trigonometry calculations as well, although I've not tested those.

What did you expect to see?

I would think that any reference to atan2() returning radians would need to be updated to show that it returns degrees instead, unless there's something I'm missing here.

Do you have any supporting links, references, or citations?

https://codepen.io/Jollus/pen/WbweZoX

Image

Do you have anything more you want to share?

No response

MDN metadata

Page report details
  • Folder: en-us/web/css/reference/values/atan2
  • MDN URL: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/atan2
  • GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/css/reference/values/atan2/index.md
  • Last commit: https://github.com/mdn/content/commit/85fccefc8066bd49af4ddafc12c77f35265c7e2d
  • Document last modified: 2025-11-07T15:58:06.000Z

Jollus174 avatar Dec 08 '25 09:12 Jollus174

Hello, angles don't have the concept of units. An angle is just an abstract mathematical entity and you can measure it in any unit. However I agree that mixing "radians" and "degrees" in the same sentence is confusing, and we can just change it to "returns an <angle> between -180deg and 180deg".

Josh-Cena avatar Dec 08 '25 17:12 Josh-Cena

Hi! I'd like to work on this issue.
I will update the documentation to clarify that atan2() returns an between -180deg and 180deg, without mixing radians terminology.

abhinav12222363 avatar Dec 09 '25 04:12 abhinav12222363

Thanks for that. It would also be worth checking these pages:

  • https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/atan
  • https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/asin
  • https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/acos

These also contain a similar line, resembling:

The function contains a single calculation that returns the number of radians representing an angle between 0deg and 180deg.

By extension, these pages also reference radians in their descriptions.

  • https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/sin
  • https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/cos
  • https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/tan

They are phrased as:

The function contains a single calculation that must resolve to either a number or an angle by interpreting the result of the argument as radians.

Personally, I find the phrasing in the latter to be less confusing, since they mention that an angle is interpreted, rather than represented (interpreted implies some sort of calculation or conversion, which is what happens). Maybe those ones could be left alone.

Jollus174 avatar Dec 09 '25 07:12 Jollus174

Hi! I can work on updating the related CSS math function pages (atan(), asin(), acos()) to clarify angle wording and avoid mixing radians/degrees terminology, similar to the atan2() fix.

kashish2710 avatar Dec 16 '25 06:12 kashish2710

Hi, I’d like to work on this issue. Please assign it to me if it’s still available. Thanks!

FlorinNatha avatar Dec 16 '25 06:12 FlorinNatha

Fixed via https://github.com/mdn/content/pull/42426

chrisdavidmills avatar Dec 17 '25 09:12 chrisdavidmills