|
@ -21,17 +21,15 @@ float cube(float x) { |
|
|
return x * x * x; |
|
|
return x * x * x; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Function to calculate the cube root of a number |
|
|
|
|
|
|
|
|
|
|
|
float cubeRoot(float x) { |
|
|
float cubeRoot(float x) { |
|
|
return cbrt(x); |
|
|
return cbrt(x); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Function to calculate the absolute value of a number |
|
|
|
|
|
float absolute(float x) { |
|
|
float absolute(float x) { |
|
|
return fabs(x); |
|
|
return fabs(x); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Function to calculate the logarithm (base 10) of a number |
|
|
|
|
|
float logarithm(float x) { |
|
|
float logarithm(float x) { |
|
|
if (x > 0) { |
|
|
if (x > 0) { |
|
|
return log10(x); |
|
|
return log10(x); |
|
@ -41,7 +39,6 @@ return 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Function to calculate the natural logarithm (base e) of a number |
|
|
|
|
|
float naturalLogarithm(float x) { |
|
|
float naturalLogarithm(float x) { |
|
|
if (x > 0) { |
|
|
if (x > 0) { |
|
|
return log(x); |
|
|
return log(x); |
|
@ -51,8 +48,6 @@ return 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Function to calculate the factorial of a number |
|
|
|
|
|
int factorial(int x) { |
|
|
int factorial(int x) { |
|
|
if (x >= 0) { |
|
|
if (x >= 0) { |
|
|
int result = 1; |
|
|
int result = 1; |
|
@ -66,37 +61,30 @@ return 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Function to calculate the floor value of a number |
|
|
|
|
|
float floorValue(float x) { |
|
|
float floorValue(float x) { |
|
|
return floor(x); |
|
|
return floor(x); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Function to calculate the ceiling value of a number |
|
|
|
|
|
float ceilingValue(float x) { |
|
|
float ceilingValue(float x) { |
|
|
return ceil(x); |
|
|
return ceil(x); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Function to calculate the absolute difference between two numbers |
|
|
|
|
|
float absoluteDifference(float x, float y) { |
|
|
float absoluteDifference(float x, float y) { |
|
|
return fabs(x - y); |
|
|
return fabs(x - y); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Function to calculate the maximum of two numbers |
|
|
|
|
|
float maximum(float x, float y) { |
|
|
float maximum(float x, float y) { |
|
|
return fmax(x, y); |
|
|
return fmax(x, y); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Function to calculate the minimum of two numbers |
|
|
|
|
|
float minimum(float x, float y) { |
|
|
float minimum(float x, float y) { |
|
|
return fmin(x, y); |
|
|
return fmin(x, y); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Function to calculate the average of two numbers |
|
|
|
|
|
float average(float x, float y) { |
|
|
float average(float x, float y) { |
|
|
return (x + y) / 2; |
|
|
return (x + y) / 2; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Function to calculate the remainder of division between two numbers |
|
|
|
|
|
float remainderValue(float x, float y) { |
|
|
float remainderValue(float x, float y) { |
|
|
return fmod(x, y); |
|
|
return fmod(x, y); |
|
|
} |
|
|
} |