sqrtf()
The sqrtf() function returns the square root of a number of type float.
Syntax
float sqrtf(float arg)
Example: Program to illustrate the use of sqrtf function
C++
// CPP program to illustrate the use of sqrtl function #include <cmath> #include <iomanip> #include <iostream> using namespace std; int main() { long long int var1 = 1000000000000000000; long long int var2 = 999999999999999999; // Calculate and print the square root of val1 cout << fixed << setprecision(12) << sqrtl(var1) << endl; // Calculate and print the square root of val2 cout << fixed << setprecision(12) << sqrtl(var2) << endl; return 0; } |
15.000000000000 17.320508956909
Complexity Analysis
- Time Complexity: O(?n)
- Auxiliary Space: O(1)
sqrt, sqrtl and sqrtf in C++
There are various functions available in the C++ Library to calculate the square root of a number. Most prominently, sqrt is used that is defined in <cmath> header file. It takes double as an argument. The <cmath> header defines two more inbuilt functions for calculating the square root of a number (apart from sqrt) which has an argument of type float and long double.
Following are the functions used for calculating square root in C++ :
- sqrt (double)
- sqrtf (float)
- sqrtl (long double)
The above functions have been discussed in detail below: