Category : sqrt

#include <iostream> float calculating_root(float N, float root_N, float increment) { int safety=1; while(safety==1) { if (N == (root_N*root_N)) { safety=0; return root_N; } else if(N<((root_N+increment)*(root_N+increment))) { safety=0; return calculating_root(N,root_N, increment*0.1); } root_N=root_N+increment; } } int main() { float N, root_N=0.0, increment=1000.0; scanf("%f",&N); float x = calculating_root(N, root_N, increment); printf("n%gn",x); return 0; } I’ve been thinking ..

Read more

I need to evaluate the expression cbrt(b) / ((b)^2 + 1). If b less than zero, the log is not correct and outputs an incorrect answer. For example, if the input is -3 the answer is y = -1IND. #include <iostream> #include <cmath> int main() { float b, y, y1, y2; std::cout << "The equation: ..

Read more

I wrote this implementation of sqrt that is finite in complexity and precise up to the last digit when double is ieee754 double. The question is that is this portable on devices of various endian (assuming 0LL is still 64 bit)? get_fraction returns the 52bits plus the 1 bit at the begining. Small doubles are ..

Read more

writing a function for columnwise computation of sample skewness in Rcpp I’m in trouble using sqrt()-function. I know that sqrt(x) works for NumericVector types (tested it in a separate file), however in my code (where I’m trying to pass doubles) it does not work. Here’s my code: #include <Rcpp.h> #include <cmath> using namespace Rcpp; // ..

Read more

#include <iostream> #include <cmath> using namespace std; int main(){ int n; cin >> n; int i = sqrt(1 + 2 * n * (n + 1)) – 1; cout << i; } I have written a simple program which utilizes the sqrt() function in C++. The above program prints out a negative value on the ..

Read more