Add const attribute to new sqrt routines.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2019-12-25 19:03:30 +00:00
parent 0aaa3237b1
commit 0b680952a4
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
2 changed files with 6 additions and 7 deletions

View File

@ -11,8 +11,7 @@
#include "math.h"
// Recursive function that returns square root
// of a number with precision upto 5 decimal places
double Square(double n, double i, double j)
__attribute__((const)) double Square(const double n, const double i, const double j)
{
double mid = (i + j) / 2;
double mul = mid * mid;
@ -31,8 +30,8 @@ double Square(double n, double i, double j)
}
}
// Function to find the square root of n
double my_sqrt(double n)
// Function to find the square root of n
__attribute__((const)) double my_sqrt(const double n)
{
// While the square root is not found
for(double i = 1.0; true; i++)
@ -44,7 +43,7 @@ double my_sqrt(double n)
}
else if (i * i > n)
{
// Square root will lie in the interval i-1 and i
// Square root is in [i-1, i]
return Square(n, i - 1, i);
}
i++;

View File

@ -17,9 +17,9 @@
#define SQRT_PRECISION 1e-5
// Recursive function that returns square root
double Square(double n, double i, double j);
double Square(const double n, const double i, const double j) __attribute__((const));
// Function to find the square root of n
double my_sqrt(double n);
double my_sqrt(const double n) __attribute__((const));
#endif //MATH_H