CiCueTea v0.0.1
Loading...
Searching...
No Matches
MathUtils.h File Reference

Some Mathematical functions used in the library. More...

#include <cmath>
#include <Eigen/Core>

Go to the source code of this file.

Functions

constexpr size_t jsa::cicuetea::nextPow2 (size_t x)
 Computes the next power of 2 greater than or equal to the given number.
size_t jsa::cicuetea::constrain (size_t idx, size_t size)
 Constrains an index to fit within the bounds of a given size by wrapping it around.
double jsa::cicuetea::square (double x)
 Computes the square of a given number.
Eigen::ArrayXd jsa::cicuetea::regspace (Eigen::Index num)
 Generates a linearly spaced array of values from 0 to num-1.
Eigen::ArrayXd jsa::cicuetea::regspace (Eigen::Index low, Eigen::Index high)
 Generates a linearly spaced array of values between a specified range.
Eigen::ArrayXd jsa::cicuetea::logspace (double start, double end, Eigen::Index num)
 Generates a logarithmically spaced array.

Detailed Description

Some Mathematical functions used in the library.

Author
Juan Sierra
Date
3/23/25

Function Documentation

◆ constrain()

size_t jsa::cicuetea::constrain ( size_t idx,
size_t size )
inline

Constrains an index to fit within the bounds of a given size by wrapping it around.

This function ensures that the provided index remains within the range [0, size - 1] by using the modulo operation. It is useful for cyclic or circular indexing.

Parameters
idxThe index to be constrained.
sizeThe size of the range within which the index should be constrained.
Returns
The constrained index within the range [0, size - 1].

◆ logspace()

Eigen::ArrayXd jsa::cicuetea::logspace ( double start,
double end,
Eigen::Index num )
inline

Generates a logarithmically spaced array.

This function creates an array of num elements, logarithmically spaced between start and end. The values are computed using the natural logarithm and then exponentiated to return the final array.

Parameters
startThe starting value of the sequence (must be positive).
endThe ending value of the sequence (must be positive).
numThe number of elements in the sequence.
Returns
Eigen::ArrayXd A logarithmically spaced array of size num.
Note
The start and end parameters must be greater than zero, as the logarithm of non-positive numbers is undefined.

◆ nextPow2()

size_t jsa::cicuetea::nextPow2 ( size_t x)
inlineconstexpr

Computes the next power of 2 greater than or equal to the given number.

This function calculates the smallest power of 2 that is greater than or equal to the input value x. If x is 0, the function returns 1.

Parameters
xThe input value for which the next power of 2 is to be computed.
Returns
The next power of 2 greater than or equal to x.
Note
This function uses bitwise operations to efficiently compute the result. It assumes that the input is within the range of a 64-bit unsigned integer.

◆ regspace() [1/2]

Eigen::ArrayXd jsa::cicuetea::regspace ( Eigen::Index low,
Eigen::Index high )
inline

Generates a linearly spaced array of values between a specified range.

This function creates an Eigen::ArrayXd containing evenly spaced values starting from low and ending at high, inclusive. The number of elements in the array is determined by the difference between high and low plus one.

Parameters
lowThe starting value of the range (inclusive).
highThe ending value of the range (inclusive).
Returns
Eigen::ArrayXd A 1D array of linearly spaced values from low to high.

◆ regspace() [2/2]

Eigen::ArrayXd jsa::cicuetea::regspace ( Eigen::Index num)
inline

Generates a linearly spaced array of values from 0 to num-1.

Parameters
numThe number of elements in the resulting array.
Returns
Eigen::ArrayXd A 1D array containing linearly spaced values from 0 to num-1.

◆ square()

double jsa::cicuetea::square ( double x)
inline

Computes the square of a given number.

This function takes a double-precision floating-point number as input and returns its square (the number multiplied by itself).

Parameters
xThe number to be squared.
Returns
The square of the input number.