Bug 145630 - Use atan2 function instead of atan
Summary: Use atan2 function instead of atan
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
(earliest affected)
Hardware: All All
: medium normal
Assignee: Not Assigned
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Reported: 2021-11-11 15:04 UTC by Hossein
Modified: 2021-11-18 15:09 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Note You need to log in before you can comment on or make changes to this bug.
Description Hossein 2021-11-11 15:04:25 UTC
If you use atan(x) to calculate the output θ, you have to think about different situations that may occur, because with the same value of x, there are multiple values of θ, and it would be your responsibility to handle that, and find out what is the suitable value of θ.

But, if you have two values y and x, and you want to calculate atan(y / x), there is a better choice: using atan2(y, x); atan2(y, x) can handle the values from all the 4 different quadrants:


Instances of the similar situations can be found by invoking:

git grep atan\(

Within the results of the grep, you can find places that atan2() is better suited. You should take care about the conditions that may be present (or missing) after the atan() in which check the signature of the  and make sure that the code works correctly after removing them.
Comment 1 Hossein 2021-11-17 15:42:26 UTC
Blog post related to this EasyHack in the LibreOffice Development Blog:

Example commit (hwpfilter/source/hcode.cxx)