MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / fastPow10

Function fastPow10

app/src/UI/Widgets/Plot3D.cpp:37–50  ·  view source on GitHub ↗

* @brief Integer-exponent 10^n via table lookup; std::pow fallback for out-of-band values. */

Source from the content-addressed store, hash-verified

35 * @brief Integer-exponent 10^n via table lookup; std::pow fallback for out-of-band values.
36 */
37static double fastPow10(double exponent) noexcept
38{
39 static constexpr double kTable[] = {
40 1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, 1e-9, 1e-8, 1e-7, 1e-6, 1e-5,
41 1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6,
42 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15,
43 };
44
45 const int idx = static_cast<int>(exponent) + 15;
46 if (idx < 0 || idx >= static_cast<int>(sizeof(kTable) / sizeof(kTable[0]))) [[unlikely]]
47 return std::pow(10.0, exponent);
48
49 return kTable[idx];
50}
51
52//--------------------------------------------------------------------------------------------------
53// Constructor & initialization

Callers 2

idealWorldScaleMethod · 0.70
gridStepMethod · 0.70

Calls 1

powFunction · 0.85

Tested by

no test coverage detected