mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-03 00:36:48 +00:00
Test optimization: Number_test::pow10
This commit is contained in:
@@ -48,17 +48,23 @@ class Number_test : public beast::unit_test::Suite
|
||||
static T
|
||||
pow10(int n)
|
||||
{
|
||||
if (n == 0)
|
||||
return 1;
|
||||
if (n == 1)
|
||||
return 10;
|
||||
|
||||
if (n > 1)
|
||||
{
|
||||
auto r = pow10<T>(n / 2);
|
||||
r *= r;
|
||||
if (n % 2 != 0)
|
||||
r *= 10;
|
||||
return r;
|
||||
}
|
||||
|
||||
// n < 0
|
||||
T p = 1;
|
||||
if (n >= 0)
|
||||
{
|
||||
for (int i = 0; i < n; ++i)
|
||||
p *= 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < -n; ++i)
|
||||
p /= 10;
|
||||
}
|
||||
p /= pow10<T>(-n);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user