• c/c++中数学函数


    1.

    abs
      原型:extern int abs(int x);
      
      用法:#include <math.h>
      
      功能:求整数x的绝对值
      
      说明:计算|x|, 当x不为负时返回x,否则返回-x
      
      举例:
    
          // abs.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            int x;
            
            clrscr();        // clear screen
            
            x=-5;
            printf("|%d|=%d
    ",x,abs(x));
            x=0;
            printf("|%d|=%d
    ",x,abs(x));
            x=+5;
            printf("|%d|=%d
    ",x,abs(x));
            
            getchar();
            return 0;
          }

     2.

    acos
      原型:extern float acos(float x);
      
      用法:#include <math.h>
      
      功能:求x(弧度表示)的反余弦值
      
      说明:x的定义域为[-1.0,1.0],值域为[0,π]。
      
      举例:
    
          // acos.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            x=0.32;
            printf("acos(%.2f)=%.4f",x,acos(x));
            
            getchar();
            return 0;
          }

    3.

    asin
      原型:extern float asin(float x);
      
      用法:#include <math.h>
      
      功能:求x(弧度表示)的反正弦值
      
      说明:x的定义域为[-1.0,1.0],值域为[-π/2,+π/2]。
      
      举例:
    
          // asin.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            x=0.32;
            printf("asin(%.2f)=%.4f",x,asin(x));
            
            getchar();
            return 0;
          }
          

    4.

    atan
      原型:extern float atan(float x);
      
      用法:#include <math.h>
      
      功能:求x(弧度表示)的反正切值
      
      说明:值域为(-π/2,+π/2)。
      
      举例:
    
          // atan.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            x=0.32;
            printf("atan(%.2f)=%.4f",x,atan(x));
            
            getchar();
            return 0;
          }

     5.

    atan2
      原型:extern float atan2(float y, float x);
      
      用法:#include <math.h>
      
      功能:求y/x(弧度表示)的反正切值
      
      说明:值域为(-π/2,+π/2)。
      
      举例:
    
          // atan2.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x,y;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            x=0.064;
            y=0.2;
            printf("atan2(%.3f,%.2f)=%.4f",y,x,atan2(y,x));
            
            getchar();
            return 0;
          }
          

     6.

    ceil
      原型:extern float ceil(float x);
      
      用法:#include <math.h>
      
      功能:求不小于x的最小整数
      
      说明:返回x的上限,如74.12的上限为75,-74.12的上限为-74。返回值为float类型。
      
      举例:
    
          // ceil.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            x=74.12;
            printf("ceil(%.2f)=%.0f
    ",x,ceil(x));
            x=-74.12;
            printf("ceil(%.2f)=%.0f
    ",x,ceil(x));
            
            getchar();
            return 0;
          }

     7.

    cos
      原型:extern float cos(float x);
      
      用法:#include <math.h>
      
      功能:求x(弧度表示)的余弦值
      
      说明:返回值在[-1.0,1.0]之间。
      
      举例:
    
          // cos.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            x=PI/4.;
            printf("cos(%.4f)=%.4f
    ",x,cos(x));
            
            getchar();
            return 0;
          }

     8.

    cosh
      原型:extern float cosh(float x);
      
      用法:#include <math.h>
      
      功能:求x的双曲余弦值
      
      说明:cosh(x)=(e^x+e^(-x))/2
      
      举例:
    
          // cosh.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            x=PI/4.;
            printf("cosh(%.4f)=%.4f
    ",x,cosh(x));
            
            getchar();
            return 0;
          }

     9.

    exp
      原型:extern float exp(float x);
      
      用法:#include <math.h>
      
      功能:求e的x次幂
      
      说明:e=2.718281828...
      
      举例:
    
          // exp.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            printf("e=%f
    ",exp(1.0));
            
            getchar();
            return 0;
          }
          

     10.

    fabs
      原型:extern float fabs(float x);
      
      用法:#include <math.h>
      
      功能:求浮点数x的绝对值
      
      说明:计算|x|, 当x不为负时返回x,否则返回-x
      
      举例:
    
          // fabs.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            x=-74.12;
            printf("|%f|=%f
    ",x,fabs(x));
            x=0;
            printf("|%f|=%f
    ",x,fabs(x));
            x=74.12;
            printf("|%f|=%f
    ",x,fabs(x));
            
            getchar();
            return 0;
          }

     11.

    floor
      原型:extern float floor(float x);
      
      用法:#include <math.h>
      
      功能:求不大于x的最达整数
      
      说明:返回x的下限,如74.12的下限为74,-74.12的下限为-75。返回值为float类型。
      
      举例:
    
          // floor.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            x=74.12;
            printf("floor(%.2f)=%.0f
    ",x,floor(x));
            x=-74.12;
            printf("floor(%.2f)=%.0f
    ",x,floor(x));
            
            getchar();
            return 0;
          }
          

    12.

    fmod
      原型:extern float fmod(float x, float y);
      
      用法:#include <math.h>
      
      功能:计算x/y的余数
      
      说明:返回x-n*y,符号同y。n=[x/y](向离开零的方向取整)
      
      举例:
    
          // fmod.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x,y;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
    
            x=74.12;
            y=6.4;
            printf("74.12/6.4: %f
    ",fmod(x,y));        
            x=74.12;
            y=-6.4;
            printf("74.12/(-6.4): %f
    ",fmod(x,y));        
            
            getchar();
            return 0;
          }

     13.

    frexp
      原型:extern float frexp(float x, int *exp);
      
      用法:#include <math.h>
      
      功能:把浮点数x分解成尾数和指数。
      
      说明:x=m*2^exp,m为规格化小数。返回尾数m,并将指数存入exp中。
      
      举例:
    
          // frexp.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            int exp;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
          
            x=frexp(64.0,&exp);
            printf("64=%.2f*2^%d",x,exp);
            
            getchar();
            return 0;
          }
          

     14.

    hypot
      原型:extern float hypot(float x, float y);
      
      用法:#include <math.h>
      
      功能:对于给定的直角三角形的两个直角边,求其斜边的长度。
      
      说明:返回斜边值。
      
      举例:
    
          // hypot.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
          
            printf("3^2+4^2=%.0f^2
    ",hypot(3.,4.));
            printf("3.2^2+4.3^2=%.2f^2",hypot(x,y));
            
            getchar();
            return 0;
          }

     15.

    ldexp
      原型:extern float ldexp(float x, int exp);
      
      用法:#include <math.h>
      
      功能:装载浮点数。
      
      说明:返回x*2^exp的值。
      
      举例:
    
          // ldexp.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
          
            x=ldexp(1.0,6);  // 1.0*2^6
            printf("2^6=%.2f",x);
            
            getchar();
            return 0;
          }
          

     16.

    log
      原型:extern float log(float x);
      
      用法:#include <math.h>
      
      功能:计算x的自然对数。
      
      说明:x的值应大于零。
      
      举例:
    
          // log.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
          
            printf("ln(e)=%f
    ", log(M_E));  // M_E is 2.71828..., defined in math.h
            
            getchar();
            return 0;
          }
          

     17.

    log10
      原型:extern float log10(float x);
      
      用法:#include <math.h>
      
      功能:计算x的常用对数。
      
      说明:x的值应大于零。
      
      举例:
    
          // log10.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
          
            printf("lg(5)=%f
    ", log10(5.0));
            
            getchar();
            return 0;
          }
          

     18.

    modf
      原型:extern float modf(float num, float *i);
      
      用法:#include <math.h>
      
      功能:将浮点数num分解成整数部分和小数部分。
      
      说明:返回小数部分,将整数部分存入*i所指内存中。
      
      举例:
    
          // modf.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x, i;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
          
            x=modf(-74.12,&i);
            printf("-74.12=%.0f+(%.2f)",i,x);
            
            getchar();
            return 0;
          }
          

     19.

    pow
      原型:extern float pow(float x, float y);
      
      用法:#include <math.h>
      
      功能:计算x的y次幂。
      
      说明:x应大于零,返回幂指数的结果。
      
      举例:
    
          // pow.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
          
            printf("4^5=%f",pow(4.,5.));
            
            getchar();
            return 0;
          }
          

     20.

    pow10
      原型:extern float pow10(float x);
      
      用法:#include <math.h>
      
      功能:计算10的x次幂。
      
      说明:相当于pow(10.0,x)。
      
      举例:
    
          // pow10.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
          
            printf("10^3.2=%f
    ",pow10(3.2));
            printf("10^3.2=%f",pow(10,3.2));
            
            getchar();
            return 0;
          }
          

     21.

    sin
      原型:extern float sin(float x);
      
      用法:#include <math.h>
      
      功能:计算x(弧度表示)的正弦值。
      
      说明:x的值域为[-1.0,1.0]。
      
      举例:
    
          // sin.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
          
            x=M_PI/2;        // M_PI=PI=3.14159265..., defined in math.h
            printf("sin(PI/2)=%f",sin(x));
            
            getchar();
            return 0;
          }
          

     22.

    sinh
      原型:extern float sinh(float x);
      
      用法:#include <math.h>
      
      功能:计算x(弧度表示)的双曲正弦值。
      
      说明:sinh(x)=(e^x-e^(-x))/2。
      
      举例:
    
    
          // sinh.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            x=PI/4.;
            printf("sinh(%.4f)=%.4f
    ",x,sinh(x));
            
            getchar();
            return 0;
          }
                

     23.

    sqrt
      原型:extern float sqrt(float x);
      
      用法:#include <math.h>
      
      功能:计算x的平方根。
      
      说明:x应大于等于零。
      
      举例:
    
    
          // sqrt.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            printf("sqrt(2000)=%f",sqrt(2000.0));
            
            getchar();
            return 0;
          }
                

     24.

    tan
      原型:extern float tan(float x);
      
      用法:#include <math.h>
      
      功能:计算x(弧度表示)的正切值。
      
      说明:返回x的正切值。
      
      举例:
    
          // tan.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
          
            x=M_PI/4;        // M_PI=PI=3.14159265..., defined in math.h
            printf("tan(PI/4)=%f",tan(x));
            
            getchar();
            return 0;
          }
          

     25.

    tanh
      原型:extern float tanh(float x);
      
      用法:#include <math.h>
      
      功能:求x的双曲正切值
      
      说明:tanh(x)=(e^x-e^(-x))/(e^2+e^(-x))
      
      举例:
    
          // tanh.c
          
          #include <syslib.h>
          #include <math.h>
    
          main()
          {
            float x;
            
            clrscr();        // clear screen
            textmode(0x00);  // 6 lines per LCD screen
            
            x=PI/4.;
            printf("tanh(%.4f)=%.4f
    ",x,tanh(x));
            
            getchar();
            return 0;
          }
          
  • 相关阅读:
    haproxy实现负载均衡集群
    docker私有仓库搭建,证书认证,鉴权管理
    dockerhub私有镜像仓库harbor部署
    Delphi用窗体类名创建窗体(需要用到GetClass)
    Delphi中Class of 第二篇
    Delphi中Class of
    Delphi中ADO之初识
    Delphi遍历枚举
    二进制乘除的原理
    Delphi图像处理之图像着色
  • 原文地址:https://www.cnblogs.com/lipching/p/3860658.html
Copyright © 2020-2023  润新知