https://bugs.documentfoundation.org/show_bug.cgi?id=147906
Bug ID: 147906
Summary: Use std::hypot for Pythagorean addition
Product: LibreOffice
Version: 7.4.0.0 alpha0+ Master
Hardware: All
OS: All
Status: UNCONFIRMED
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Severity: normal
Priority: medium
Component: LibreOffice
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
There are many places in the code that calculating the Pythagorean addition is
needed, which is defined as:
a ⊕ b = sqrt(a^2+b^2)
This is hypotenuse, or the length of the longest side of a right-angled
triangle, that we know the other 2 sides, a and b.
https://en.wikipedia.org/wiki/Pythagorean_addition
Theoretically, this calculation could be done using sqrt(a * a + b * b), but
there are problems with this approach. For large a or b, there is a possibility
of overflow, although the result itself is not that big to cause overflow.
To overcome this problem, there are implementations of hypotenuse that do not
use power of 2, and use other methods to calculate the result. One of them
which is usable in C++ is the std::hypot. To calculate a ⊕ b, you can easily
use std::hypot(a,b).
https://en.cppreference.com/w/cpp/numeric/math/hypot
As an example, you can see this commit from Mike:
https://git.libreoffice.org/core/+/4cbaaf21fe1c22b36dd72798cecfa59e73d0f8c3
How to find instances
Among the result of this output, you can find some instances:
git grep sqrt
but then you should look for things like 'statement * statement' in the
results.
--
You are receiving this mail because:
You are the assignee for the bug.