本文转载链接:https://blog.csdn.net/AnthongDai/article/details/78696573
/* cos example */
#include /* printf */
#include /* cos */
#define PI 3.14159265
int main ()
{
double param, result;
param = 60.0;
result = cos ( param * PI / 180.0 );
printf ("The cosine of %f degrees is %f.\n", param, result );
return 0;
}
/* sin example */
#include /* printf */
#include /* sin */
#define PI 3.14159265
int main ()
{
double param, result;
param = 30.0;
result = sin (param*PI/180);
printf ("The sine of %f degrees is %f.\n", param, result );
return 0;
}
/* tan example */
#include /* printf */
#include /* tan */
#define PI 3.14159265
int main ()
{
double param, result;
param = 45.0;
result = tan ( param * PI / 180.0 );
printf ("The tangent of %f degrees is %f.\n", param, result );
return 0;
}
/* cos example */
/* acos example */
#include /* printf */
#include /* acos */
#define PI 3.14159265
int main ()
{
double param, result;
param = 0.5;
result = acos (param) * 180.0 / PI;
printf ("The arc cosine of %f is %f degrees.\n", param, result);
return 0;
}
/* asin example */
#include /* printf */
#include /* asin */
#define PI 3.14159265
int main ()
{
double param, result;
param = 0.5;
result = asin (param) * 180.0 / PI;
printf ("The arc sine of %f is %f degrees\n", param, result);
return 0;
}
6、atan() 反正切函数
/* atan example */
#include /* printf */
#include /* atan */
#define PI 3.14159265
int main ()
{
double param, result;
param = 1.0;
result = atan (param) * 180 / PI;
printf ("The arc tangent of %f is %f degrees\n", param, result );
return 0;
}
7、atan2() 带两个参数的反正切函数
/* atan2 example */
#include /* printf */
#include /* atan2 */
#define PI 3.14159265
int main ()
{
double x, y, result;
x = -10.0;
y = 10.0;
result = atan2 (y,x) * 180 / PI;
printf ("The arc tangent for (x=%f, y=%f) is %f degrees\n", x, y, result );
return 0;
}
双曲线函数///
* cosh example */
#include /* printf */
#include /* cosh, log */
int main ()
{
double param, result;
param = log(2.0);
result = cosh (param);
printf ("The hyperbolic cosine of %f is %f.\n", param, result );
return 0;
}
/* sinh example */
#include /* printf */
#include /* sinh, log */
int main ()
{
double param, result;
param = log(2.0);
result = sinh (param);
printf ("The hyperbolic sine of %f is %f.\n", param, result );
return 0;
}
/* cos example */
/* tanh example */
#include /* printf */
#include /* tanh, log */
int main ()
{
double param, result;
param = log(2.0);
result = tanh (param);
printf ("The hyperbolic tangent of %f is %f.\n", param, result);
return 0;
}
///指数函数与对数函数 Exponential and logarithmic functions/
/* exp example */
#include /* printf */
#include /* exp */
int main ()
{
double param, result;
param = 5.0;
result = exp (param);
printf ("The exponential value of %f is %f.\n", param, result );
return 0;
}
/* frexp example */
#include /* printf */
#include /* frexp */
int main ()
{
double param, result;
int n;
param = 8.0;
result = frexp (param , &n);
printf ("%f = %f * 2^%d\n", param, result, n);
return 0;
}
/* log example */
#include /* printf */
#include /* log */
int main ()
{
double param, result;
param = 5.5;
result = log (param);
printf ("log(%f) = %f\n", param, result );
return 0;
}
/* log10 example */
#include /* printf */
#include /* log10 */
int main ()
{
double param, result;
param = 1000.0;
result = log10 (param);
printf ("log10(%f) = %f\n", param, result );
return 0;
}
/* modf example */
#include /* printf */
#include /* modf */
int main ()
{
double param, fractpart, intpart;
param = 3.14159265;
fractpart = modf (param , &intpart);
printf ("%f = %f + %f \n", param, intpart, fractpart);
return 0;
}
/* exp2 example */
#include /* printf */
#include /* exp2 */
int main ()
{
double param, result;
param = 8.0;
result = exp2 (param);
printf ("2 ^ %f = %f.\n", param, result );
return 0;
}
/* log2 example */
#include /* printf */
#include /* log2 */
int main ()
{
double param, result;
param = 1024.0;
result = log2 (param);
printf ("log2 (%f) = %f.\n", param, result );
return 0;
}
/幂函数 Power functions//
/* pow example */
#include /* printf */
#include /* pow */
int main ()
{
printf ("7 ^ 3 = %f\n", pow (7.0, 3.0) );
printf ("4.73 ^ 12 = %f\n", pow (4.73, 12.0) );
printf ("32.01 ^ 1.54 = %f\n", pow (32.01, 1.54) );
return 0;
}
/* sqrt example */
#include /* printf */
#include /* sqrt */
int main ()
{
double param, result;
param = 1024.0;
result = sqrt (param);
printf ("sqrt(%f) = %f\n", param, result );
return 0;
}
/* cbrt example */
#include /* printf */
#include /* cbrt */
int main ()
{
double param, result;
param = 27.0;
result = cbrt (param);
printf ("cbrt (%f) = %f\n", param, result);
return 0;
}
/* hypot example */
#include /* printf */
#include /* hypot */
int main ()
{
double leg_x, leg_y, result;
leg_x = 3;
leg_y = 4;
result = hypot (leg_x, leg_y);
printf ("%f, %f and %f form a right-angled triangle.\n",leg_x,leg_y,result);
return 0;
}
/* log10 example */
#include /* printf */
#include /* log10 */
int main ()
{
double param, result;
param = 1000.0;
result = log10 (param);
printf ("log10(%f) = %f\n", param, result );
return 0;
}
/* hypot example */
#include /* printf */
#include /* hypot */
int main ()
{
double leg_x, leg_y, result;
leg_x = 3;
leg_y = 4;
result = hypot (leg_x, leg_y);
printf ("%f, %f and %f form a right-angled triangle.\n",leg_x,leg_y,result);
return 0;
}
//四舍五入与余数函数Rounding and remainder functions///
/* ceil example */
#include /* printf */
#include /* ceil */
int main ()
{
printf ( "ceil of 2.3 is %.1f\n", ceil(2.3) );
printf ( "ceil of 3.8 is %.1f\n", ceil(3.8) );
printf ( "ceil of -2.3 is %.1f\n", ceil(-2.3) );
printf ( "ceil of -3.8 is %.1f\n", ceil(-3.8) );
return 0;
}
/* floor example */
#include /* printf */
#include /* floor */
int main ()
{
printf ( "floor of 2.3 is %.1lf\n", floor (2.3) );
printf ( "floor of 3.8 is %.1lf\n", floor (3.8) );
printf ( "floor of -2.3 is %.1lf\n", floor (-2.3) );
printf ( "floor of -3.8 is %.1lf\n", floor (-3.8) );
return 0;
}
/* fmod example */
#include /* printf */
#include /* fmod */
int main ()
{
printf ( "fmod of 5.3 / 2 is %f\n", fmod (5.3,2) );
printf ( "fmod of 18.5 / 4.2 is %f\n", fmod (18.5,4.2) );
return 0;
}
/* round vs floor vs ceil vs trunc */
#include /* printf */
#include /* round, floor, ceil, trunc */
int main ()
{
const char * format = "%.1f \t%.1f \t%.1f \t%.1f \t%.1f\n";
printf ("value\tround\tfloor\tceil\ttrunc\n");
printf ("-----\t-----\t-----\t----\t-----\n");
printf (format, 2.3,round( 2.3),floor( 2.3),ceil( 2.3),trunc( 2.3));
printf (format, 3.8,round( 3.8),floor( 3.8),ceil( 3.8),trunc( 3.8));
printf (format, 5.5,round( 5.5),floor( 5.5),ceil( 5.5),trunc( 5.5));
printf (format,-2.3,round(-2.3),floor(-2.3),ceil(-2.3),trunc(-2.3));
printf (format,-3.8,round(-3.8),floor(-3.8),ceil(-3.8),trunc(-3.8));
printf (format,-5.5,round(-5.5),floor(-5.5),ceil(-5.5),trunc(-5.5));
return 0;
}
///绝对值、最小、最大 Absolute、Minimum, maximum//
/* fabs example */
#include /* printf */
#include /* fabs */
int main ()
{
printf ("The absolute value of 3.1416 is %f\n", fabs (3.1416) );
printf ("The absolute value of -10.6 is %f\n", fabs (-10.6) );
return 0;
}
// cmath's abs example
#include // std::cout
#include // std::abs
int main ()
{
std::cout << "abs (3.1416) = " << std::abs (3.1416) << '\n';
std::cout << "abs (-10.6) = " << std::abs (-10.6) << '\n';
return 0;
}
/* fmax example */
#include /* printf */
#include /* fmax */
int main ()
{
printf ("fmax (100.0, 1.0) = %f\n", fmax(100.0,1.0));
printf ("fmax (-100.0, 1.0) = %f\n", fmax(-100.0,1.0));
printf ("fmax (-100.0, -1.0) = %f\n", fmax(-100.0,-1.0));
return 0;
}
/* fmin example */
#include /* printf */
#include /* fmin */
int main ()
{
printf ("fmin (100.0, 1.0) = %f\n", fmin(100.0,1.0));
printf ("fmin (-100.0, 1.0) = %f\n", fmin(-100.0,1.0));
printf ("fmin (-100.0, -1.0) = %f\n", fmin(-100.0,-1.0));
return 0;
}