zoukankan      html  css  js  c++  java
  • 数学函数

    三角函数方法

      Math 类中三角函数方法:

    1. Math.toDegrees(Math.PI / 2)返回90.0
    2. Math.toRadians(30)返回0.5236(PI / 6)
    3. Math.sin(0)返回0.0
    4. Math.sin(Math.toRadians(270)返回-1.0
    5. Math.sin(Math.PI / 6)返回0.5
    6. Math.sin(Math.PI/2)返回1.0
    7. Math.cos(0)返回1.0
    8. Math.cos(Math.PI / 6)返回0.866
    9. Math.cos(Math.PI / 2)返回0
    10. Math.asin(0.5)返回0.523598333(PI/ 6)
    11. Math.acos(0.5)返回1.0472(PI/3)
    12. Math.atan(1.0)返回0.785398(PI/)

      指数函数:

    1. exp(x);
    2. log(x);
    3. log10(x);
    4. pow(a,b);
    5. sqrt(x);

      取整函数(返回都是双精度):

    1. 向上取整  ceil(x)     Math.ceil(2.1)返回3.0    Math.ceil(-2.1)返回-2.0
    2. 向下取整       floor(x)   Math.floor(2.1)返回2.0   Math.floor(-2.1)返回-3.0
    3. 取整为它最接近的整数。如果x与两个整数相等,偶数的整数作为返回值  

        Math.rint(2.1)返回2.0  Math.rint(-2.1)返回-2.0  Math.rint(2.5)返回2.0  Math.rint(2.6)返回3.0  Math.rint(1.5)返回2.0

      4.  round(x)  如果x是单精度数,返回(int)Math.floor(x+0.5);如果x是双精度数,返回(long)Math.floor(x+0.5)

        Math.round(2.6f)返回3  Math.round(2.0)返回2  Math.round(-2.4)返回-2

      min、max和abs方法:

    1. min和max方法用于返回两个数(int、long、float或double型)的最小值和最大值。
    2. abs方法以返回一个数(int、long、float或double型)的绝对值。

        Math.max(2, 3)  return 3;  Math.min(2.5, 4.6)  return 2.5;  

        Math.max(Math.max(2.5, 4.6), Math.min(3, 5.6))  return 4.6;

        Math.abs(-2)  return 2;

      random方法:

      1. a+Math.random() * b  返回a~a+b之间的一个随机数,不包括a+b

  • 相关阅读:
    Linux C++ 处理 Kill 信号、Ctrl+C信号,便于安全退出
    静态链接libcurl的步骤
    编译器如何C++的函数重载
    单链表逆序 也叫反转
    VC 创建拨号连接A
    强大的vim配置,让编程更随意
    已知二叉树后序遍历序列是DBCEFGHA,中序遍历序列EDCBAHFG,它的前序遍历的序列是?麻烦再画下这二叉树.
    怎样使用IPV6编程
    全面详细介绍libcurl的使用
    ZeroMQ全面介绍
  • 原文地址:https://www.cnblogs.com/King-boy/p/10498558.html
Copyright © 2011-2022 走看看