• C# Math类简介运用


    总结了一下几个常用的Math类

    /*
                   #########                       
                  ############                     
                  #############                    
                 ##  ###########                   
                ###  ###### #####                  
                ### #######   ####                 
               ###  ########## ####                
              ####  ########### ####               
             ####   ###########  #####             
            #####   ### ########   #####           
           #####   ###   ########   ######         
          ######   ###  ###########   ######       
         ######   #### ##############  ######      
        #######  #####################  ######     
        #######  ######################  ######    
       #######  ###### #################  ######   
       #######  ###### ###### #########   ######   
       #######    ##  ######   ######     ######   
       #######        ######    #####     #####    
        ######        #####     #####     ####     
         #####        ####      #####     ###      
          #####       ###        ###      #        
            ###       ###        ###              
             ##       ###        ###               
    __________#_______####_______####______________
    
                    我们的未来没有BUG              
    * ==============================================================================
    * Filename: Maths
    * Created:  2017/4/27
    * Author:   ShangHai WangYuChen
    * ==============================================================================
    */
    using UnityEngine;
    using System.Collections;
    using System;
    
    public class Maths : MonoBehaviour {
    	void Start () {
            /*银行家舍入:四舍六入五取偶法*/
            //取整、保留小数等数字处理方法
            //double maths = Math.Round(11.635, 0);
            double Round = Math.Round(11.535, 2);
            Debug.Log("取舍: " + Round);
            //取整
            double ToInt32 = Convert.ToInt32(3.5);
            Debug.Log("取整: " + ToInt32);
            //计算绝对值
            double Abs = Math.Abs(-45.36);
            Debug.Log("计算绝对值: " + Abs);
            //计算从x 坐标轴到点的角度
            double Atan2 = Math.Atan2(45,32);
            Debug.Log("计算从x 坐标轴到点的角度: " + Atan2);
            //计算余弦值
            double Cos = Math.Cos(45);
            Debug.Log("计算余弦值: " + Cos);
            //计算正弦值
            double Sin = Math.Sin(45);
            Debug.Log("计算正弦值: " + Sin);
            //计算正切值
            double Tan = Math.Tan(45);
            Debug.Log("计算正切值: " + Tan);
            //计算平方根。 
            double Sqrt = Math.Sqrt(100);
            Debug.Log("计算平方根: " + Sqrt);
            //计算x 的y 次方
            double Pow = Math.Pow(3,2);
            Debug.Log("计算x 的y 次方: " + Pow);
            //计算自然对数
            double Log = Math.Log(6);
            Debug.Log("计算自然对数: " + Log);
            //返回两个整数中较大的一个
            double Max = Math.Max(3,8);
            Debug.Log("返回两个整数中较大的一个: " + Max);
            //返回两个整数中较小的一个
            double Min = Math.Min(3,8);
            Debug.Log("返回两个整数中较小的一个: " + Min);
            //将数字向上舍入为最接近的整数
            double Ceiling = Math.Ceiling(45.36);
            Debug.Log("将数字向上舍入为最接近的整数: " + Ceiling);
            //将数字向下舍入为最接近的整数
            double Floor = Math.Floor(45.36);
            Debug.Log("将数字向下舍入为最接近的整数: " + Floor);
            //返回一个0 与10 之间的伪随机数
            System.Random rr = new System.Random();
            Debug.Log("返回一个0.0 与1.0 之间的伪随机数: " + rr.Next(0, 10)); 
        }
    }
    

      

  • 相关阅读:
    类和函数傻傻分不清楚?三个例子讲明白
    使用Python进行数据降维|线性降维
    上班摸鱼系列|Python开发命令行斗地主
    常用统计检验的Python实现
    快速提高Python数据分析速度的八个技巧
    Python解放双手系列——用python自动追踪你的快递
    收下这份来自GitHub的神器,一图搞定Matplotlib!
    mysql插入中文乱码
    DeepLearning4J
    jsp标签之jsp:setProperty用法
  • 原文地址:https://www.cnblogs.com/mclll520/p/6776092.html
Copyright © 2020-2023  润新知