C# Math类详细说明

1、Math.Cos(X) 
 
函数中的X 都是指的“弧度”而非“角度”,弧度的计算公式为: 2*PI/360*角度,例如:X° 角度 的弧度为2*PI/360*X或者 Math.Cos(Math.PI * X° / 180) 
 

Math.sin(x)      x 的正玄值。返回值在 -1.0 到 1.0 之间;

Math.cos(x)    x 的余弦值。返回的是 -1.0 到 1.0 之间的数;

 

2、其他方法说明
 
名称说明
Abs(Decimal)返回 Decimal 数字的绝对值。
Abs(Double)返回双精度浮点数字的绝对值。
Abs(Int16)返回 16 位有符号整数的绝对值。
Abs(Int32)返回 32 位有符号整数的绝对值。
Abs(Int64)返回 64 位有符号整数的绝对值。
Abs(SByte)返回 8 位有符号整数的绝对值。
Abs(Single)返回单精度浮点数字的绝对值。
Acos返回余弦值为指定数字的角度。
Asin返回正弦值为指定数字的角度。
Atan返回正切值为指定数字的角度。
Atan2返回正切值为两个指定数字的商的角度。
BigMul生成两个 32 位数字的完整乘积。
Ceiling(Decimal)返回大于或等于指定的十进制数的最小整数值。
Ceiling(Double)返回大于或等于指定的双精度浮点数的最小整数值。
Cos返回指定角度的余弦值。
Cosh返回指定角度的双曲余弦值。
DivRem(Int32, Int32, Int32)计算两个 32 位有符号整数的商,并通过输出参数返回余数。
DivRem(Int64, Int64, Int64)计算两个 64 位有符号整数的商,并通过输出参数返回余数。
Exp返回 e 的指定次幂。
Floor(Decimal)返回小于或等于指定小数的最大整数。
Floor(Double)返回小于或等于指定双精度浮点数的最大整数。
IEEERemainder返回一指定数字被另一指定数字相除的余数。
Log(Double)返回指定数字的自然对数(底为 e)。
Log(Double, Double)返回指定数字在使用指定底时的对数。
Log10返回指定数字以 10 为底的对数。
Max(Byte, Byte)返回两个 8 位无符号整数中较大的一个。
Max(Decimal, Decimal)返回两个十进制数中较大的一个。
Max(Double, Double)返回两个双精度浮点数字中较大的一个。
Max(Int16, Int16)返回两个 16 位有符号的整数中较大的一个。
Max(Int32, Int32)返回两个 32 位有符号的整数中较大的一个。
Max(Int64, Int64)返回两个 64 位有符号的整数中较大的一个。
Max(SByte, SByte)返回两个 8 位有符号的整数中较大的一个。
Max(Single, Single)返回两个单精度浮点数字中较大的一个。
Max(UInt16, UInt16)返回两个 16 位无符号整数中较大的一个。
Max(UInt32, UInt32)返回两个 32 位无符号整数中较大的一个。
Max(UInt64, UInt64)返回两个 64 位无符号整数中较大的一个。
Min(Byte, Byte)返回两个 8 位无符号整数中较小的一个。
Min(Decimal, Decimal)返回两个十进制数中较小的一个。
Min(Double, Double)返回两个双精度浮点数字中较小的一个。
Min(Int16, Int16)返回两个 16 位有符号整数中较小的一个。
Min(Int32, Int32)返回两个 32 位有符号整数中较小的一个。
Min(Int64, Int64)返回两个 64 位有符号整数中较小的一个。
Min(SByte, SByte)返回两个 8 位有符号整数中较小的一个。
Min(Single, Single)返回两个单精度浮点数字中较小的一个。
Min(UInt16, UInt16)返回两个 16 位无符号整数中较小的一个。
Min(UInt32, UInt32)返回两个 32 位无符号整数中较小的一个。
Min(UInt64, UInt64)返回两个 64 位无符号整数中较小的一个。
Pow返回指定数字的指定次幂。
Round(Decimal)将小数值舍入到最接近的整数值。
Round(Double)将双精度浮点值舍入为最接近的整数值。
Round(Decimal, Int32)将小数值按指定的小数位数舍入。
Round(Decimal, MidpointRounding)将小数值舍入到最接近的整数。 一个参数,指定当一个值正好处于两个数中间时如何舍入这个值。
Round(Double, Int32)将双精度浮点值按指定的小数位数舍入。
Round(Double, MidpointRounding)将双精度浮点值舍入为最接近的整数。 一个参数,指定当一个值正好处于两个数中间时如何舍入这个值。
Round(Decimal, Int32, MidpointRounding)将小数值按指定的小数位数舍入。 一个参数,指定当一个值正好处于两个数中间时如何舍入这个值。
Round(Double, Int32, MidpointRounding)将双精度浮点值按指定的小数位数舍入。 一个参数,指定当一个值正好处于两个数中间时如何舍入这个值。
Sign(Decimal)返回表示数字符号的值。
Sign(Double)返回表示双精度浮点数字的符号的值。
Sign(Int16)返回表示 16 位有符号整数的符号的值。
Sign(Int32)返回表示 32 位有符号整数的符号的值。
Sign(Int64)返回表示 64 位有符号整数的符号的值。
Sign(SByte)返回表示 8 位有符号整数的符号的值。
Sign(Single)返回表示单精度浮点数字的符号的值。
Sin返回指定角度的正弦值。
Sinh返回指定角度的双曲正弦值。
Sqrt返回指定数字的平方根。
Tan返回指定角度的正切值。
Tanh返回指定角度的双曲正切值。
Truncate(Decimal)计算指定小数的整数部分。
Truncate(Double)计算指定双精度浮点数的整数部分。
 
