Show / Hide Table of Contents

Class MathHelper

Contains common mathematical functions and constants.

Inheritance
System.Object
MathHelper
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: OpenTK
Assembly: cs.temp.dll.dll
Syntax
public static class MathHelper

Fields

E

Defines the value of E as a System.Single.

Declaration
public const float E = 2.71828175F
Field Value
Type Description
System.Single

Log10E

Defines the base-10 logarithm of E.

Declaration
public const float Log10E = 0.4342945F
Field Value
Type Description
System.Single

Log2E

Defines the base-2 logarithm of E.

Declaration
public const float Log2E = 1.442695F
Field Value
Type Description
System.Single

Pi

Defines the value of Pi as a System.Single.

Declaration
public const float Pi = 3.14159274F
Field Value
Type Description
System.Single

PiOver2

Defines the value of Pi divided by two as a System.Single.

Declaration
public const float PiOver2 = 1.57079637F
Field Value
Type Description
System.Single

PiOver3

Defines the value of Pi divided by three as a System.Single.

Declaration
public const float PiOver3 = 1.04719758F
Field Value
Type Description
System.Single

PiOver4

Definesthe value of Pi divided by four as a System.Single.

Declaration
public const float PiOver4 = 0.7853982F
Field Value
Type Description
System.Single

PiOver6

Defines the value of Pi divided by six as a System.Single.

Declaration
public const float PiOver6 = 0.5235988F
Field Value
Type Description
System.Single

ThreePiOver2

Defines the value of Pi multiplied by 3 and divided by two as a System.Single.

Declaration
public const float ThreePiOver2 = 4.712389F
Field Value
Type Description
System.Single

TwoPi

Defines the value of Pi multiplied by two as a System.Single.

Declaration
public const float TwoPi = 6.28318548F
Field Value
Type Description
System.Single

Methods

ApproximatelyEqual(Single, Single, Int32)

Approximates floating point equality with a maximum number of different bits. This is typically used in place of an epsilon comparison. see: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ see: https://stackoverflow.com/questions/3874627/floating-point-comparison-functions-for-c-sharp

Declaration
public static bool ApproximatelyEqual(float a, float b, int maxDeltaBits)
Parameters
Type Name Description
System.Single a

the first value to compare

System.Single b

the second value to compare

System.Int32 maxDeltaBits

the number of floating point bits to check

Returns
Type Description
System.Boolean

ApproximatelyEqualEpsilon(Double, Double, Double)

Approximates double-precision floating point equality by an epsilon (maximum error) value. This method is designed as a "fits-all" solution and attempts to handle as many cases as possible.

Declaration
public static bool ApproximatelyEqualEpsilon(double a, double b, double epsilon)
Parameters
Type Name Description
System.Double a

The first float.

System.Double b

The second float.

System.Double epsilon

The maximum error between the two.

Returns
Type Description
System.Boolean

true if the values are approximately equal within the error margin; otherwise, false.

ApproximatelyEqualEpsilon(Single, Single, Single)

Approximates single-precision floating point equality by an epsilon (maximum error) value. This method is designed as a "fits-all" solution and attempts to handle as many cases as possible.

Declaration
public static bool ApproximatelyEqualEpsilon(float a, float b, float epsilon)
Parameters
Type Name Description
System.Single a

The first float.

System.Single b

The second float.

System.Single epsilon

The maximum error between the two.

Returns
Type Description
System.Boolean

true if the values are approximately equal within the error margin; otherwise, false.

ApproximatelyEquivalent(Double, Double, Double)

Approximates equivalence between two double-precision floating-point numbers on a direct human scale. It is important to note that this does not approximate equality - instead, it merely checks whether or not two numbers could be considered equivalent to each other within a certain tolerance. The tolerance is inclusive.

Declaration
public static bool ApproximatelyEquivalent(double a, double b, double tolerance)
Parameters
Type Name Description
System.Double a

The first value to compare.

System.Double b

The second value to compare·

System.Double tolerance

The tolerance within which the two values would be considered equivalent.

Returns
Type Description
System.Boolean

Whether or not the values can be considered equivalent within the tolerance.

ApproximatelyEquivalent(Single, Single, Single)

Approximates equivalence between two single-precision floating-point numbers on a direct human scale. It is important to note that this does not approximate equality - instead, it merely checks whether or not two numbers could be considered equivalent to each other within a certain tolerance. The tolerance is inclusive.

Declaration
public static bool ApproximatelyEquivalent(float a, float b, float tolerance)
Parameters
Type Name Description
System.Single a

The first value to compare.

System.Single b

The second value to compare·

System.Single tolerance

The tolerance within which the two values would be considered equivalent.

Returns
Type Description
System.Boolean

Whether or not the values can be considered equivalent within the tolerance.

BinomialCoefficient(Int32, Int32)

Calculates the binomial coefficient n above k.

Declaration
public static long BinomialCoefficient(int n, int k)
Parameters
Type Name Description
System.Int32 n

The n.

System.Int32 k

The k.

Returns
Type Description
System.Int64

