java数学函数Math类

  1. Math.abs(12.3);                 //12.3 返回这个数的绝对值  
  2. Math.abs(-12.3);                //12.3  
  3.   
  4. Math.copySign(1.23, -12.3);     //-1.23,返回第一个参数的量值和第二个参数的符号  
  5. Math.copySign(-12.31.23);     //12.3  
  6.   
  7. Math.signum(x);                 //如果x大于0则返回1.0,小于0则返回-1.0,等于0则返回0  
  8. Math.signum(12.3);              //1.0  
  9. Math.signum(-12.3);             //-1.0  
  10. Math.signum(0);                 //0.0  
  11.   
  12.   
  13. //指数  
  14. Math.exp(x);                    //e的x次幂  
  15. Math.expm1(x);                  //e的x次幂 - 1  
  16.   
  17. Math.scalb(x, y);               //x*(2的y次幂)  
  18. Math.scalb(12.33);            //12.3*2³  
  19.   
  20. //取整  
  21. Math.ceil(12.3);                //返回最近的且大于这个数的整数13.0  
  22. Math.ceil(-12.3);               //-12.0  
  23.   
  24. Math.floor(12.3);               //返回最近的且小于这个数的整数12.0  
  25. Math.floor(-12.3);              //-13.0  
  26.   
  27. //x和y平方和的二次方根  
  28. Math.hypot(x, y);               //√(x²+y²)  
  29.   
  30. //返回概述的二次方根  
  31. Math.sqrt(x);                   //√(x) x的二次方根  
  32. Math.sqrt(9);                   //3.0  
  33. Math.sqrt(16);                  //4.0  
  34.   
  35. //返回该数的立方根  
  36. Math.cbrt(27.0);                //3   
  37. Math.cbrt(-125.0);              //-5  
  38.   
  39. //对数函数  
  40. Math.log(e);                    //1 以e为底的对数  
  41. Math.log10(100);                //10 以10为底的对数  
  42. Math.log1p(x);                  //Ln(x+ 1)  
  43.   
  44. //返回较大值和较小值  
  45. Math.max(x, y);                 //返回x、y中较大的那个数  
  46. Math.min(x, y);                 //返回x、y中较小的那个数  
  47.   
  48. //返回 x的y次幂  
  49. Math.pow(x, y);                   
  50. Math.pow(23);                 //即2³ 即返回:8  
  51.   
  52. //随机返回[0,1)之间的无符号double值  
  53. Math.random();                    
  54.   
  55. //返回最接近这个数的整数,如果刚好居中,则取偶数  
  56. Math.rint(12.3);                //12.0   
  57. Math.rint(-12.3);               //-12.0  
  58. Math.rint(78.9);                //79.0  
  59. Math.rint(-78.9);               //-79.0  
  60. Math.rint(34.5);                //34.0  
  61. Math.rint(35.5);                //36.0  
  62.   
  63. Math.round(12.3);               //与rint相似,返回值为long  
  64.   
  65. //三角函数  
  66. Math.sin(α);                    //sin(α)的值  
  67. Math.cos(α);                    //cos(α)的值  
  68. Math.tan(α);                    //tan(α)的值  
  69.   
  70. //求角  
  71. Math.asin(x/z);                 //返回角度值[-π/2,π/2]  arc sin(x/z)  
  72. Math.acos(y/z);                 //返回角度值[0~π]   arc cos(y/z)  
  73. Math.atan(y/x);                 //返回角度值[-π/2,π/2]  
  74. Math.atan2(y-y0, x-x0);         //同上,返回经过点(x,y)与原点的的直线和经过点(x0,y0)与原点的直线之间所成的夹角  
  75.   
  76. Math.sinh(x);                   //双曲正弦函数sinh(x)=(exp(x) - exp(-x)) / 2.0;  
  77. Math.cosh(x);                   //双曲余弦函数cosh(x)=(exp(x) + exp(-x)) / 2.0;  
  78. Math.tanh(x);                   //tanh(x) = sinh(x) / cosh(x);  
  79.   
  80. //角度弧度互换  
  81. Math.toDegrees(angrad);         //角度转换成弧度,返回:angrad * 180d / PI  
  82.   
  83. Math.toRadians(angdeg);         //弧度转换成角度,返回:angdeg / 180d * PI  

猜你喜欢

转载自blog.csdn.net/chehec2010/article/details/80687122