3、MSDN示例
/// <summary>
/// The following class represents simple functionality of the trapezoid.
/// </summary> using System; namespace MathClassCS { class MathTrapezoidSample { private double m_longBase; private double m_shortBase; private double m_leftLeg; private double m_rightLeg; public MathTrapezoidSample(double longbase, double shortbase, double leftLeg, double rightLeg) { m_longBase = Math.Abs(longbase); m_shortBase = Math.Abs(shortbase); m_leftLeg = Math.Abs(leftLeg); m_rightLeg = Math.Abs(rightLeg); } private double GetRightSmallBase() { return (Math.Pow(m_rightLeg,2.0) - Math.Pow(m_leftLeg,2.0) + Math.Pow(m_longBase,2.0) + Math.Pow(m_shortBase,2.0) - 2* m_shortBase * m_longBase)/ (2*(m_longBase - m_shortBase)); } public double GetHeight() { double x = GetRightSmallBase(); return Math.Sqrt(Math.Pow(m_rightLeg,2.0) - Math.Pow(x,2.0)); } public double GetSquare() { return GetHeight() * m_longBase / 2.0; } public double GetLeftBaseRadianAngle() { double sinX = GetHeight()/m_leftLeg; return Math.Round(Math.Asin(sinX),2); } public double GetRightBaseRadianAngle() { double x = GetRightSmallBase(); double cosX = (Math.Pow(m_rightLeg,2.0) + Math.Pow(x,2.0) - Math.Pow(GetHeight(),2.0))/(2*x*m_rightLeg); return Math.Round(Math.Acos(cosX),2); } public double GetLeftBaseDegreeAngle() { double x = GetLeftBaseRadianAngle() * 180/ Math.PI; return Math.Round(x,2); } public double GetRightBaseDegreeAngle() { double x = GetRightBaseRadianAngle() * 180/ Math.PI; return Math.Round(x,2); } static void Main(string[] args) { MathTrapezoidSample trpz = new MathTrapezoidSample(20.0, 10.0, 8.0, 6.0); Console.WriteLine("The trapezoid's bases are 20.0 and 10.0, the trapezoid's legs are 8.0 and 6.0"); double h = trpz.GetHeight(); Console.WriteLine("Trapezoid height is: " + h.ToString()); double dxR = trpz.GetLeftBaseRadianAngle(); Console.WriteLine("Trapezoid left base angle is: " + dxR.ToString() + " Radians"); double dyR = trpz.GetRightBaseRadianAngle(); Console.WriteLine("Trapezoid right base angle is: " + dyR.ToString() + " Radians"); double dxD = trpz.GetLeftBaseDegreeAngle(); Console.WriteLine("Trapezoid left base angle is: " + dxD.ToString() + " Degrees"); double dyD = trpz.GetRightBaseDegreeAngle(); Console.WriteLine("Trapezoid left base angle is: " + dyD.ToString() + " Degrees"); } } } 

