# Algorithms_in_C++: numerical_methods/babylonian_method.cpp File Reference

Loading...
Searching...
No Matches
babylonian_method.cpp File Reference

A babylonian method (BM) is an algorithm that computes the square root. More...

`#include <cassert>`
`#include <cmath>`
`#include <iostream>`
Include dependency graph for babylonian_method.cpp:

## Namespaces

namespace | numerical_methods
| for assert

## Functions

double | numerical_methods::babylonian_method (double radicand)
| Babylonian methods is an iterative function which returns square root of radicand. More...
static void | test ()
| Self-test implementations. More...
int | main (int argc, char const *argv[])
| Main function. More...

## Detailed Description

A babylonian method (BM) is an algorithm that computes the square root.

This algorithm has an application in use case scenario where a user wants find accurate square roots of large numbers

Author
  Ameya Chawla

## Function Documentation

## main()

int main | ( | int | argc,
|  | char const * | argv[]
| ) |  |

Main function.

Parameters

  argc | commandline argument count (ignored)
  argv | commandline array of arguments (ignored) calls automated test function to test the working of fast fourier transform.

Returns
  0 on exit

{
test(); // run self-test implementations
// with 2 defined test cases
return 0;
}
test
static void test()
Self-test implementations.
Definition: babylonian_method.cpp:62
Here is the call graph for this function:

## test()

static void test | ( |  | ) |

static

Self-test implementations.

Declaring two test cases and checking for the error in predicted and true value is less than 0.0001.

Returns
  void

Testcase 1

Testcase 2

Real Output 1

Real Output 2

Test result for testcase 1

Test result for testcase 2

Testing for test Case 1

Testing for test Case 2

{
/* descriptions of the following test */
auto testcase1 = 125348; /// Testcase 1
auto testcase2 = 752080; /// Testcase 2
auto real_output1 = 354.045194855; /// Real Output 1
auto real_output2 = 867.225460881; /// Real Output 2
auto test_result1 = numerical_methods::babylonian_method(testcase1);
/// Test result for testcase 1
auto test_result2 = numerical_methods::babylonian_method(testcase2);
/// Test result for testcase 2
assert(std::max(test_result1, real_output1) -
std::min(test_result1, real_output1) <
0.0001);
/// Testing for test Case 1
assert(std::max(test_result2, real_output2) -
std::min(test_result2, real_output2) <
0.0001);
/// Testing for test Case 2
std::cout << "All tests have successfully passed!\n";
}
std::cout
std::max
T max(T... args)
std::min
T min(T... args)
numerical_methods::babylonian_method
double babylonian_method(double radicand)
Babylonian methods is an iterative function which returns square root of radicand.
Definition: babylonian_method.cpp:30
Here is the call graph for this function: