Skip to content

Latest commit

 

History

History
189 lines (182 loc) · 7.98 KB

File metadata and controls

189 lines (182 loc) · 7.98 KB

Atc.Math


MathEx

Provides extended mathematical operations including number theory, signal processing, and functional programming utilities.

public static class MathEx

Static Methods

Ceiling

int Ceiling(int x, int period)

Summary: Rounds a value up to the nearest multiple of a specified period.

Parameters:
     x  -  The value to round.
     period  -  The period (interval) to round to.

Returns: The smallest multiple of period that is greater than or equal to x.

Ceiling

Func<int, int> Ceiling(Func<int, int> f, int period)

Summary: Rounds a value up to the nearest multiple of a specified period.

Parameters:
     x  -  The value to round.
     period  -  The period (interval) to round to.

Returns: The smallest multiple of period that is greater than or equal to x.

Compose

Func<int, int> Compose(Func<int, int> f, Func<int, int> g)

Summary: Creates a new function that represents the composition of two functions.

Parameters:
     f  -  The outer function.
     g  -  The inner function.

Returns: A function that returns f(g(x)) for any input x.

Floor

int Floor(int x, int period)

Summary: Rounds a value down to the nearest multiple of a specified period.

Parameters:
     x  -  The value to round.
     period  -  The period (interval) to round to.

Returns: The largest multiple of period that is less than or equal to x.

Floor

Func<int, int> Floor(Func<int, int> f, int period)

Summary: Rounds a value down to the nearest multiple of a specified period.

Parameters:
     x  -  The value to round.
     period  -  The period (interval) to round to.

Returns: The largest multiple of period that is less than or equal to x.

GetDivisorsLessThanOrEqual

IEnumerable<int> GetDivisorsLessThanOrEqual(int value, int max)

Summary: Gets divisors for value that is less than or equal to the specified max value.

Parameters:
     value  -  The value to get divisors of.
     max  -  The maximum divisor threshold.

GreatestCommonDivisor

int GreatestCommonDivisor(int v1, int v2)

Summary: Calculates the greatest common divisor (GCD) of two integers using Euclid's algorithm.

Parameters:
     v1  -  The first integer value.
     v2  -  The second integer value.

Returns: The greatest common divisor of v1 and v2.

GreatestCommonDivisor

double GreatestCommonDivisor(double v1, double v2)

Summary: Calculates the greatest common divisor (GCD) of two integers using Euclid's algorithm.

Parameters:
     v1  -  The first integer value.
     v2  -  The second integer value.

Returns: The greatest common divisor of v1 and v2.

Hysteron

int Hysteron(ref int state, int x, int width = 1, int height = 1)

Summary: Implements a hysteresis (hysteron) operator where the output depends on both current input and previous state.

Parameters:
     state  -  The current state of the operator, which is updated based on the input.
     x  -  The input value.
     width  -  The upper threshold. When input reaches or exceeds this value, state becomes . Default is 1.
     height  -  The maximum output value. Default is 1.

Returns: The updated state value.

Remarks: This function maintains state between calls, implementing memory-like behavior common in control systems.

Modulate

Func<int, int> Modulate(Func<int, int> carrier, Func<int, int> cellFunction, int period)

Summary: Creates a modulated function by combining a carrier function with a cell function.

Parameters:
     carrier  -  The carrier function that provides the base signal.
     cellFunction  -  The cell function that modulates the carrier within each period.
     period  -  The modulation period.

Returns: A function representing the modulated signal.

Remarks: This implements a form of amplitude modulation where the carrier is sampled at period boundaries and interpolated using the cell function.

Multiply

Func<int, int> Multiply(Func<int, int> f, Func<int, int> g)

Summary: Creates a new function that multiplies the results of two functions pointwise.

Parameters:
     f  -  The first function.
     g  -  The second function.

Returns: A function that returns f(x) * g(x) for any input x.

Periodic

Func<int, int> Periodic(Func<int, int> f, int period)

Summary: Creates a periodic version of a function by applying sawtooth wrapping to its input.

Parameters:
     f  -  The function to make periodic.
     period  -  The period of repetition.

Returns: A function that repeats f every period units.

Rect

int Rect(int x, int width = 1, int height = 1)

Summary: Implements a rectangular (pulse) function that returns a specified height within a defined width, otherwise 0.

Parameters:
     x  -  The input value.
     width  -  The width of the rectangular pulse. Default is 1.
     height  -  The height of the rectangular pulse. Default is 1.

Returns: height if x is within [0, width); otherwise, 0.

SawTooth

int SawTooth(int x, int period)

Summary: Generates a sawtooth wave pattern with a specified period.

Parameters:
     x  -  The input value.
     period  -  The period of the sawtooth wave.

Returns: A value in the range [0, period) that repeats in a sawtooth pattern.

Step

int Step(int x)

Summary: Implements a step function (Heaviside step function) that returns 0 for negative values and 1 for non-negative values.

Parameters:
     x  -  The input value.

Returns: 0 if x is negative; otherwise, 1.


Generated by MarkdownCodeDoc version 1.2