Created
January 16, 2017 18:31
-
-
Save jlindsey/a84248c3837cd20d8429ccfa776d832a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The main Math class | |
Contains all methods for performing basic math functions | |
*/ | |
/// <summary> | |
/// The main <c>Math</c> class. | |
/// Contains all methods for performing basic math functions. | |
/// </summary> | |
public class Math | |
{ | |
/// <summary> | |
/// Adds two integers and returns the result. | |
/// </summary> | |
/// <returns> | |
/// The sum of two integers. | |
/// </returns> | |
/// <example> | |
/// <code> | |
/// int c = Math.Add(4, 5); | |
/// if (c > 10) | |
/// { | |
/// Console.WriteLine(c); | |
/// } | |
/// </code> | |
/// </example> | |
/// <exception cref="System.OverflowException">Thrown when one parameter is max | |
/// and the other is greater than 0.</exception> | |
public static int Add(int a, int b) | |
{ | |
if ((a == int.MaxValue && b > 0) || (b == int.MaxValue && a > 0)) | |
throw new System.OverflowException(); | |
return a + b; | |
} | |
/// <summary> | |
/// Adds two doubles and returns the result. | |
/// </summary> | |
/// <returns> | |
/// The sum of two doubles. | |
/// </returns> | |
/// <exception cref="System.OverflowException">Thrown when one parameter is max | |
/// and the other is greater than zero.</exception> | |
public static double Add(double a, double b) | |
{ | |
if ((a == double.MaxValue && b > 0) || (b == double.MaxValue && a > 0)) | |
throw new System.OverflowException(); | |
return a + b; | |
} | |
/// <summary> | |
/// Divides an integer by another and returns the result. | |
/// </summary> | |
/// <returns> | |
/// The division of two integers. | |
/// </returns> | |
/// <exception cref="System.DivideByZeroException">Thrown when a division by zero occurs.</exception> | |
public static int Divide(int a, int b) | |
{ | |
return a / b; | |
} | |
/// <summary> | |
/// Divides a double by another and returns the result. | |
/// </summary> | |
/// <returns> | |
/// The division of two doubles. | |
/// </returns> | |
/// <exception cref="System.DivideByZeroException">Thrown when a division by zero occurs.</exception> | |
public static double Divide(double a, double b) | |
{ | |
return a / b; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment