Math built-in functions

PHOTO EMBED

Wed Aug 17 2022 20:31:42 GMT+0000 (Coordinated Universal Time)

Saved by @Aly #c++ #stls #built-in_function

//Power function //Complexity: O(exponent).
double x = 6.1, y = 4.8;
double result = pow(x, y);
--------------------------------------------------------------------------------------------------- 
// modulous a floating number types (n % dn)
double n = fmod(num , denum);
---------------------------------------------------------------------------------------------------
//limits of integer types and help you when you handle (min/max)
int n1 =INT_MAX;  //+2147483647 //== 2*1e9 
int n2 =INT_MIN;  //-2147483647 //== -2*1e9
---------------------------------------------------------------------------------------------------
//Ceiling and flooring with double numbers
//1- Flooring
double a = 2.3;  a = floor(a);  //2
double b = -2.3; b = floor(b);  //-3
//2- ceiling
double a = 2.3;  a = ceil(a);  //3
double b = -2.3; b = ceil(b);  //-2
---------------------------------------------------------------------------------------------------
// Square Root //Time Complexity: θ(log(N))
int x = 24;
double answer;
answer = sqrt(x);
---------------------------------------------------------------------------------------------------
// max/min of three numbers //Time Complexity: O(1)
ans = max(a,max(b,c));
ans = min(a, min(b,c));
---------------------------------------------------------------------------------------------------
//GCD //Library: 'algorithm' //Time Complexity: O(log(max(value1, value2))))
int a = 6, b = 20;
int ans = __gcd(a, b); //gcd(6, 20) = 2
---------------------------------------------------------------------------------------------------
//Lowercase and Uppercase handle  //Time Complexity: O(1)
// convert 'a' to uppercase
char ch = toupper('a');  //A
// convert 'A' to lowercase
char ch = tolower('A');  //a
---------------------------------------------------------------------------------------------------
//Rounding numbers // return double type
double dUp = round(2.6);
double dDown = round(2.4);
cout << dUp;   //3
cout << dDown;   //2
---------------------------------------------------------------------------------------------------
content_copyCOPY