C# Class GarrysModLuaShared.math

The math library is a standard Lua library that provides functions for manipulating numbers. In Garry's Mod several additional math functions have been added.
ファイルを表示 Open project: OmegaExtern/gmod-csharp-binary-module

Public Methods

Method Description
AngleDifference ( LuaState luaState, double a, double b ) : double

Calculates the difference between two angles.

Approach ( LuaState luaState, double start, double end, double amount ) : double

Increments a value from a start point by the given amount, up to a given upper limit.

ApproachAngle ( LuaState luaState, double currentAngle, double targetAngle, double rate ) : double

Increments an angle towards another by specified rate. NOTE: This function is for numbers representing angles(0-360), NOT Structs.Angle objects!

BinToInt ( LuaState luaState, string @string ) : double

Converts a binary string into a number.

Clamp ( LuaState luaState, double input, double min, double max ) : double

Clamps a number between a minimum and maximum value.

Distance ( LuaState luaState, double x1, double y1, double x2, double y2 ) : double

Returns the difference between two points in 2D space.

EaseInOut ( LuaState luaState, double progress, double easeIn, double easeOut ) : double

Calculates the progress of a value fraction, taking in to account given easing fractions.

IntToBin ( LuaState luaState, double number ) : string

Converts an integer to a binary (base-2) string.

NormalizeAngle ( LuaState luaState, double angle ) : double

Normalizes angle, so it returns value between -180 and 180.

Rand ( LuaState luaState, double min, double max ) : double

Returns a random float between min and max.

Remap ( LuaState luaState, double value, double inMin, double inMax, double outMin, double outMax ) : double

Remaps the value from one range to another.

Round ( LuaState luaState, double value, double decimals = 0.0D ) : double

Rounds the given value to the nearest whole number or to the given decimal places.

TimeFraction ( LuaState luaState, double start, double end, double current ) : double

Returns the fraction of where the current time is relative to the start and end times.

Truncate ( LuaState luaState, double number, double digits ) : double

Rounds towards zero.

abs ( LuaState luaState, double x ) : double

Calculates the absolute value of a number (effectively removes any negative sign).

acos ( LuaState luaState, double x ) : double

Returns the arc cosine of the given number.

asin ( LuaState luaState, double x ) : double

Returns the arc sine of the given number.

atan ( LuaState luaState, double x ) : double

Returns the arc tangent of the given number.

atan2 ( LuaState luaState, double y, double x ) : double

Returns atan(y / x) in radians. The result is between - pi and pi.

calcBSplineN ( LuaState luaState, double i, double k, double t, double tInc ) : double

Basic code for Bezier-Spline algorithm.

ceil ( LuaState luaState, double number ) : double

Ceils or rounds a number up.

cos ( LuaState luaState, double angle ) : double

Returns cosine of the given angle.

cosh ( LuaState luaState, double number ) : double

Returns hyperbolic cosine of the given number.

deg ( LuaState luaState, double radians ) : double

Converts radians to degrees.

exp ( LuaState luaState, double exponent ) : double

Returns the x power of the euler constant.

floor ( LuaState luaState, double number ) : double

Floors or rounds a number down.

fmod ( LuaState luaState, double @base, double modulator ) : double

Returns the modulus of the specified values. The same effect can be achieved using the % operator.

frexp ( LuaState luaState, double inputValue ) : double>.Tuple

Used to split the number value into a normalized fraction and an exponent.

frexp ( LuaState luaState, double inputValue, double &normalizedFraction, double &exponent ) : void

Used to split the number value into a normalized fraction and an exponent.

ldexp ( LuaState luaState, double normalizedFraction, double exponent ) : double

Takes a normalised number and returns the floating-point representation.

log ( LuaState luaState, double x, double @base = e ) : double

With one argument, return the natural logarithm of x (to base e). With two arguments, return the logarithm of x to the given base, calculated as log(x)/log(base).

log10 ( LuaState luaState, double x ) : double

Returns the base-10 logarithm of x. This is usually more accurate than log( x, 10).

max ( LuaState luaState ) : double

Returns the largest value of all arguments.

min ( LuaState luaState ) : double

Returns the smallest value of all arguments.

modf ( LuaState luaState, double @base, double modulator ) : double>.Tuple

