formatting source-code for 153fb7b8a5

This commit is contained in:
github-actions
2020-05-30 04:02:09 +00:00
parent 92fe9495ec
commit 8a2de9842b
175 changed files with 1671 additions and 3460 deletions

View File

@@ -23,8 +23,7 @@
* algorithm implementation for \f$a^b\f$
*/
template <typename T>
double fast_power_recursive(T a, T b)
{
double fast_power_recursive(T a, T b) {
// negative power. a^b = 1 / (a^-b)
if (b < 0)
return 1.0 / fast_power_recursive(a, -b);
@@ -48,15 +47,13 @@ double fast_power_recursive(T a, T b)
It still calculates in \f$O(\log N)\f$
*/
template <typename T>
double fast_power_linear(T a, T b)
{
double fast_power_linear(T a, T b) {
// negative power. a^b = 1 / (a^-b)
if (b < 0)
return 1.0 / fast_power_linear(a, -b);
double result = 1;
while (b)
{
while (b) {
if (b & 1)
result = result * a;
a = a * a;
@@ -68,14 +65,12 @@ double fast_power_linear(T a, T b)
/**
* Main function
*/
int main()
{
int main() {
std::srand(std::time(nullptr));
std::ios_base::sync_with_stdio(false);
std::cout << "Testing..." << std::endl;
for (int i = 0; i < 20; i++)
{
for (int i = 0; i < 20; i++) {
int a = std::rand() % 20 - 10;
int b = std::rand() % 20 - 10;
std::cout << std::endl << "Calculating " << a << "^" << b << std::endl;