转载于:https://www.cnblogs.com/wcnm/p/3907600.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编程实例 MICROSOFT SOFTWARE LICENSE TERMS Microsoft Visual Studio 2005 and .NET Framework 2.0 Samples These license terms are an agreement between Microsoft Corporation (or based on where you live, one of its affiliates) and you. Please read them. They apply to the software named above, which includes the media on which you received it, if any. The terms also apply to any Microsoft * updates, * supplements, * Internet-based services, and * support services for this software, unless other terms accompany those items. If so, those terms apply. BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS. IF YOU DO NOT ACCEPT THEM, DO NOT USE THE SOFTWARE. If you comply with these license terms, you have the rights below. 1. INSTALLATION AND USE RIGHTS. You may install and use any number of copies of the software on your devices. 2. ADDITIONAL LICENSING REQUIREMENTS AND/OR USE RIGHTS. a. Distributable Code. The software contains code that you are permitted to distribute in programs you develop if you comply with the terms below. i. Right to Use and Distribute. The code and text files listed below are 揇istributable Code.? * Sample Code. You may modify, copy, and distribute the source and object code form of the sample source code included in the subfolders of the project files. * Third Party Distribution. You may permit distributors of your programs to copy and distribute the Distributable Code as part of those programs. ii. Distribution Requirements. For any Distributable Code you distribute, you must * add significant primary functionality to it in your programs; * require distributors and external end users to agree to terms that protect it at least as much as this agreement; * display your valid copyright notice on your programs; and * indemnify, defend, and hold harmless Microsoft from any claims, including attorneys?fees, related to the distribution or use of your programs. iii. Distribution Restrictions. You may not * alter any copyright, trademark or patent notice in the Distributable Code; * use Microsoft抯 trademarks in your programs?names or in a way that suggests your programs come from or are endorsed by Microsoft; * distribute Distributable Code to run on a platform other than the Windows platform; * include Distributable Code in malicious, deceptive or unlawful programs; or * modify or distribute the source code of any Distributable Code so that any part of it becomes subject to an Excluded License. An Excluded License is one that requires, as a condition of use, modification or distribution, that * the code be disclosed or distributed in source code form; or * others have the right to modify it. 3. SCOPE OF LICENSE. The software is licensed, not sold. This agreement only gives you some rights to use the software. Microsoft reserves all other rights. Unless applicable law gives you more rights despite this limitation, you may use the software only as expressly permitted in this agreement. In doing so, you must comply with any technical limitations in the software that only allow you to use it in certain ways. You may not * work around any technical limitations in the software; * reverse engineer, decompile or disassemble the software, except and only to the extent that applicable law expressly permits, despite this limitation; * make more copies of the software than specified in this agreement or allowed by applicable law, despite this limitation; * publish the software for others to copy; * rent, lease or lend the software; * transfer the software or this agreement to any third party; or * use the software for commercial software hosting services. 4. BACKUP COPY. You may make one backup copy of the software. You may use it only to reinstall the software. 5. DOCUMENTATION. Any person that has valid access to your computer or internal network may copy and use the documentation for your internal, reference purposes. 6. EXPORT RESTRICTIONS. The software is subject to United States export laws and regulations. You must comply with all domestic and international export laws and regulations that apply to the software. These laws include restrictions on destinations, end users and end use. For additional information, see www.microsoft.com/exporting. 7. SUPPORT SERVICES. Because this software is 揳s is,?we may not provide support services for it. 8. ENTIRE AGREEMENT. This agreement, and the terms for supplements, updates, Internet-based services and support services that you use, are the entire agreement for the software and support services. 9. APPLICABLE LAW. a. United States. If you acquired the software in the United States, Washington state law governs the interpretation of this agreement and applies to claims for breach of it, regardless of conflict of laws principles. The laws of the state where you live govern all other claims, including claims under state consumer protection laws, unfair competition laws, and in tort. b. Outside the United States. If you acquired the software in any other country, the laws of that country apply. 10. LEGAL EFFECT. This agreement describes certain legal rights. You may have other rights under the laws of your country. You may also have rights with respect to the party from whom you acquired the software. This agreement does not change your rights under the laws of your country if the laws of your country do not permit it to do so. 11. DISCLAIMER OF WARRANTY. THE SOFTWARE IS LICENSED 揂S-IS.? YOU BEAR THE RISK OF USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES OR CONDITIONS. YOU MAY HAVE ADDITIONAL CONSUMER RIGHTS UNDER YOUR LOCAL LAWS WHICH THIS AGREEMENT CANNOT CHANGE. TO THE EXTENT PERMITTED UNDER YOUR LOCAL LAWS, MICROSOFT EXCLUDES THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 12. LIMITATION ON AND EXCLUSION OF REMEDIES AND DAMAGES. YOU CAN RECOVER FROM MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, INDIRECT OR INCIDENTAL DAMAGES. This limitation applies to * anything related to the software, services, content (including code) on third party Internet sites, or third party programs; and * claims for breach of contract, breach of warranty, guarantee or condition, strict liability, negligence, or other tort to the extent permitted by applicable law. It also applies even if Microsoft knew or should have known about the possibility of the damages. The above limitation or exclusion may not apply to you because your country may not allow the exclusion or limitation of incidental, consequential or other damages. Please note: As this software is distributed in Quebec, Canada, some of the clauses in this agreement are provided below in French. Remarque : Ce logiciel 閠ant distribu?au Qu閎ec, Canada, certaines des clauses dans ce contrat sont fournies ci-dessous en fran鏰is. EXON蒖ATION DE GARANTIE. Le logiciel vis?par une licence est offert ?tel quel ? Toute utilisation de ce logiciel est ?votre seule risque et p閞il. Microsoft n抋ccorde aucune autre garantie expresse. Vous pouvez b閚閒icier de droits additionnels en vertu du droit local sur la protection dues consommateurs, que ce contrat ne peut modifier. La ou elles sont permises par le droit locale, les garanties implicites de qualit?marchande, d抋d閝uation ?un usage particulier et d抋bsence de contrefa鏾n sont exclues. LIMITATION DES DOMMAGES-INT蒖蔜S ET EXCLUSION DE RESPONSABILIT?POUR LES DOMMAGES. Vous pouvez obtenir de Microsoft et de ses fournisseurs une indemnisation en cas de dommages directs uniquement ?hauteur de 5,00 $ US. Vous ne pouvez pr閠endre ?aucune indemnisation pour les autres dommages, y compris les dommages sp閏iaux, indirects ou accessoires et pertes de b閚閒ices. Cette limitation concerne : * tout ce qui est reli?au logiciel, aux services ou au contenu (y compris le code) figurant sur des sites Internet tiers ou dans des programmes tiers ; et * les r閏lamations au titre de violation de contrat ou de garantie, ou au titre de responsabilit?stricte, de n間ligence ou d抲ne autre faute dans la limite autoris閑 par la loi en vigueur. Elle s抋pplique 間alement, m阭e si Microsoft connaissait ou devrait conna顃re l掗ventualit?d抲n tel dommage. Si votre pays n抋utorise pas l抏xclusion ou la limitation de responsabilit?pour les dommages indirects, accessoires ou de quelque nature que ce soit, il se peut que la limitation ou l抏xclusion ci-dessus ne s抋ppliquera pas ?votre 間ard. EFFET JURIDIQUE. Le pr閟ent contrat d閏rit certains droits juridiques. Vous pourriez avoir d抋utres droits pr関us par les lois de votre pays. Le pr閟ent contrat ne modifie pas les droits que vous conf鑢ent les lois de votre pays si celles ci ne le permettent pas.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值