Returns the integral and fractional component of the modulo operation.

modf ( LuaState luaState, double @base, double modulator, double &integral, double &fractional ) : void

Returns the integral and fractional component of the modulo operation.

pow ( LuaState luaState, double x, double y ) : double

Returns x raised to the power y. In particular, math.pow(1.0, x) and math.pow(x, 0.0) always return 1.0, even when x is a zero or a NaN. If both x and y are finite, x is negative, and y is not an integer then math.pow( x, y) is undefined.

rad ( LuaState luaState, double degrees ) : double

Converts an angle in degrees to it's equivalent in radians.

random ( LuaState luaState, int min, int max ) : int

Returns a random integer between min and max.

randomseed ( LuaState luaState, double seed ) : void

Seeds the seed for the random generator, which will cause random to return the same sequence of numbers.

sin ( LuaState luaState, double angle ) : double

Returns sine of the given angle.

sinh ( LuaState luaState, double number ) : double

Returns hyperbolic sine of the given number.

sqrt ( LuaState luaState, double number ) : double

Returns square root of the given number.

tan ( LuaState luaState, double angle ) : double

Returns tangent of the given angle.

tanh ( LuaState luaState, double number ) : double

Returns hyperbolic tangent of the given number.

Method Details

AngleDifference() public static method

Calculates the difference between two angles.
public static AngleDifference ( LuaState luaState, double a, double b ) : double
luaState LuaState Pointer to lua_State struct.
a double The first angle.
b double The second angle.
return double

Approach() public static method

Increments a value from a start point by the given amount, up to a given upper limit.
public static Approach ( LuaState luaState, double start, double end, double amount ) : double
luaState LuaState Pointer to lua_State struct.
start double The number to start with.
end double The max value, this function will never return a number greater than this.
amount double The amount to increment the starting number by.
return double

ApproachAngle() public static method

Increments an angle towards another by specified rate. NOTE: This function is for numbers representing angles(0-360), NOT Structs.Angle objects!
public static ApproachAngle ( LuaState luaState, double currentAngle, double targetAngle, double rate ) : double
luaState LuaState Pointer to lua_State struct.
currentAngle double The current angle to increase.
targetAngle double The angle to increase towards.
rate double The amount to approach the target angle by.
return double

BinToInt() public static method

Converts a binary string into a number.
public static BinToInt ( LuaState luaState, string @string ) : double
luaState LuaState Pointer to lua_State struct.
@string string
return double

Clamp() public static method

Clamps a number between a minimum and maximum value.
public static Clamp ( LuaState luaState, double input, double min, double max ) : double
luaState LuaState Pointer to lua_State struct.
input double The number to clamp.
min double The minimum value, this function will never return a number less than this.
max double The maximum value, this function will never return a number greater than this.
return double

Distance() public static method

Returns the difference between two points in 2D space.
public static Distance ( LuaState luaState, double x1, double y1, double x2, double y2 ) : double
luaState LuaState Pointer to lua_State struct.
x1 double X position of first point.
y1 double Y position of first point.
x2 double X position of second point.
y2 double Y position of second point.
return double

EaseInOut() public static method

Calculates the progress of a value fraction, taking in to account given easing fractions.
public static EaseInOut ( LuaState luaState, double progress, double easeIn, double easeOut ) : double
luaState LuaState Pointer to lua_State struct.
progress double Fraction of the progress to ease.
easeIn double Fraction of how much easing to begin with.
easeOut double Fraction of how much easing to end with.
return double

IntToBin() public static method

Converts an integer to a binary (base-2) string.
public static IntToBin ( LuaState luaState, double number ) : string
luaState LuaState Pointer to lua_State struct.
number double Number to be converted.
return string

NormalizeAngle() public static method

Normalizes angle, so it returns value between -180 and 180.
public static NormalizeAngle ( LuaState luaState, double angle ) : double
luaState LuaState Pointer to lua_State struct.
angle double The angle to normalize, in degrees.
return double

Rand() public static method

Returns a random float between min and max.
public static Rand ( LuaState luaState, double min, double max ) : double
luaState LuaState Pointer to lua_State struct.
min double The minimum value.
max double The maximum value.
return double

Remap() public static method

