diff --git a/docs/raw/maths/Invert.txt b/docs/maths/Invert.md similarity index 59% rename from docs/raw/maths/Invert.txt rename to docs/maths/Invert.md index 39f12921..52bc9674 100644 --- a/docs/raw/maths/Invert.txt +++ b/docs/maths/Invert.md @@ -1,29 +1,52 @@ -Invert -20.9.0 +--- +title: "Invert" +--- + +{{< callout type="info">}} + Header: `invert.h` + Since: `20.9.0` +{{< /callout >}} + Invert an input range. +```cpp template class invert : public etl::unary_function +``` -TInput The input data type. -____________________________________________________________________________________________________ +``TInput``` The input data type. + +```cpp invert() -offset = 0 -minuend = etl::numeric_limits::is_signed) ? TInput(0) - : etl::numeric_limits::max()) -If the type is signed then the input values have their sign changed. -i.e. 10 => -10, -10 => 10. +``` +**Description** +`offset` = 0 +`minuend` = `etl::numeric_limits::is_signed) ? TInput(0) + : etl::numeric_limits::max())` + +If the type is signed then the input values have their sign changed. +i.e. `10` => `-10`, `-10` => `10`. If the type is unsigned then the input values are subtracted from the type's maximum value. -invert(TInput offset, TInput minuend) -Sets the offset and minuend. -____________________________________________________________________________________________________ -TInput operator()(TInput value) const -Invert a value. -Calculates minuend - (value - offset) -____________________________________________________________________________________________________ -Example +--- +```cpp +invert(TInput offset, TInput minuend) +``` +**Description** +Sets the offset and minuend. + +--- + +```cpp +TInput operator()(TInput value) const +``` +**Description** +Invert a value. +Calculates `minuend - (value - offset)` + +## Example +```cpp std::array input = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 @@ -36,4 +59,4 @@ etl::invert invert(10, 100); // offset = 10, minuend = 100 std::transform(input.begin(), input.end(), output.begin(), invert); // output = 100.0, 99.0, 98.0, 97.0, 96.0, 95.0, 94.0, 93.0, 92.0, 91.0 - +``` diff --git a/docs/maths/is_negative.md b/docs/maths/is_negative.md new file mode 100644 index 00000000..96b8d764 --- /dev/null +++ b/docs/maths/is_negative.md @@ -0,0 +1,12 @@ +--- +title: "is_negative" +--- + +Allows a parameter of type `T` to be checked for a positive or negative value, while eliminating compiler warnings for checking `< 0` for unsigned types. + +```cpp +template +ETL_CONSTEXPR bool is_negative(const T value) +``` +**Return** +`true` if the value is negative, otherwise `false`. diff --git a/docs/maths/limiter.md b/docs/maths/limiter.md new file mode 100644 index 00000000..40ad7961 --- /dev/null +++ b/docs/maths/limiter.md @@ -0,0 +1,50 @@ +--- +title: "limiter" +--- + +{{< callout type="info">}} + Header: `limiter.h` + Since: `20.9.0` +{{< /callout >}} + +Limits an input range. + +```cpp +template > +class limit : public etl::unary_function +``` + +`TInput` The input data type. +`TCompare` The functor type used to compare values to the threshold. The default is `etl::less`. + +```cpp +limit(TInput lowest, TInput highest) +``` +**Description** +`lowest` The lowest limit. +`highest` The highest limit. + +--- + +```cpp +TInput operator()(TInput value) const +``` +**Return** +The limited value. + +```cpp +Example + +std::array input = +{ + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 +}; + +std::array output; + +etl::limiter limiter(13, 16); + +std::transform(input.begin(), input.end(), output.begin(), limiter); + +// output = 13, 13, 13, 13, 14, 15, 16, 16, 16, 16 +``` diff --git a/docs/maths/mean.md b/docs/maths/mean.md new file mode 100644 index 00000000..09150d9a --- /dev/null +++ b/docs/maths/mean.md @@ -0,0 +1,114 @@ +--- +title: "mean" +--- + +{{< callout type="info">}} + Header: `mean.h` + Since: `20.9.0` +{{< /callout >}} + +```cpp +template +class mean : public etl::unary_function +``` + +`TInput` The input data type. +`TCalc` The type to use for internal calculations. By default, equal to `TInput`. + +--- + +```cpp +mean() +``` +**Description** +Default constructor. + +--- + +```cpp +template +mean(TIterator first, TIterator last) +``` +**Description** +Construct from an iterator range. + +--- + +```cpp +void add(TInput value1) +``` +**Description** +Add a value. + +--- + +```cpp +template +void add(TIterator first, TIterator last) +``` +**Description** +Add a range of values. + +--- + +```cpp +void operator()(TInput value) +``` +**Description** +Add a values. + +--- + +```cpp +template +void operator()(TIterator first, TIterator last) +``` +**Description** +Add a range of values. + +--- + +```cpp +double get_mean() const +``` +**Description** +Returns the calculated mean for the data. + +--- + +```cpp +operator double() const +``` +**Return** +The calculated mean for the data. + +--- + +```cpp +size_t count() const +``` +**Description** +Get the total number added entries. + +--- + +```cpp +void clear() +``` +**Description** +Clear the mean. + +## Example + +```cpp +std::array input +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 +}; + +etl::mean mean(input.begin(), input.end()); + +double mean_result; + +mean_result = mean; // mean_result == 4.5 +``` diff --git a/docs/raw/maths/pseudo_moving_average.txt b/docs/maths/pseudo_moving_average.md similarity index 51% rename from docs/raw/maths/pseudo_moving_average.txt rename to docs/maths/pseudo_moving_average.md index 662dcecf..ed44a637 100644 --- a/docs/raw/maths/pseudo_moving_average.txt +++ b/docs/maths/pseudo_moving_average.md @@ -1,88 +1,159 @@ -pseudo_moving_average +--- +title: "pseudo_moving_average" +--- -A moving average algorithm that continuously calculates an average value from a stream of samples. -The sample size does not affect the size of the instantiated object. There is no overhead based on the number of samples as it simulates a window of N values from the current average. +A moving average algorithm that continuously calculates an average value from a stream of samples. +The sample size does not affect the size of the instantiated object. There is no overhead based on the number of samples as it simulates a window of N values from the current average. -There are four variants of the algorithm; two for integral values and two for floating point. Each sub variant allows the selection of compile time or run time sample size. -The integral variant allows a compile time scaling factor to emulate fixed point arithmetic. -____________________________________________________________________________________________________ -Integral +There are four variants of the algorithm; two for integral values and two for floating point. Each sub-variant allows the selection of compile time or run time sample size. +The integral variant allows a compile time scaling factor to emulate fixed point arithmetic. +## Integral + +```cpp template pseudo_moving_average; +``` +```cpp static const size_t SAMPLE_SIZE -The number of samples averaged over. +``` +The number of samples averaged over. If this value is zero, then the run time sample size specialisation is used. +```cpp static const size_t SCALING +``` The sample scaling factor. -__________________________________________________________________________________________________ -pseudo_moving_average(const T initial_value) -Constructs the object with the initial value for the average. -__________________________________________________________________________________________________ -pseudo_moving_average(const T initial_value, const size_t sample_size) -For runtime sample size specialisation only. -Constructs the object with the initial value for the average and the sample size. -__________________________________________________________________________________________________ -void clear(const T initial_value) -Clears the object to the initial value for the average. -__________________________________________________________________________________________________ -void add(T new_value) -Adds a new sample value. -__________________________________________________________________________________________________ -T value() const -Returns the scaled value of the average. -To unscale the returned value, use one of the rounding found in scaled_rounding. -__________________________________________________________________________________________________ -iterator input() +```cpp +pseudo_moving_average(const T initial_value) +``` +**Description** +Constructs the object with the initial value for the average. + +--- + +```cpp +pseudo_moving_average(const T initial_value, const size_t sample_size) +``` +**Description** +*For runtime sample size specialisation only.* +Constructs the object with the initial value for the average and the sample size. + +--- + +```cpp +void clear(const T initial_value) +``` +**Description** +Clears the object to the initial value for the average. + +--- + +```cpp +void add(T new_value) +``` +**Description** +Adds a new sample value. + +--- + +```cpp +T value() const +``` +**Description** +Returns the scaled value of the average. +To unscale the returned value, use one of the rounding found in scaled_rounding. + +--- + +```cpp +iterator input() +``` +**Description** Returns an iterator that allows the input of new values. -Example +## Example +```cpp std::array data{ 9, 1, 8, 2, 7, 3, 6, 4, 5 }; etl::pseudo_moving_average cma(0); std::copy(data.begin(), data.end(), cma.input()); int average = cma.value(); -__________________________________________________________________________________________________ +``` + +--- + +```cpp void set_sample_size(const size_t sample_size) - -For runtime sample size specialisation only. +``` +**Description** +For runtime sample size specialisation only. Sets the sample size. -____________________________________________________________________________________________________ -Floating point +## Floating point + +```cpp template pseudo_moving_average; - +``` +```cpp static const size_t SAMPLE_SIZE +``` The number of samples averaged over. -__________________________________________________________________________________________________ + +--- + +```cpp pseudo_moving_average(const T initial_value) +``` +**Description** Constructs the object with the initial value for the average. -__________________________________________________________________________________________________ + +--- + +```cpp pseudo_moving_average(const T initial_value, const size_t sample_size) -For runtime sample size specialisation only. +``` +**Description** +For runtime sample size specialisation only. Constructs the object with the initial value for the average and the sample size. -__________________________________________________________________________________________________ + +--- + +```cpp void clear(const T initial_value) +``` +**Description** Clears the object to the initial value for the average. -__________________________________________________________________________________________________ + +--- + +```cpp void add(T new_value) +``` +**Description** Adds a new sample value. -__________________________________________________________________________________________________ + +--- + +```cpp T value() const +``` +**Description** Returns the average value. -__________________________________________________________________________________________________ + +--- + +```cpp void set_sample_size(const size_t sample_size) -For runtime sample size specialisation only. +``` +**Description** +For runtime sample size specialisation only. Sets the sample size. -____________________________________________________________________________________________________ -How It Works -If the current moving average is 5, then an equivalent sequence of samples (for a sample size of 9), that gives the same average, would be 5, 5, 5, 5, 5, 5, 5, 5, 5 +## How It Works -This means, to find the average when adding a new sample to a moving average that has a current value of 5, all we need to do is multiply the current average by the sample size (9), add the new sample, and divide by the sample size + 1 (10). - -Wikipedia +If the current moving average is 5, then an equivalent sequence of samples (for a sample size of 9), that gives the same average, would be 5, 5, 5, 5, 5, 5, 5, 5, 5 +This means, to find the average when adding a new sample to a moving average that has a current value of 5, all we need to do is multiply the current average by the sample size (9), add the new sample, and divide by the sample size + 1 (10). diff --git a/docs/raw/maths/Quantize.txt b/docs/maths/quantize.md similarity index 59% rename from docs/raw/maths/Quantize.txt rename to docs/maths/quantize.md index 4284386f..899496fc 100644 --- a/docs/raw/maths/Quantize.txt +++ b/docs/maths/quantize.md @@ -1,26 +1,47 @@ -Quantize -20.9.0 +--- +title: "quantize" +--- + +{{< callout type="info">}} + Header: `quantize.h` + Since: `20.9.0` +{{< /callout >}} + Quantizes an input range. +```cpp template > class quantize : public etl::unary_function +``` -TInput The input data type. -TCompare The functor type used to compare values to the threshold. The default is etl::less -____________________________________________________________________________________________________ +`TInput` The input data type. +`TCompare` The functor type used to compare values to the threshold. The default is `etl::less`. + +--- + +```cpp quantize(const TInput* p_thresholds, const TInput* p_quantizations, size_t n_quantizations, TCompare compare = TCompare()) -p_thresholds A pointer to the list of threshold values. -p_quantizations A pointer to the list of quantization values. One more than the number of thresholds. -n_quantizations The number of quantization values. -____________________________________________________________________________________________________ -TInput operator()(TInput value) const -Quantatize a value. -____________________________________________________________________________________________________ -Example +``` +**Description** +`p_thresholds` A pointer to the list of threshold values. +`p_quantizations` A pointer to the list of quantization values. One more than the number of thresholds. +`n_quantizations` The number of quantization values. +--- + +```cpp +TInput operator()(TInput value) const +``` +**Description** +Quantatize a value. + +--- + +## Example +```cpp constexpr size_t Size = 20U; constexpr size_t NThresholds = 4U; @@ -46,4 +67,4 @@ etl::quantize quantize(thresholds.data(), quantizations.data(), quantizatio std::transform(input.begin(), input.end(), output.begin(), quantize); // output = 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5 - +``` diff --git a/docs/maths/radix.md b/docs/maths/radix.md new file mode 100644 index 00000000..f05fccd5 --- /dev/null +++ b/docs/maths/radix.md @@ -0,0 +1,18 @@ +--- +title: "radix" +--- + +A smart enumeration to encode radix constants. + +```cpp +struct radix +``` + +**Defines the constants** +```cpp +undefined +binary +octal +decimal +hex +``` diff --git a/docs/maths/random.md b/docs/maths/random.md new file mode 100644 index 00000000..d288b5a1 --- /dev/null +++ b/docs/maths/random.md @@ -0,0 +1,325 @@ +--- +title: "random" +--- + +Utilities for producing random numbers. + +## random +The base class for all 32 bit random number generators. + +If `ETL_POLYMORPHIC_RANDOM` is defined, then the base class will have the following members, otherwise the base is empty. + +```cpp +virtual ~random(); +virtual void initialise(uint32_t seed) = 0; +virtual uint32_t operator()() = 0; +virtual uint32_t range(uint32_t low, uint32_t high) = 0; +``` + +## random_xorshift +Uses a 128bit XOR shift algorithm for producing a pseudo-random sequence of integers. +The result is a 32 bit integer between 0 and 4,294,967,295 (2^32 - 1). + +```cpp +random_xor_shift() +``` +**Description** +Constructor. +Uses the address of the object as the seed for the sequence. + +--- + +```cpp +random_xor_shift(uint32_t seed) +``` +**Description** +Constructor. +Uses seed as the `seed` for the sequence. + +--- + +```cpp +void initialise(uint32_t seed) +``` +**Description** +Sets the seed as the new seed for the sequence. + +--- + +```cpp +uint32_t operator()() +``` +**Return** +The next number in the pseudo-random sequence. + +--- + +```cpp +uint32_t range(uint32_t low, uint32_t high) +``` +** Return** +A number between the specified ranges, inclusive. + +## random_lcg +Generates a 32 bit pseudo-random number using a linear congruent generator. +The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1). + +```cpp +random_lcg() +``` +**Description** +Constructor. +Uses the address of the object as the seed for the sequence + +--- +```cpp +random_lcg(uint32_t seed) +``` +**Description** +Constructor. +Uses seed as the seed for the sequence. + +--- + +```cpp +void initialise(uint32_t seed) +``` +**Description** +Sets the seed as the new seed for the sequence. + +--- + +```cpp +uint32_t operator()() +``` +**Return** +The next number in the pseudo-random sequence. + +--- + +```cpp +uint32_t range(uint32_t low, uint32_t high) +``` +**Return** +A number between the specified ranges, inclusive. + +## random_clcg +Generates a 32 bit pseudo-random number using a combined linear congruent generator. +The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1). + +```cpp +random_clcg() +``` +**Description** +Constructor. +Uses the address of the object as the seed for the sequence. + +--- + +```cpp +random_clcg(uint32_t seed) +``` +**Description** +Constructor. +Uses seed as the seed for the sequence. + +--- + +```cpp +void initialise(uint32_t seed) +``` +**Description** +Sets the seed as the new seed for the sequence. + +--- + +```cpp +uint32_t operator()() +``` +**Return** +The next number in the pseudo-random sequence. + +--- + +```cpp +uint32_t range(uint32_t low, uint32_t high) +``` +**Return** +A number between the specified ranges, inclusive. + +## random_lsfr +Generates a 32 bit pseudo-random number using a linear shift feedback register. +The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1). +The seed must not be zero. The output does not include zero. + +```cpp +random_lsfr() +``` +**Description** +Constructor. +Uses the address of the object as the seed for the sequence. + +--- + +```cpp +random_lsfr(uint32_t seed) +``` +**Description** +Constructor. +Uses seed as the seed for the sequence. + +--- + +```cpp +void initialise(uint32_t seed) +``` +**Description** +Sets the seed as the new seed for the sequence. + +```cpp +uint32_t operator()() +``` +**Return** +The next number in the pseudo-random sequence. + +--- + +```cpp +uint32_t range(uint32_t low, uint32_t high) +``` +**Return** +A number between the specified ranges, inclusive. + +## random_mwc +Generates a 32 bit pseudo-random number using a multiply-with-carry algorithm. +The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1). + +```cpp +random_mwc() +``` +**Description** +Constructor. +Uses the address of the object as the seed for the sequence. + +--- + +```cpp +random_mwc(uint32_t seed) +``` +**Description** +Constructor. +Uses seed as the seed for the sequence. + +--- + +```cpp +void initialise(uint32_t seed) +``` +**Description** +Sets the seed as the new seed for the sequence. + +--- + +```cpp +uint32_t operator()() +``` +**Return** +The next number in the pseudo-random sequence. + +--- + +```cpp +uint32_t range(uint32_t low, uint32_t high) +``` +**Return** +A number between the specified ranges, inclusive. + +## random_pcg +Generates a 32 bit pseudo-random number using a permuted congruential generator algorithm. +The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1). + +```cpp +random_pcg() +``` +**Description** +Constructor. +Uses the address of the object as the seed for the sequence. + +--- + +```cpp +random_pcg(uint32_t seed) +``` +**Description** +Constructor. +Uses seed as the seed for the sequence. + +--- + +```cpp +void initialise(uint32_t seed) +``` +**Description** +Sets the seed as the new seed for the sequence. + +```cpp +uint32_t operator()() +``` +**Return** +The next number in the pseudo-random sequence. + +--- + +```cpp +uint32_t range(uint32_t low, uint32_t high) +``` +**Return** +A number between the specified ranges, inclusive. + +## random_hash + +```cpp +template +``` +Generates a 32 bit pseudo-random number by applying a user supplied 32bit hash to a counter. +The hash must implement void `add(uint8_t)` and `uint8_t value()` member functions. + +```cpp +random_hash() +``` +**Description** +Constructor. +Uses the address of the object as the seed for the sequence. + +--- + +```cpp +random_hash(uint32_t seed) +``` +**Description** +Constructor. +Uses seed as the seed for the sequence. + +--- + +```cpp +void initialise(uint32_t seed) +``` +**Description** +Sets the seed as the new seed for the sequence. + +--- + +```cpp +uint32_t operator()() +``` +**Return** +The next number in the pseudo-random sequence. + +--- + +```cpp +uint32_t range(uint32_t low, uint32_t high) +``` +**Return** +A number between the specified ranges, inclusive. diff --git a/docs/raw/maths/ratio.txt b/docs/maths/ratio.md similarity index 73% rename from docs/raw/maths/ratio.txt rename to docs/maths/ratio.md index 186077b7..4cb2f3f4 100644 --- a/docs/raw/maths/ratio.txt +++ b/docs/maths/ratio.md @@ -1,56 +1,80 @@ -ratio -A template constant to encode ratios. -C++11 equivalent std::ratio +--- +title: "ratio" +--- -____________________________________________________________________________________________________ +{{< callout type="info">}} + Header: `ratio.h` + Since: `TBC` + Similar to: [std::ratio](https://en.cppreference.com/w/cpp/numeric/ratio/ratio) +{{< /callout >}} + +A template constant to encode ratios. + +```cpp template struct ratio { static ETL_CONSTANT intmax_t num = NUM; static ETL_CONSTANT intmax_t den = DEN; }; +``` -num : Numerator -den : Denominator +`num` : Numerator +`den` : Denominator -____________________________________________________________________________________________________ -Predefined ratios +## Predefined ratios -If INT_MAX > INT32_MAX +If `INT_MAX` > `INT32_MAX` +```cpp typedef ratio<1, 1000000000000000000000000> yocto; typedef ratio<1, 1000000000000000000000> zepto; typedef ratio<1, 1000000000000000000> atto; typedef ratio<1, 1000000000000000> femto; typedef ratio<1, 1000000000000> pico; +``` -If INT_MAX >= INT32_MAX +If `INT_MAX` >= `INT32_MAX` +```cpp typedef ratio<1, 1000000000> nano; typedef ratio<1, 1000000> micro; +``` -If INT_MAX >= INT16_MAX +If `INT_MAX` >= `INT16_MAX` +```cpp typedef ratio<1, 1000> milli; typedef ratio<1, 100> centi; typedef ratio<1, 10> deci; typedef ratio<10, 1> deca; typedef ratio<100, 1> hecto; typedef ratio<1000, 1> kilo; +``` -If INT_MAX >= INT32_MAX +If `INT_MAX` >= `INT32_MAX` +```cpp typedef ratio<1000000, 1> mega; typedef ratio<1000000000, 1> giga; +``` -If INT_MAX > INT32_MAX +If `INT_MAX` > `INT32_MAX` +```cpp typedef ratio<1000000000000, 1> tera; typedef ratio<1000000000000000, 1> peta; typedef ratio<1000000000000000000, 1> exa; typedef ratio<1000000000000000000000, 1> zetta; typedef ratio<1000000000000000000000000, 1> yotta; +``` An approximation of PI to 6 digits. +```cpp typedef ratio<355, 113> ratio_pi; +``` An approximation of root 2. +```cpp typedef ratio<239, 169> ratio_root2; +``` An approximation of e. +```cpp typedef ratio<326, 120> ratio_e; +``` diff --git a/docs/raw/maths/Rescale.txt b/docs/maths/rescale.md similarity index 58% rename from docs/raw/maths/Rescale.txt rename to docs/maths/rescale.md index acf094fd..7ee56b8c 100644 --- a/docs/raw/maths/Rescale.txt +++ b/docs/maths/rescale.md @@ -1,23 +1,43 @@ -Rescale -20.9.0 +--- +title: "rescale" +--- + +{{< callout type="info">}} + Header: `rescale.h` + Since: `20.9.0` +{{< /callout >}} + Rescales an input range. +```cpp template class rescale : public etl::unary_function +``` -TInput The input data type. -TCompare The functor type used to compare values to the threshold. The default is etl::less -____________________________________________________________________________________________________ +`TInput` The input data type. +`TCompare` The functor type used to compare values to the threshold. The default is `etl::less`. + +--- + +```cpp rescale (TInput input_min_value, TInput input_max_value, TOutput output_min_value, TOutput output_max_value) -____________________________________________________________________________________________________ -TOutput operator()(TInput value) const -Rescale a value. -____________________________________________________________________________________________________ -Example +``` +**Description** +Sets the rescale limits. +--- + +```cpp +TOutput operator()(TInput value) const +``` +**Description** +Rescale a value. + +## Example +```cpp std::array input = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 @@ -30,4 +50,4 @@ etl::rescale rescale(10, 19, 40000, 41900); std::transform(input.begin(), input.end(), output.begin(), rescale); // output = 40000, 40211, 40422, 40633, 40844, 41055, 41266, 41477, 41688, 41900 - +``` diff --git a/docs/maths/rms.md b/docs/maths/rms.md new file mode 100644 index 00000000..86a72476 --- /dev/null +++ b/docs/maths/rms.md @@ -0,0 +1,112 @@ +--- +title: "RMS (Root Mean Square)" +--- + +{{< callout type="info">}} + Header: `rms.h` + Since: `20.9.0` +{{< /callout >}} + +```cpp +template +class rms : public etl::unary_function +``` + +`TInput` The input data type. +`TCalc` The type to use for internal calculations. By default, equal to TInput. + +--- + +```cpp +rms() +``` +**Description** +Default constructor. + +--- + +```cpp +template +rms(TIterator first, TIterator last) +``` +**Description** +Construct from an iterator range. + +--- + +```cpp +void add(TInput value1) +``` +**Description** +Add a value. + +--- + +```cpp +template +void add(TIterator first, TIterator last) +``` +**Description** +Add a range of values. + +--- + +```cpp +void operator()(TInput value) +``` +**Description** +Add a values. + +--- + +```cpp +template +void operator()(TIterator first, TIterator last) +``` +**Description** +Add a range of values. + +--- + +```cpp +double get_rms() +``` +**Return** +The calculated RMS for the data. + +--- + +```cpp +operator double() +``` +**Return** +The calculated RMS value for the data. + +--- + +```cpp +size_t count() const +``` +**Description** +Get the total number added entries. + +--- + +```cpp +void clear() +``` +Clear the mean. + +## Example +```cpp +std::array input +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 +}; + +etl::rms rms(input.begin(), input.end()); + +double rms_result; + +rms_result = rms; // rms_result == 5.21 +``` diff --git a/docs/raw/maths/Rounded integral division.txt b/docs/maths/rounded-integral-division.md similarity index 67% rename from docs/raw/maths/Rounded integral division.txt rename to docs/maths/rounded-integral-division.md index f737bb9d..ac161a08 100644 --- a/docs/raw/maths/Rounded integral division.txt +++ b/docs/maths/rounded-integral-division.md @@ -1,17 +1,26 @@ -Rounded integral division -Rounded division algorithms for integral values. -20.43.0 +--- +title: "Rounded integral division" +--- + +{{< callout type="info">}} + Header: `rounded_integral_division.h` + Since: `20.9.0` +{{< /callout >}} + +Rounded division algorithms for integral values. These algorithms perform integer division while rounding the result as though the fractional part were actually present. They do not check for a denominator of zero. -____________________________________________________________________________________________________ -divide_round_to_ceiling + +## divide_round_to_ceiling Values are rounded to the next more positive integral value. +```cpp template ETL_CONSTEXPR14 etl::common_type_t divide_round_to_ceiling(T1 numerator, T2 denominator) ETL_NOEXCEPT - +``` +```cpp .151 / 100 == 2 .150 / 100 == 2 .149 / 100 == 2 @@ -24,15 +33,18 @@ divide_round_to_ceiling(T1 numerator, T2 denominator) ETL_NOEXCEPT -149 / 100 == -1 -150 / 100 == -1 -151 / 100 == -1 -____________________________________________________________________________________________________ -divide_round_to_floor +``` + +## divide_round_to_floor Values are rounded to the next more negative integral value. +```cpp template ETL_CONSTEXPR14 etl::common_type_t divide_round_to_floor(T1 numerator, T2 denominator) ETL_NOEXCEPT - +``` +```cpp .151 / 100 == 1 .150 / 100 == 1 .149 / 100 == 1 @@ -45,15 +57,18 @@ divide_round_to_floor(T1 numerator, T2 denominator) ETL_NOEXCEPT -149 / 100 == -2 -150 / 100 == -2 -151 / 100 == -2 -____________________________________________________________________________________________________ -divide_round_to_zero +``` + +## divide_round_to_zero Values are rounded towards zero. +```cpp template ETL_CONSTEXPR14 etl::common_type_t divide_round_to_zero(T1 numerator, T2 denominator) ETL_NOEXCEPT - +``` +```cpp .151 / 100 == 1 .150 / 100 == 1 .149 / 100 == 1 @@ -66,15 +81,18 @@ divide_round_to_zero(T1 numerator, T2 denominator) ETL_NOEXCEPT -149 / 100 == -1 -150 / 100 == -1 -151 / 100 == -1 -____________________________________________________________________________________________________ -divide_round_to_infinity +``` + +## divide_round_to_infinity Values are rounded towards infinity. +```cpp template ETL_CONSTEXPR14 etl::common_type_t divide_round_to_infinity(T1 numerator, T2 denominator) ETL_NOEXCEPT - +``` +```cpp .151 / 100 == 2 .150 / 100 == 2 .149 / 100 == 2 @@ -87,15 +105,19 @@ divide_round_to_infinity(T1 numerator, T2 denominator) ETL_NOEXCEPT -149 / 100 == -2 -150 / 100 == -2 -151 / 100 == -2 -____________________________________________________________________________________________________ -divide_round_half_up -Values are rounded to the nearest integral value. 'Half' values are rounded up (towards infinity). +``` +## divide_round_half_up +Values are rounded to the nearest integral value. +'Half' values are rounded up (towards infinity). + +```cpp template ETL_CONSTEXPR14 etl::common_type_t divide_round_half_up(T1 numerator, T2 denominator) ETL_NOEXCEPT - +``` +```cpp .151 / 100 == 3 .150 / 100 == 3 .149 / 100 == 1 @@ -108,15 +130,18 @@ divide_round_half_up(T1 numerator, T2 denominator) ETL_NOEXCEPT -149 / 100 == -1 -150 / 100 == -3 -151 / 100 == -3 -____________________________________________________________________________________________________ -divide_round_half_down -Values are rounded to the nearest integral value. 'Half' values are rounded up (towards zero) +``` +## divide_round_half_down +Values are rounded to the nearest integral value. +'Half' values are rounded up (towards zero) + +```cpp template ETL_CONSTEXPR14 etl::common_type_t divide_round_half_down(T1 numerator, T2 denominator) ETL_NOEXCEPT - +```cpp .151 / 100 == 3 .150 / 100 == 2 .149 / 100 == 1 @@ -129,16 +154,19 @@ divide_round_half_down(T1 numerator, T2 denominator) ETL_NOEXCEPT -149 / 100 == -1 -150 / 100 == -2 -151 / 100 == -3 -____________________________________________________________________________________________________ -divide_round_half_even -(Banker's rounding) -Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest even value. +``` +## divide_round_half_even +(Banker's rounding) +Values are rounded to the nearest integral value. +'Half' values are rounded to the nearest even value. +```cpp template ETL_CONSTEXPR14 etl::common_type_t divide_round_half_even(T1 numerator, T2 denominator) ETL_NOEXCEPT - +``` +```cpp .151 / 100 == 2 .150 / 100 == 2 .149 / 100 == 1 @@ -151,15 +179,19 @@ divide_round_half_even(T1 numerator, T2 denominator) ETL_NOEXCEPT -149 / 100 == -1 -150 / 100 == -2 -151 / 100 == -2 -____________________________________________________________________________________________________ -divide_round_half_odd -Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest odd value. +``` +## divide_round_half_odd +Values are rounded to the nearest integral value. +'Half' values are rounded to the nearest odd value. + +```cpp template ETL_CONSTEXPR14 etl::common_type_t divide_round_half_even(T1 numerator, T2 denominator) ETL_NOEXCEPT - +``` +```cpp .151 / 100 == 2 .150 / 100 == 1 .149 / 100 == 1 @@ -172,4 +204,4 @@ divide_round_half_even(T1 numerator, T2 denominator) ETL_NOEXCEPT -149 / 100 == -1 -150 / 100 == -1 -151 / 100 == -2 - +``` diff --git a/docs/raw/maths/Scaled Rounding.txt b/docs/maths/scaled-rounding.md similarity index 60% rename from docs/raw/maths/Scaled Rounding.txt rename to docs/maths/scaled-rounding.md index 5a220a41..2ab82070 100644 --- a/docs/raw/maths/Scaled Rounding.txt +++ b/docs/maths/scaled-rounding.md @@ -1,29 +1,35 @@ -Scaled Rounding -Rounding algorithms for scaled integral values. +--- +title: "Scaled Rounding" +--- -From 20.40.1 all scaling functions are ETL_NODISCARD and ETL_CONSTEXPR14. +Rounding algorithms for scaled integral values. -It is often advantageous to use scaled integral values rather than floating point for performance reasons. -These functions will round the supplied values according to various popular rounding algorithms. -See http://www.clivemaxfield.com/diycalculator/sp-round.shtml +From `20.40.1` all scaling functions are `ETL_NODISCARD` and `ETL_CONSTEXPR14`. -The results may be scaled or unscaled. -Scaled : The result has the same scaling as the input value. -Unscaled : The result has the scaling factor removed from the input value. 'Unscaled' is a little faster than 'scaled'. +It is often advantageous to use scaled integral values rather than floating point for performance reasons. +These functions will round the supplied values according to various popular rounding algorithms. +See [http://www.clivemaxfield.com/diycalculator/sp-round.shtml](http://www.clivemaxfield.com/diycalculator/sp-round.shtml) -Assume a scaling factor of 10 for all of the examples below (simulated one decimal place). -i.e. 5.1 => 51 -____________________________________________________________________________________________________ -Round Ceiling +The results may be scaled or unscaled. +**Scaled** +The result has the same scaling as the input value. + +**Unscaled** +The result has the scaling factor removed from the input value. 'Unscaled' is a little faster than 'scaled'. + +Assume a scaling factor of `10` for all of the examples below (simulated one decimal place). +i.e. `5.1` => `51` + +## Round Ceiling Values are rounded to the next more positive integral value. -Scaling = 10 -Therefore 54 represents 5.4 - +```cpp template T round_ceiling_scaled(T value) - +``` +**Description** | +```cpp -54 => -50 -5.4 => -5.0 -55 => -50 -5.5 => -5.0 -56 => -50 -5.6 => -5.0 @@ -31,10 +37,16 @@ T round_ceiling_scaled(T value) 54 => 60 5.4 => 6.0 55 => 60 5.5 => 6.0 56 => 60 5.5 => 6.0 +``` +--- + +```cpp template T round_ceiling_unscaled(T value) - +``` +**Description** | +```cpp -54 => -5 -5.4 => -5 -55 => -5 -5.5 => -5 -56 => -5 -5.6 => -5 @@ -42,17 +54,18 @@ T round_ceiling_unscaled(T value) 54 => 6 5.4 => 6 55 => 6 5.5 => 6 56 => 6 5.6 => 6 -____________________________________________________________________________________________________ -Round Floor + ``` + +## Round Floor Values are rounded to the next more negative integral value. -Scaling = 10 -Therefore 54 represents 5.4 - +```cpp template T round_floor_scaled(T value) - +``` +**Description** | +```cpp -54 => -60 -5.4 => -6.0 -55 => -60 -5.5 => -6.0 -56 => -60 -5.6 => -6.0 @@ -60,10 +73,16 @@ T round_floor_scaled(T value) 54 => 50 5.4 => 5.0 55 => 50 5.5 => 5.0 56 => 50 5.6 => 5.0 +``` +--- + +```cpp template T round_floor_unscaled(T value) - +``` +**Description** | +```cpp -54 => -6 -5.4 => -6 -55 => -6 -5.5 => -6 -56 => -6 -5.6 => -6 @@ -71,14 +90,19 @@ T round_floor_unscaled(T value) 54 => 5 5.4 => 5 55 => 5 5.5 => 5 56 => 5 5.6 => 5 -____________________________________________________________________________________________________ -Round Half Up +``` -Values are rounded to the nearest integral value. 'Half' values are rounded up (towards infinity). +## Round Half Up +Values are rounded to the nearest integral value. +'Half' values are rounded up (towards infinity). + +```cpp template T round_half_up_scaled(T value) - +``` +**Description** | +```cpp -54 => -50 -5.4 => -5.0 -55 => -60 -5.5 => -5.0 -56 => -60 -5.6 => -5.0 @@ -86,10 +110,16 @@ T round_half_up_scaled(T value) 54 => 50 55 => 60 56 => 60 +``` +--- + +```cpp template T round_half_up_unscaled(T value) - +``` +**Description** | +```cpp -54 => -5 -55 => -6 -56 => -6 @@ -97,14 +127,19 @@ T round_half_up_unscaled(T value) 54 => 5 55 => 6 56 => 6 -____________________________________________________________________________________________________ -Round Half Down + ``` -Values are rounded to the nearest integral value. 'Half' values are rounded down (towards zero). +## Round Half Down +Values are rounded to the nearest integral value. +'Half' values are rounded down (towards zero). + +```cpp template T round_half_down_scaled(T value) - +``` +**Description** | +```cpp -54 => -50 -55 => -50 -56 => -60 @@ -112,10 +147,16 @@ T round_half_down_scaled(T value) 54 => 50 55 => 50 56 => 60 +``` +--- + +```cpp template T round_half_down_unscaled(T value) - +``` +**Description** | +```cpp -54 => -5 -55 => -5 -56 => -6 @@ -123,14 +164,20 @@ T round_half_down_unscaled(T value) 54 => 5 55 => 5 56 => 6 -____________________________________________________________________________________________________ -Round To Zero +``` + +--- + +## Round To Zero Values are rounded towards zero. +```cpp template T round_zero_scaled(T value) - +``` +**Description** | +```cpp -54 => -50 -55 => -50 -56 => -50 @@ -138,10 +185,16 @@ T round_zero_scaled(T value) 54 => 50 55 => 50 56 => 50 +``` +--- + +```cpp template T round_zero_unscaled(T value) - +``` +**Description** | +```cpp -54 => -5 -55 => -5 -56 => -5 @@ -149,15 +202,18 @@ T round_zero_unscaled(T value) 54 => 5 55 => 5 56 => 5 +``` -____________________________________________________________________________________________________ -Round To Infinity +## Round To Infinity Values are rounded towards infinity. +```cpp template T round_infinity_scaled(T value) - +``` +**Description** | +```cpp -54 => -60 -55 => -60 -56 => -60 @@ -165,10 +221,16 @@ T round_infinity_scaled(T value) 54 => 60 55 => 60 56 => 60 +``` +--- + +```cpp template T round_infinity_unscaled(T value) - +``` +**Description** | +```cpp -54 => -6 -55 => -6 -56 => -6 @@ -176,15 +238,19 @@ T round_infinity_unscaled(T value) 54 => 6 55 => 6 56 => 6 +``` -____________________________________________________________________________________________________ -Round Half Even (Banker's Rounding) +## Round Half Even (Banker's Rounding) -Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest even value. +Values are rounded to the nearest integral value. +'Half' values are rounded to the nearest even value. +```cpp template T round_half_even_scaled(T value) - +``` +**Description** | +```cpp -54 => -50 -55 => -60 -56 => -60 @@ -198,10 +264,16 @@ T round_half_even_scaled(T value) 64 => 60 65 => 60 66 => 70 +``` +--- + +```cpp template T round_half_even_unscaled(T value) - +``` +**Description** | +```cpp -54 => -5 -55 => -6 -56 => -6 @@ -215,15 +287,21 @@ T round_half_even_unscaled(T value) 64 => 6 65 => 6 66 => 7 +``` -____________________________________________________________________________________________________ -Round Half Odd +--- -Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest odd value. +## Round Half Odd +Values are rounded to the nearest integral value. +'Half' values are rounded to the nearest odd value. + +```cpp template T round_half_even_scaled(T value) - +``` +**Description** | +```cpp -54 => -50 -55 => -50 -56 => -60 @@ -237,10 +315,16 @@ T round_half_even_scaled(T value) 64 => 60 65 => 70 66 => 70 +``` +--- + +```cpp template T round_half_even_unscaled(T value) - +``` +**Description** | +```cpp -54 => -5 -55 => -5 -56 => -6 @@ -254,4 +338,4 @@ T round_half_even_unscaled(T value) 64 => 6 65 => 7 66 => 7 - +``` diff --git a/docs/maths/standard_deviation.md b/docs/maths/standard_deviation.md new file mode 100644 index 00000000..fe930b3d --- /dev/null +++ b/docs/maths/standard_deviation.md @@ -0,0 +1,132 @@ +--- +title: "standard_deviation" +--- + +{{< callout type="info">}} + Header: `standard_deviation.h` + Since: `20.9.0` +{{< /callout >}} + +```cpp +template +class standard_deviation : public etl::unary_function +``` + +`Standard_Deviation_Type` `Population` or `Sample`. +`TInput` The input data type. +`TCalc` The type to use for internal calculations. By default, equal to `TInput`. + +**Enumeration** +```cpp +standard_deviation_type +etl::standard_deviation_type::Sample +etl::standard_deviation_type::Population +``` + +--- + +```cp +standard_deviation() +``` +**Description** +Default constructor. + +--- + +```cpp +template +standard_deviation(TIterator first, TIterator last) +``` +**Description** +Construct from an iterator range. + +--- + +```cpp +void add(TInput value1) +``` +**Description** +Add a value. + +--- + +```cpp +template +void add(TIterator first, TIterator last) +``` +**Description** +Add a range of values. + +--- + +```cpp +void operator()(TInput value) +``` +**Description** +Add a values. + +--- + +```cpp +template +void operator()(TIterator first, TIterator last) +``` +**Description** +Add a range of values. + +--- + +```cpp +double get_standard_deviation() const +``` +**Return** +The calculated standard deviation for the data. + +--- + +```cpp +double get_variance() const +``` +**Return** +The calculated variance for the data. + +--- + +```cpp +operator double() const +``` +**Return** +The calculated standard deviation for the data. + +--- + +```cpp +size_t count() const +``` +**Description** +Get the total number added entries. + +--- + +```cpp +void clear() +``` +**Description** +Clear the standard deviation. + +## Example +```cpp +std::array input +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 +}; + +etl::standard_deviation + standard_deviation(input.begin(), input.end()); + +double standard_deviation_result; +double variance_result; + +standard_deviation_result = standard_deviation; // standard_deviation_result == 2.87 +variance_result = standard_deviation.get_variance(); // variance_result == 8.25 +``` diff --git a/docs/raw/maths/Threshold.txt b/docs/maths/threshold.md similarity index 58% rename from docs/raw/maths/Threshold.txt rename to docs/maths/threshold.md index 2de5e753..59c4cf68 100644 --- a/docs/raw/maths/Threshold.txt +++ b/docs/maths/threshold.md @@ -1,23 +1,40 @@ -Threshold -20.9.0 +--- +title: "threshold" +--- +{{< callout type="info">}} + Header: `threshold.h` + Since: `20.9.0` +{{< /callout >}} + +```cpp template > class threshold : public etl::unary_function +``` -TInput The input data type. -TCompare The functor type used to compare values to the threshold. The default is etl::less -____________________________________________________________________________________________________ +`TInput` The input data type. +`TCompare` The functor type used to compare values to the threshold. The default is `etl::less`. + +--- + +```cpp threshold(TInput threshold_value, TInput true_value, TInput false_value, TCompare compare = TCompare()) +``` +**Description** Constructor. -____________________________________________________________________________________________________ -TInput operator()(TInput value) const -Threshold a value. -____________________________________________________________________________________________________ -Example +--- + +```cpp +TInput operator()(TInput value) const +``` +Threshold a value. + +## Example +```cpp std::array input { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @@ -30,4 +47,4 @@ etl::threshold threshold(4, 0, 9); // Compares each value to 4 and output 0 std::transform(input.begin(), input.end(), output.begin(), threshold); // output == 0, 0, 0, 0, 9, 9, 9, 9, 9, 9 - +``` diff --git a/docs/maths/variance.md b/docs/maths/variance.md new file mode 100644 index 00000000..065897aa --- /dev/null +++ b/docs/maths/variance.md @@ -0,0 +1,119 @@ +--- +title: "variance" +--- + +```cpp +template +class variance : public etl::unary_function +``` + +`Variance_Type` `Population` or `Sample`. +`TInput` The input data type. +`TCalc` The type to use for internal calculations. By default, equal to `TInput`. + +**Enumeration** +```cpp +variance_type +etl::variance_type::Sample +etl::variance_type::Population +``` + +--- + +```cpp +variance() +``` +**Description** +Default constructor. + +--- + +```cpp +template +variance(TIterator first, TIterator last) +``` +**Description** +Construct from an iterator range. + +--- + +```cpp +void add(TInput value1) +``` +**Description** +Add a value. + +--- + +```cpp +template +void add(TIterator first, TIterator last) +``` +**Description** +Add a range of values. + +--- + +```cpp +void operator()(TInput value) +``` +**Description** +Add a values. + +--- + +```cpp +template +void operator()(TIterator first, TIterator last) +``` +**Description** +Add a range of values. + +--- + +```cpp +double get_variance() const +``` +**Return** +The calculated variance for the data. + +--- + +```cpp +operator double() const +``` +**Return** +The calculated variance for the data. + +--- + +```cpp +size_t count() const +``` +**Description** +Get the total number added entries. + +--- + +```cpp +void clear() +``` +**Description** +Clear the variance. + +--- + +## Example +```cpp +std::array input +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 +}; + +etl::variance variance(input.begin(), + input.end()); + +double variance_result; + +variance_result = variance; // variance_result == 8.25 +``` diff --git a/docs/pseudo-containers/_index.md b/docs/pseudo-containers/_index.md new file mode 100644 index 00000000..e88f4c4a --- /dev/null +++ b/docs/pseudo-containers/_index.md @@ -0,0 +1,5 @@ +--- +title: "Pseudo containers" +weight: 100 +--- + diff --git a/docs/pseudo-containers/bresenham_line.md b/docs/pseudo-containers/bresenham_line.md new file mode 100644 index 00000000..eca08b16 --- /dev/null +++ b/docs/pseudo-containers/bresenham_line.md @@ -0,0 +1,150 @@ +--- +title: "bresenham_line" +--- + +A 'pseudo' container that generates coordinates on a line between two points using the [Bresenham line algorithm](https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm). +The class has an STL-like API and is a forward iterator type container. + +**Note:** The iterator only supports pre-increment. + +```cpp +etl::bresenham_line +``` +Where `T` is the coordinate element type. + +## Member types + +```cpp +value_type etl::coordinate_2d +size_type std::size_t +difference_type std::ptrdiff_t +const_reference const value_type& +const_pointer const value_type* +const_iterator Constant forward iterator +``` + +## Constructor +```cpp +etl::bresenham_line(); +``` +**Description** +Default constructor. +Creates an empty line. + +--- + +```cpp +etl::bresenham_line(T first_x, T first_y, T last_x, T last_y); +``` +**Description** +Creates a line from pairs of coordinates. + +--- + +```cpp +etl::bresenham_line(const etl::coordinate_2d& first, const etl::coordinate_2d& last); +``` +**Description** +Creates a line from pairs of coordinates. + +## Initialisation + +```cpp +void reset(T first_x, T first_y, T last_x, T last_y); +``` +**Description** +Creates a line from pairs of coordinates. +Overwrites any current coordinates. + + +--- + +```cpp +void reset(const etl::coordinate_2d& first, const etl::coordinate_2d& last); +``` +**Description** +Creates a line from pairs of coordinates. +Overwrites any current coordinates. + +## Element access + +```cpp +const_reference front() const +``` +**Return** +A const reference to the first coordinate in the line. + +--- + +```cpp +const_reference back() const +``` +**Return** +A const reference to the last coordinate in the line. + +## Iterators + +```cpp +const_iterator begin() +``` +**Return** +An iterator to the beginning of the coordinate series. +This will reset the Bresenham line algorithm to the first coordinate. + +```cpp +const_iterator end() const +``` +**Return** An iterator to the end of the coordinate series. + +## Capacity + +```cpp +size_t size() const +``` +**Return** +The number of coordinates in the series. + +## Non-member functions +```cpp +== true if the two lines are equal, otherwise false. +!= true if the two lines are not equal, otherwise false. +``` + +## Examples + +**Plot pixels on a line** +```cpp +std::ostream& operator << (std::ostream& os, const etl::coordinate_2d& coordinate) +{ + os << "(" << coordinate.x << "," << coordinate.y << ")"; + return os; +} + +etl::coordinate_2d first = { -3, 5 }; +etl::coordinate_2d last = { 3, -5 }; + +etl::bresenham_line line(first, last); + +std::cout << "There are " + << line.size() + << " coordinates between " + << line.front() + << " and " + << line.back(); + +// Plot the pixels between first and last. +std::for_each(line.begin(), line.end(), PlotPixel); +``` + +**Create a vector of pixels on a line** +```cpp +etl::coordinate_2d first = { -3, 5 }; +etl::coordinate_2d last = { 3, -5 }; + +etl::bresenham_line line(first, last); + +std::vector> coordinates; + +// Create the vector of points on the line between first and last. +std::copy(line.begin(), line.end(), std::back_inserter(coordinates)); +``` diff --git a/docs/raw/maths/Limiter.txt b/docs/raw/maths/Limiter.txt deleted file mode 100644 index 9c726786..00000000 --- a/docs/raw/maths/Limiter.txt +++ /dev/null @@ -1,32 +0,0 @@ -Limiter -20.9.0 -Limits an input range. - -template > -class limit : public etl::unary_function - -TInput The input data type. -TCompare The functor type used to compare values to the threshold. The default is etl::less -____________________________________________________________________________________________________ -limit(TInput lowest, TInput highest) -lowest The lowest limit. -highest The highest limit. -____________________________________________________________________________________________________ -TInput operator()(TInput value) const -Limit a value. -____________________________________________________________________________________________________ -Example - -std::array input = -{ - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 -}; - -std::array output; - -etl::limiter limiter(13, 16); - -std::transform(input.begin(), input.end(), output.begin(), limiter); - -// output = 13, 13, 13, 13, 14, 15, 16, 16, 16, 16 - diff --git a/docs/raw/maths/Mean.txt b/docs/raw/maths/Mean.txt deleted file mode 100644 index 5d6b0d45..00000000 --- a/docs/raw/maths/Mean.txt +++ /dev/null @@ -1,55 +0,0 @@ -Mean -20.9.0 - -template -class mean : public etl::unary_function - -TInput The input data type. -TCalc The type to use for internal calculations. By default, equal to TInput. -____________________________________________________________________________________________________ -mean() -Default constructor. - -template -mean(TIterator first, TIterator last) -Construct from an iterator range. -____________________________________________________________________________________________________ -void add(TInput value1) -Add a value. - -template -void add(TIterator first, TIterator last) -Add a range of values. -____________________________________________________________________________________________________ -void operator()(TInput value) -Add a values. - -template -void operator()(TIterator first, TIterator last) -Add a range of values. -____________________________________________________________________________________________________ -double get_mean() const -Returns the calculated mean for the data. -____________________________________________________________________________________________________ -operator double() const -Returns the calculated mean for the data. -____________________________________________________________________________________________________ -size_t count() const -Get the total number added entries. -____________________________________________________________________________________________________ -void clear() -Clear the mean. -____________________________________________________________________________________________________ -Example - -std::array input -{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 -}; - -etl::mean mean(input.begin(), input.end()); - -double mean_result; - -mean_result = mean; // mean_result == 4.5 - diff --git a/docs/raw/maths/RMS.txt b/docs/raw/maths/RMS.txt deleted file mode 100644 index e1a51558..00000000 --- a/docs/raw/maths/RMS.txt +++ /dev/null @@ -1,56 +0,0 @@ -RMS -(Root Mean Square) -20.9.0 - -template -class rms : public etl::unary_function - -TInput The input data type. -TCalc The type to use for internal calculations. By default, equal to TInput. -____________________________________________________________________________________________________ -rms() -Default constructor. - -template -rms(TIterator first, TIterator last) -Construct from an iterator range. -____________________________________________________________________________________________________ -void add(TInput value1) -Add a value. - -template -void add(TIterator first, TIterator last) -Add a range of values. -____________________________________________________________________________________________________ -void operator()(TInput value) -Add a values. - -template -void operator()(TIterator first, TIterator last) -Add a range of values. -____________________________________________________________________________________________________ -double get_rms() -Returns the calculated RMS for the data. -____________________________________________________________________________________________________ -operator double() -Returns the calculated RMS value for the data. -____________________________________________________________________________________________________ -size_t count() const -Get the total number added entries. -____________________________________________________________________________________________________ -void clear() -Clear the mean. -____________________________________________________________________________________________________ -Example - -std::array input -{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 -}; - -etl::rms rms(input.begin(), input.end()); - -double rms_result; - -rms_result = rms; // rms_result == 5.21 - diff --git a/docs/raw/maths/Standard Deviation.txt b/docs/raw/maths/Standard Deviation.txt deleted file mode 100644 index 2c3e221b..00000000 --- a/docs/raw/maths/Standard Deviation.txt +++ /dev/null @@ -1,67 +0,0 @@ -Standard Deviation -20.9.0 - -template -class standard_deviation : public etl::unary_function - -Standard_Deviation_Type Population or Sample. -TInput The input data type. -TCalc The type to use for internal calculations. By default, equal to TInput. -____________________________________________________________________________________________________ -standard_deviation_type -etl::standard_deviation_type::Sample -etl::standard_deviation_type::Population -____________________________________________________________________________________________________ -standard_deviation -standard_deviation() -Default constructor. - -template -standard_deviation(TIterator first, TIterator last) -Construct from an iterator range. -____________________________________________________________________________________________________ -void add(TInput value1) -Add a value. - -template -void add(TIterator first, TIterator last) -Add a range of values. -____________________________________________________________________________________________________ -void operator()(TInput value) -Add a values. - -template -void operator()(TIterator first, TIterator last) -Add a range of values. -____________________________________________________________________________________________________ -double get_standard_deviation() const -Returns the calculated standard deviation for the data. -____________________________________________________________________________________________________ -double get_variance() const -Returns the calculated variance for the data. -____________________________________________________________________________________________________ -operator double() const -Returns the calculated standard deviation for the data. -____________________________________________________________________________________________________ -size_t count() const -Get the total number added entries. -____________________________________________________________________________________________________ -void clear() -Clear the standard deviation. -____________________________________________________________________________________________________ -Example - -std::array input -{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 -}; - -etl::standard_deviation - standard_deviation(input.begin(), input.end()); - -double standard_deviation_result; -double variance_result; - -standard_deviation_result = standard_deviation; // standard_deviation_result == 2.87 -variance_result = standard_deviation.get_variance(); // variance_result == 8.25 - diff --git a/docs/raw/maths/Variance.txt b/docs/raw/maths/Variance.txt deleted file mode 100644 index 6a617aab..00000000 --- a/docs/raw/maths/Variance.txt +++ /dev/null @@ -1,62 +0,0 @@ -Variance -20.9.0 - -template -class variance : public etl::unary_function - -Variance_Type Population or Sample. -TInput The input data type. -TCalc The type to use for internal calculations. By default, equal to TInput. -____________________________________________________________________________________________________ -variance_type -etl::variance_type::Sample -etl::variance_type::Population -____________________________________________________________________________________________________ -variance -variance() -Default constructor. - -template -variance(TIterator first, TIterator last) -Construct from an iterator range. -____________________________________________________________________________________________________ -void add(TInput value1) -Add a value. - -template -void add(TIterator first, TIterator last) -Add a range of values. -____________________________________________________________________________________________________ -void operator()(TInput value) -Add a values. - -template -void operator()(TIterator first, TIterator last) -Add a range of values. -____________________________________________________________________________________________________ -double get_variance() const -Returns the calculated variance for the data. -____________________________________________________________________________________________________ -operator double() const -Returns the calculated variance for the data. -____________________________________________________________________________________________________ -size_t count() const -Get the total number added entries. -____________________________________________________________________________________________________ -void clear() -Clear the variance. -____________________________________________________________________________________________________ -Example - -std::array input -{ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 -}; - -etl::variance variance(input.begin(), - input.end()); - -double variance_result; - -variance_result = variance; // variance_result == 8.25 - diff --git a/docs/raw/maths/is_negative.txt b/docs/raw/maths/is_negative.txt deleted file mode 100644 index 9593ab5e..00000000 --- a/docs/raw/maths/is_negative.txt +++ /dev/null @@ -1,7 +0,0 @@ -is_negative - -Allows a parameter of type T to be checked for a positive or negative value, while eliminating compiler warnings for checking < 0 for unsigned types. - -template -ETL_CONSTEXPR bool is_negative(const T value) - diff --git a/docs/raw/maths/radix.txt b/docs/raw/maths/radix.txt deleted file mode 100644 index 243a3a4b..00000000 --- a/docs/raw/maths/radix.txt +++ /dev/null @@ -1,13 +0,0 @@ -radix -A smart enumeration to encode radix constants. - -____________________________________________________________________________________________________ -struct radix - -Define the constants: -undefined -binary -octal -decimal -hex - diff --git a/docs/raw/maths/random.txt b/docs/raw/maths/random.txt deleted file mode 100644 index 554a6149..00000000 --- a/docs/raw/maths/random.txt +++ /dev/null @@ -1,234 +0,0 @@ -random -Utilities for producing random numbers. - -____________________________________________________________________________________________________ -random -The base class for all 32 bit random number generators. - -If ETL_POLYMORPHIC_RANDOM is defined, then the base class will have the following members, otherwise the base is empty. - -virtual ~random(); -virtual void initialise(uint32_t seed) = 0; -virtual uint32_t operator()() = 0; -virtual uint32_t range(uint32_t low, uint32_t high) = 0; - -____________________________________________________________________________________________________ -random_xorshift -Uses a 128bit XOR shift algorithm for producing a pseudo-random sequence of integers. -The result is a 32 bit integer between 0 and 4,294,967,295 (2^32 - 1). - -random_xor_shift() - -Constructor. -Uses the address of the object as the seed for the sequence. - -random_xor_shift(uint32_t seed) - -Constructor. -Uses seed as the seed for the sequence. - -void initialise(uint32_t seed) - -Sets the seed as the new seed for the sequence. - -uint32_t operator()() - -Returns the next number in the pseudo-random sequence. - -uint32_t range(uint32_t low, uint32_t high) - -Returns a number between the specified ranges, inclusive. - -____________________________________________________________________________________________________ -random_lcg -Generates a 32 bit pseudo-random number using a linear congruent generator. -The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1). - -____________________________________________________________________________________________________ -random_lcg() - -Constructor. -Uses the address of the object as the seed for the sequence - -____________________________________________________________________________________________________ -random_lcg(uint32_t seed) - -Constructor. -Uses seed as the seed for the sequence. - -____________________________________________________________________________________________________ -void initialise(uint32_t seed) - -Sets the seed as the new seed for the sequence. - -____________________________________________________________________________________________________ -uint32_t operator()() - -Returns the next number in the pseudo-random sequence. - -____________________________________________________________________________________________________ -uint32_t range(uint32_t low, uint32_t high) - -Returns a number between the specified ranges, inclusive. - -____________________________________________________________________________________________________ -random_clcg -Generates a 32 bit pseudo-random number using a combined linear congruent generator. -The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1). - -____________________________________________________________________________________________________ -random_clcg() - -Constructor. -Uses the address of the object as the seed for the sequence. - -____________________________________________________________________________________________________ -random_clcg(uint32_t seed) - -Constructor. -Uses seed as the seed for the sequence. - -____________________________________________________________________________________________________ -void initialise(uint32_t seed) - -Sets the seed as the new seed for the sequence. - -____________________________________________________________________________________________________ -uint32_t operator()() - -Returns the next number in the pseudo-random sequence. - -____________________________________________________________________________________________________ -uint32_t range(uint32_t low, uint32_t high) -Returns a number between the specified ranges, inclusive. - -____________________________________________________________________________________________________ -random_lsfr -Generates a 32 bit pseudo-random number using a linear shift feedback register. -The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1). -The seed must not be zero. The output does not include zero. - -____________________________________________________________________________________________________ -random_lsfr() - -Constructor. -Uses the address of the object as the seed for the sequence. - -____________________________________________________________________________________________________ -random_lsfr(uint32_t seed) - -Constructor. -Uses seed as the seed for the sequence. - -____________________________________________________________________________________________________ -void initialise(uint32_t seed) - -Sets the seed as the new seed for the sequence. - -____________________________________________________________________________________________________ -uint32_t operator()() - -Returns the next number in the pseudo-random sequence. - -____________________________________________________________________________________________________ -uint32_t range(uint32_t low, uint32_t high) - -Returns a number between the specified ranges, inclusive. - -____________________________________________________________________________________________________ -random_mwc -Generates a 32 bit pseudo-random number using a multiply-with-carry algorithm. -The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1). - -____________________________________________________________________________________________________ -random_mwc() - -Constructor. -Uses the address of the object as the seed for the sequence. - -____________________________________________________________________________________________________ -random_mwc(uint32_t seed) - -Constructor. -Uses seed as the seed for the sequence. - -____________________________________________________________________________________________________ -void initialise(uint32_t seed) - -Sets the seed as the new seed for the sequence. - -____________________________________________________________________________________________________ -uint32_t operator()() - -Returns the next number in the pseudo-random sequence. - -____________________________________________________________________________________________________ -uint32_t range(uint32_t low, uint32_t high) - -Returns a number between the specified ranges, inclusive. - -____________________________________________________________________________________________________ -random_pcg -Generates a 32 bit pseudo-random number using a permuted congruential generator algorithm. -The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1). - -____________________________________________________________________________________________________ -random_pcg() - -Constructor. -Uses the address of the object as the seed for the sequence. - -____________________________________________________________________________________________________ -random_pcg(uint32_t seed) - -Constructor. -Uses seed as the seed for the sequence. - -____________________________________________________________________________________________________ -void initialise(uint32_t seed) - -Sets the seed as the new seed for the sequence. - -____________________________________________________________________________________________________ -uint32_t operator()() - -Returns the next number in the pseudo-random sequence. - -____________________________________________________________________________________________________ -uint32_t range(uint32_t low, uint32_t high) - -Returns a number between the specified ranges, inclusive. - -____________________________________________________________________________________________________ -random_hash - -template -Generates a 32 bit pseudo-random number by applying a user supplied 32bit hash to a counter. -The hash must implement void add(uint8_t) and uint8_t value() member functions. -____________________________________________________________________________________________________ -random_hash() - -Constructor. -Uses the address of the object as the seed for the sequence. - -____________________________________________________________________________________________________ -random_hash(uint32_t seed) - -Constructor. -Uses seed as the seed for the sequence. - -____________________________________________________________________________________________________ -void initialise(uint32_t seed) - -Sets the seed as the new seed for the sequence. - -____________________________________________________________________________________________________ -uint32_t operator()() - -Returns the next number in the pseudo-random sequence. - -____________________________________________________________________________________________________ -uint32_t range(uint32_t low, uint32_t high) - -Returns a number between the specified ranges, inclusive. -