using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace math_syan
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine(System.Math.Abs(-12.01));//绝对值
System.Console.WriteLine(System.Math.PI);//圆周率
System.Console.WriteLine(System.Math.Max(12, 14));//最大值
System.Console.WriteLine(System.Math.Min(12, 14));//最小值
System.Console.WriteLine(System.Math.Ceiling(12.34));//最高整数
System.Console.WriteLine(System.Math.Floor(12.34));//最低整数
System.Console.WriteLine(System.Math.Truncate(12.34));//取整
System.Console.WriteLine(System.Math.Acos(0.45));//余弦值
System.Console.WriteLine(System.Math.Asin(0.45));//正弦值
System.Console.WriteLine(System.Math.Atan(0.45));//正切值
System.Console.WriteLine("/*************************************/");
System.Console.WriteLine(System.Math.Sin(90));//正弦值
System.Console.WriteLine(System.Math.Sinh(90));//双曲正弦值
System.Console.WriteLine(System.Math.Tan(90));//正切值
System.Console.WriteLine(System.Math.Tanh(90));//双曲正切值
System.Console.WriteLine(System.Math.Log(3, 10));//对数
System.Console.WriteLine(System.Math.Log10(3));//以 10 为底的对
System.Console.WriteLine(System.Math.Pow(2, 10));//次幂
System.Console.WriteLine(System.Math.Sqrt(9));//平方根
System.Console.WriteLine(System.Math.Round(3.25, 1));
System.Console.WriteLine(System.Math.Round(3.15, 1));
/*Math.Round方法并不是传统意义上的4舍5入,由前两句可知。
原因是Round的默认精度控制是遵循 IEEE 标准 754 的第 4 节。这种舍入有时称为就近舍入或四舍六入五成双。
它可以将因单方向持续舍入中点值而导致的舍入误差降到最低。说的通俗点就是,逢六必进位,逢五看奇偶,奇进偶不进。*/
//如果我们希望精度的控制和我们目前的国内传统一致,请编写以下代码:
System.Console.WriteLine(System.Math.Round(3.25, 1, MidpointRounding.AwayFromZero));
System.Console.WriteLine(System.Math.Round(3.15, 1, MidpointRounding.AwayFromZero));
System.Console.ReadLine();
//http://msdn.microsoft.com/zh-cn/library/3s2d3xkk.aspx
//http://msdn.microsoft.com/zh-cn/library/ms131274.aspx
}
}
}
system_math
最新推荐文章于 2021-10-21 20:59:11 发布