Remaps the value from one range to another.
public static Remap ( LuaState luaState, double value, double inMin, double inMax, double outMin, double outMax ) : double
luaState LuaState Pointer to lua_State struct.
value double The value.
inMin double The minimum of the initial range.
inMax double The maximum of the initial range.
outMin double The minimum of new range.
outMax double The maximum of new range.
return double

Round() public static method

Rounds the given value to the nearest whole number or to the given decimal places.
public static Round ( LuaState luaState, double value, double decimals = 0.0D ) : double
luaState LuaState Pointer to lua_State struct.
value double The value to round.
decimals double The decimal places to round to.
return double

TimeFraction() public static method

Returns the fraction of where the current time is relative to the start and end times.
public static TimeFraction ( LuaState luaState, double start, double end, double current ) : double
luaState LuaState Pointer to lua_State struct.
start double Start time in seconds.
end double End time in seconds.
current double Current time in seconds.
return double

Truncate() public static method

Rounds towards zero.
public static Truncate ( LuaState luaState, double number, double digits ) : double
luaState LuaState Pointer to lua_State struct.
number double The number to truncate.
digits double The amount of digits to keep after the point.
return double

abs() public static method

Calculates the absolute value of a number (effectively removes any negative sign).
public static abs ( LuaState luaState, double x ) : double
luaState LuaState Pointer to lua_State struct.
x double The number to get the absolute value of.
return double

acos() public static method

Returns the arc cosine of the given number.
public static acos ( LuaState luaState, double x ) : double
luaState LuaState Pointer to lua_State struct.
x double Value in range from -1 to +1.
return double

asin() public static method

Returns the arc sine of the given number.
public static asin ( LuaState luaState, double x ) : double
luaState LuaState Pointer to lua_State struct.
x double Value in range from -1 to +1.
return double

atan() public static method

Returns the arc tangent of the given number.
public static atan ( LuaState luaState, double x ) : double
luaState LuaState Pointer to lua_State struct.
x double Value in range from -1 to +1.
return double

atan2() public static method

Returns atan(y / x) in radians. The result is between - pi and pi.
public static atan2 ( LuaState luaState, double y, double x ) : double
luaState LuaState Pointer to lua_State struct.
y double Y coordinate.
x double X coordinate.
return double

calcBSplineN() public static method

Basic code for Bezier-Spline algorithm.
public static calcBSplineN ( LuaState luaState, double i, double k, double t, double tInc ) : double
luaState LuaState Pointer to lua_State struct.
i double
k double
t double
tInc double
return double

ceil() public static method

Ceils or rounds a number up.
public static ceil ( LuaState luaState, double number ) : double
luaState LuaState Pointer to lua_State struct.
number double The number to be rounded up.
return double

cos() public static method

Returns cosine of the given angle.
public static cos ( LuaState luaState, double angle ) : double
luaState LuaState Pointer to lua_State struct.
angle double Angle in radians.
return double

cosh() public static method

Returns hyperbolic cosine of the given number.
public static cosh ( LuaState luaState, double number ) : double
luaState LuaState Pointer to lua_State struct.
number double Value in radians.
return double

deg() public static method

Converts radians to degrees.
public static deg ( LuaState luaState, double radians ) : double
luaState LuaState Pointer to lua_State struct.
radians double Value to be converted to degrees.
return double

exp() public static method

Returns the x power of the euler constant.
public static exp ( LuaState luaState, double exponent ) : double
luaState LuaState Pointer to lua_State struct.
exponent double The exponent for the function.
return double

floor() public static method

Floors or rounds a number down.
public static floor ( LuaState luaState, double number ) : double
luaState LuaState Pointer to lua_State struct.
number double The number to be rounded down.
return double

fmod() public static method

Returns the modulus of the specified values. The same effect can be achieved using the % operator.
public static fmod ( LuaState luaState, double @base, double modulator ) : double
luaState LuaState Pointer to lua_State struct.
@base double
modulator double The modulator.
return double

frexp() public static method

Used to split the number value into a normalized fraction and an exponent.
public static frexp ( LuaState luaState, double inputValue ) : double>.Tuple
luaState LuaState Pointer to lua_State struct.
inputValue double The value to get the normalized fraction and the exponent from.
return double>.Tuple

frexp() public static method