n! / (k! * (n - k)!)

Clamp(Double, Double, Double)

Clamps a number between a minimum and a maximum.

Declaration
public static double Clamp(double n, double min, double max)
Parameters
Type Name Description
System.Double n

The number to clamp.

System.Double min

The minimum allowed value.

System.Double max

The maximum allowed value.

Returns
Type Description
System.Double

min, if n is lower than min; max, if n is higher than max; n otherwise.

Clamp(Int32, Int32, Int32)

Clamps a number between a minimum and a maximum.

Declaration
public static int Clamp(int n, int min, int max)
Parameters
Type Name Description
System.Int32 n

The number to clamp.

System.Int32 min

The minimum allowed value.

System.Int32 max

The maximum allowed value.

Returns
Type Description
System.Int32

min, if n is lower than min; max, if n is higher than max; n otherwise.

Clamp(Single, Single, Single)

Clamps a number between a minimum and a maximum.

Declaration
public static float Clamp(float n, float min, float max)
Parameters
Type Name Description
System.Single n

The number to clamp.

System.Single min

The minimum allowed value.

System.Single max

The maximum allowed value.

Returns
Type Description
System.Single

min, if n is lower than min; max, if n is higher than max; n otherwise.

DegreesToRadians(Double)

Convert degrees to radians

Declaration
public static double DegreesToRadians(double degrees)
Parameters
Type Name Description
System.Double degrees

An angle in degrees

Returns
Type Description
System.Double

The angle expressed in radians

DegreesToRadians(Single)

Convert degrees to radians

Declaration
public static float DegreesToRadians(float degrees)
Parameters
Type Name Description
System.Single degrees

An angle in degrees

Returns
Type Description
System.Single

The angle expressed in radians

Factorial(Int32)

Calculates the factorial of a given natural number.

Declaration
public static long Factorial(int n)
Parameters
Type Name Description
System.Int32 n

The number.

Returns
Type Description
System.Int64

n!

InverseSqrtFast(Double)

Returns an approximation of the inverse square root of left number.

Declaration
public static double InverseSqrtFast(double x)
Parameters
Type Name Description
System.Double x

A number.

Returns
Type Description
System.Double

An approximation of the inverse square root of the specified number, with an upper error bound of 0.001

Remarks

This is an improved implementation of the the method known as Carmack's inverse square root which is found in the Quake III source code. This implementation comes from http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see http://www.beyond3d.com/content/articles/8/

InverseSqrtFast(Single)

Returns an approximation of the inverse square root of left number.

Declaration
public static float InverseSqrtFast(float x)
Parameters
Type Name Description
System.Single x

A number.

Returns
Type Description
System.Single

An approximation of the inverse square root of the specified number, with an upper error bound of 0.001

Remarks

This is an improved implementation of the the method known as Carmack's inverse square root which is found in the Quake III source code. This implementation comes from http://www.codemaestro.com/reviews/review00000105.html. For the history of this method, see http://www.beyond3d.com/content/articles/8/

NextPowerOfTwo(Double)

Returns the next power of two that is greater than or equal to the specified number.

Declaration
public static double NextPowerOfTwo(double n)
Parameters
Type Name Description
System.Double n

The specified number.

Returns
Type Description
System.Double

The next power of two.

NextPowerOfTwo(Int32)

Returns the next power of two that is greater than or equal to the specified number.

Declaration
public static int NextPowerOfTwo(int n)
Parameters
Type Name Description
System.Int32 n

The specified number.

Returns
Type Description
System.Int32

The next power of two.

NextPowerOfTwo(Int64)

Returns the next power of two that is greater than or equal to the specified number.

Declaration
public static long NextPowerOfTwo(long n)
Parameters
Type Name Description
System.Int64 n

The specified number.

Returns
Type Description
System.Int64

The next power of two.

NextPowerOfTwo(Single)

Returns the next power of two that is greater than or equal to the specified number.

Declaration
public static float NextPowerOfTwo(float n)
Parameters
Type Name Description
System.Single n

The specified number.

Returns
Type Description
System.Single

The next power of two.

RadiansToDegrees(Double)

Convert radians to degrees

Declaration
public static double RadiansToDegrees(double radians)
Parameters
Type Name Description
System.Double radians

An angle in radians

Returns
Type Description
System.Double

The angle expressed in degrees

RadiansToDegrees(Single)

Convert radians to degrees

Declaration
public static float RadiansToDegrees(float radians)
Parameters
Type Name Description
System.Single radians

An angle in radians

Returns
Type Description
System.Single

The angle expressed in degrees

Swap(ref Double, ref Double)

Swaps two double values.

Declaration
public static void Swap(ref double a, ref double b)
Parameters
Type Name Description
System.Double a

The first value.

System.Double b

The second value.

Swap(ref Single, ref Single)

Swaps two float values.

Declaration
public static void Swap(ref float a, ref float b)
Parameters
Type Name Description
System.Single a

The first value.

System.Single b

The second value.

Back to top Copyright © 2015-2017 Microsoft
Generated by DocFX