source: sasview/realSpaceModeling/iqPy/libiqPy/tnt/tnt_math_utils.h @ 8742751

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 8742751 was f2d6445, checked in by Mathieu Doucet <doucetm@…>, 17 years ago

moving realSpaceModeling to trunk

  • Property mode set to 100644
File size: 494 bytes
Line 
1#ifndef MATH_UTILS_H
2#define MATH_UTILS_H
3
4/* needed for fabs, sqrt() below */
5#include <cmath>
6
7
8
9namespace TNT
10{
11/**
12        @returns hypotenuse of real (non-complex) scalars a and b by
13        avoiding underflow/overflow
14        using (a * sqrt( 1 + (b/a) * (b/a))), rather than
15        sqrt(a*a + b*b).
16*/
17template <class Real>
18Real hypot(const Real &a, const Real &b)
19{
20       
21        if (a== 0)
22                return abs(b);
23        else
24        {
25                Real c = b/a;
26                return fabs(a) * sqrt(1 + c*c);
27        }
28}
29} /* TNT namespace */
30
31
32
33#endif
34/* MATH_UTILS_H */
Note: See TracBrowser for help on using the repository browser.