Used to split the number value into a normalized fraction and an exponent.
public static frexp ( LuaState luaState, double inputValue, double &normalizedFraction, double &exponent ) : void
luaState LuaState Pointer to lua_State struct.
inputValue double The value to get the normalized fraction and the exponent from.
normalizedFraction double Always in the range 1/2 (inclusive) to 1 (exclusive).
exponent double An exponent.
return void

ldexp() public static method

Takes a normalised number and returns the floating-point representation.
public static ldexp ( LuaState luaState, double normalizedFraction, double exponent ) : double
luaState LuaState Pointer to lua_State struct.
normalizedFraction double The value to get the normalized fraction and the exponent from.
exponent double The value to get the normalized fraction and the exponent from.
return double

log() public static method

With one argument, return the natural logarithm of x (to base e). With two arguments, return the logarithm of x to the given base, calculated as log(x)/log(base).
public static log ( LuaState luaState, double x, double @base = e ) : double
luaState LuaState Pointer to lua_State struct.
x double The value to get the base from exponent from.
@base double
return double

log10() public static method

Returns the base-10 logarithm of x. This is usually more accurate than log( x, 10).
public static log10 ( LuaState luaState, double x ) : double
luaState LuaState Pointer to lua_State struct.
x double The value to get the base from exponent from.
return double

max() public static method

Returns the largest value of all arguments.
public static max ( LuaState luaState ) : double
luaState LuaState Pointer to lua_State struct.
return double

min() public static method

Returns the smallest value of all arguments.
public static min ( LuaState luaState ) : double
luaState LuaState Pointer to lua_State struct.
return double

modf() public static method

Returns the integral and fractional component of the modulo operation.
public static modf ( LuaState luaState, double @base, double modulator ) : double>.Tuple
luaState LuaState Pointer to lua_State struct.
@base double
modulator double The modulator.
return double>.Tuple

modf() public static method

Returns the integral and fractional component of the modulo operation.
public static modf ( LuaState luaState, double @base, double modulator, double &integral, double &fractional ) : void
luaState LuaState Pointer to lua_State struct.
@base double
modulator double The modulator.
integral double The integral component.
fractional double The fractional component.
return void

pow() public static method

Returns x raised to the power y. In particular, math.pow(1.0, x) and math.pow(x, 0.0) always return 1.0, even when x is a zero or a NaN. If both x and y are finite, x is negative, and y is not an integer then math.pow( x, y) is undefined.
public static pow ( LuaState luaState, double x, double y ) : double
luaState LuaState Pointer to lua_State struct.
x double Base.
y double Exponent.
return double

rad() public static method

Converts an angle in degrees to it's equivalent in radians.
public static rad ( LuaState luaState, double degrees ) : double
luaState LuaState Pointer to lua_State struct.
degrees double The angle measured in degrees.
return double

random() public static method

Returns a random integer between min and max.
public static random ( LuaState luaState, int min, int max ) : int
luaState LuaState Pointer to lua_State struct.
min int The minimum value.
max int The maximum value.
return int

randomseed() public static method

Seeds the seed for the random generator, which will cause random to return the same sequence of numbers.
public static randomseed ( LuaState luaState, double seed ) : void
luaState LuaState Pointer to lua_State struct.
seed double The new seed.
return void

sin() public static method

Returns sine of the given angle.
public static sin ( LuaState luaState, double angle ) : double
luaState LuaState Pointer to lua_State struct.
angle double Angle in radians.
return double

sinh() public static method

Returns hyperbolic sine of the given number.
public static sinh ( LuaState luaState, double number ) : double
luaState LuaState Pointer to lua_State struct.
number double Value in radians.
return double

sqrt() public static method

Returns square root of the given number.
public static sqrt ( LuaState luaState, double number ) : double
luaState LuaState Pointer to lua_State struct.
number double Value to get the square root of.
return double

tan() public static method

Returns tangent of the given angle.
public static tan ( LuaState luaState, double angle ) : double
luaState LuaState Pointer to lua_State struct.
angle double Angle in radians.
return double

tanh() public static method

Returns hyperbolic tangent of the given number.
public static tanh ( LuaState luaState, double number ) : double
luaState LuaState Pointer to lua_State struct.
number double Value in radians.
return double