JUCE

- Main Page
- Related Pages
- Topics
- Classes
- Files

Loading...
Searching...
No Matches
Namespaces | Classes | Macros | Typedefs | Functions
maths
juce_core

## Namespaces
namespace | TypeHelpers
| This namespace contains a few template classes for helping work out class type variations.

## Classes
class | BigInteger
| An arbitrarily large integer class. More...
class | Expression
| A class for dynamically evaluating simple numeric expressions. More...
class | Expression::Scope
| When evaluating an Expression object, this class is used to resolve symbols and perform functions that the expression uses. More...
class | Expression::Scope::Visitor
| Used as a callback by the Scope::visitRelativeScope() method. More...
struct | Expression::Symbol
| Represents a symbol that is used in an Expression. More...
struct | MathConstants< FloatType >
| Commonly used mathematical constants. More...
class | Tolerance< Type >
| A class encapsulating both relative and absolute tolerances for use in floating-point comparisons. More...
struct | TypeHelpers::ParameterType< Type >
| The ParameterType struct is used to find the best type to use when passing some kind of object as a parameter. More...
class | NormalisableRange< ValueType >
| Represents a mapping between an arbitrary range of values and a normalised 0->1 range. More...
class | Random
| A random number generator. More...
class | Range< ValueType >
| A general-purpose range object, that simply represents any linear range with a start and end point. More...
class | StatisticsAccumulator< FloatType >
| A class that measures various statistics about a series of floating point values that it is given. More...

## Macros
#define | JUCE_UNDENORMALISE(x) { (x) += 0.1f; (x) -= 0.1f; }
| This macro can be applied to a float variable to check whether it contains a denormalised value, and to normalise it if necessary.

## Typedefs
using | int8 = signed char
| A platform-independent 8-bit signed integer type.
using | uint8 = unsigned char
| A platform-independent 8-bit unsigned integer type.
using | int16 = signed short
| A platform-independent 16-bit signed integer type.
using | uint16 = unsigned short
| A platform-independent 16-bit unsigned integer type.
using | int32 = signed int
| A platform-independent 32-bit signed integer type.
using | uint32 = unsigned int
| A platform-independent 32-bit unsigned integer type.
using | int64 = long long
| A platform-independent 64-bit integer type.
using | uint64 = unsigned long long
| A platform-independent 64-bit unsigned integer type.
using | pointer_sized_int = int
| A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it.
using | pointer_sized_uint = unsigned int
| An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it.

## Functions
OutputStream &JUCE_CALLTYPE | operator<< (OutputStream &stream, const BigInteger &value)
| Writes a BigInteger to an OutputStream as a UTF8 decimal string.
template<typename... Types>
void | ignoreUnused (Types &&...) noexcept
| Handy function for avoiding unused variables warning.
template<typename Type , size_t N>
constexpr int | numElementsInArray (Type(&)[N]) noexcept
| Handy function for getting the number of elements in a simple const C array.
template<typename Type >
Type | juce_hypot (Type a, Type b) noexcept
| Using juce_hypot is easier than dealing with the different types of hypot function that are provided by the various platforms and compilers.
template<typename FloatType >
constexpr FloatType | degreesToRadians (FloatType degrees) noexcept
| Converts an angle in degrees to radians.
template<typename FloatType >
constexpr FloatType | radiansToDegrees (FloatType radians) noexcept
| Converts an angle in radians to degrees.
template<typename NumericType >
bool | juce_isfinite (NumericType value) noexcept
| The isfinite() method seems to vary between platforms, so this is a platform-independent function for it.
template<typename Type >
constexpr bool | exactlyEqual (Type a, Type b)
| Equivalent to operator==, but suppresses float-equality warnings.
template<typename Type , std::enable_if_t< std::is_floating_point_v< Type >, int > = 0>
constexpr bool | approximatelyEqual (Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
| Returns true if the two floating-point numbers are approximately equal.
template<typename Type , std::enable_if_t<! std::is_floating_point_v< Type >, int > = 0>
constexpr bool | approximatelyEqual (Type a, Type b)
| Special case for non-floating-point types that returns true if both are exactly equal.
template<typename FloatType >
FloatType | nextFloatUp (FloatType value) noexcept
| Returns the next representable value by FloatType in the direction of the largest representable value.
template<typename FloatType >
FloatType | nextFloatDown (FloatType value) noexcept
| Returns the next representable value by FloatType in the direction of the lowest representable value.
template<typename Type >
constexpr Type | jmax (Type a, Type b)
| Returns the larger of two values.
template<typename Type >
constexpr Type | jmax (Type a, Type b, Type c)
| Returns the larger of three values.
template<typename Type >
constexpr Type | jmax (Type a, Type b, Type c, Type d)
| Returns the larger of four values.
template<typename Type >
constexpr Type | jmin (Type a, Type b)
| Returns the smaller of two values.
template<typename Type >
constexpr Type | jmin (Type a, Type b, Type c)
| Returns the smaller of three values.
template<typename Type >
constexpr Type | jmin (Type a, Type b, Type c, Type d)
| Returns the smaller of four values.
template<typename Type >
constexpr Type | jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)
| Remaps a normalised value (between 0 and 1) to a target range.
template<typename Type >
Type | jmap (Type sourceValue, Type sourceRangeMin, Type sourceRangeMax, Type targetRangeMin, Type targetRangeMax)
| Remaps a value from a source range to a target range.
template<typename Type >
Type | mapToLog10 (Type value0To1, Type logRangeMin, Type logRangeMax)
| Remaps a normalised value (between 0 and 1) to a logarithmic target range.
template<typename Type >
Type | mapFromLog10 (Type valueInLogRange, Type logRangeMin, Type logRangeMax)
| Remaps a logarithmic value in a target range to a normalised value (between 0 and 1).
template<typename Type , typename Size >
Type | findMinimum (const Type *data, Size numValues)
| Scans an array of values, returning the minimum value that it contains.
template<typename Type , typename Size >
Type | findMaximum (const Type *values, Size numValues)
| Scans an array of values, returning the maximum value that it contains.
template<typename Type >
void | findMinAndMax (const Type *values, int numValues, Type &lowest, Type &highest)
| Scans an array of values, returning the minimum and maximum values that it contains.
template<typename Type >
Type | jlimit (Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
| Constrains a value to keep it within a given range.
template<typename Type1 , typename Type2 >
bool | isPositiveAndBelow (Type1 valueToTest, Type2 upperLimit) noexcept
| Returns true if a value is at least zero, and also below a specified upper limit.
template<typename Type >
bool | isPositiveAndBelow (int valueToTest, Type upperLimit) noexcept
template<typename Type1 , typename Type2 >
bool | isPositiveAndNotGreaterThan (Type1 valueToTest, Type2 upperLimit) noexcept
| Returns true if a value is at least zero, and also less than or equal to a specified upper limit.
template<typename Type >
bool | isPositiveAndNotGreaterThan (int valueToTest, Type upperLimit) noexcept
template<typename Type >
bool | isWithin (Type a, Type b, Type tolerance) noexcept
| Computes the absolute difference between two values and returns true if it is less than or equal to a given tolerance, otherwise it returns false.
template<typename FloatType >
int | roundToInt (const FloatType value) noexcept
| Fast floating-point-to-integer conversion.
int | roundToInt (int value) noexcept
int | roundToIntAccurate (double value) noexcept
| Fast floating-point-to-integer conversion.
template<typename FloatType >
unsigned int | truncatePositiveToUnsignedInt (FloatType value) noexcept
| Truncates a positive floating-point number to an unsigned int.
template<typename IntegerType >
constexpr bool | isPowerOfTwo (IntegerType value)
| Returns true if the specified integer is a power-of-two.
int | nextPowerOfTwo (int n) noexcept
| Returns the smallest power-of-two which is equal to or greater than the given integer.
int | findHighestSetBit (uint32 n) noexcept
| Returns the index of the highest set bit in a (non-zero) number.
constexpr int | countNumberOfBits (uint32 n) noexcept
| Returns the number of bits in a 32-bit integer.
constexpr int | countNumberOfBits (uint64 n) noexcept
| Returns the number of bits in a 64-bit integer.
template<typename IntegerType >
IntegerType | negativeAwareModulo (IntegerType dividend, const IntegerType divisor) noexcept
| Performs a modulo operation, but can cope with the dividend being negative.
template<typename NumericType >
constexpr NumericType | square (NumericType n) noexcept
| Returns the square of its argument.
void | writeLittleEndianBitsInBuffer (void *targetBuffer, uint32 startBit, uint32 numBits, uint32 value) noexcept
| Writes a number of bits into a memory buffer at a given bit index.
uint32 | readLittleEndianBitsInBuffer (const void *sourceBuffer, uint32 startBit, uint32 numBits) noexcept
| Reads a number of bits from a buffer at a given bit index.
template<typename T >
constexpr auto | toUnderlyingType (T t) -> std::enable_if_t< std::is_enum_v< T >, std::underlying_type_t< T > >
| Converts an enum to its underlying integral type.

## Detailed Description

## Macro Definition Documentation

## ◆ JUCE_UNDENORMALISE

#define JUCE_UNDENORMALISE | ( |  | x | ) | { (x) += 0.1f; (x) -= 0.1f; }

This macro can be applied to a float variable to check whether it contains a denormalised value, and to normalise it if necessary.

On CPUs that aren't vulnerable to denormalisation problems, this will have no effect.

## Typedef Documentation

## ◆ int8

using int8 = signed char

A platform-independent 8-bit signed integer type.

## ◆ uint8

using uint8 = unsigned char

A platform-independent 8-bit unsigned integer type.

## ◆ int16

using int16 = signed short

A platform-independent 16-bit signed integer type.

## ◆ uint16

using uint16 = unsigned short

A platform-independent 16-bit unsigned integer type.

## ◆ int32

using int32 = signed int

A platform-independent 32-bit signed integer type.

## ◆ uint32

using uint32 = unsigned int

A platform-independent 32-bit unsigned integer type.

## ◆ int64

using int64 = long long

A platform-independent 64-bit integer type.

## ◆ uint64

using uint64 = unsigned long long

A platform-independent 64-bit unsigned integer type.

## ◆ pointer_sized_int

using pointer_sized_int = int

A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it.

## ◆ pointer_sized_uint

using pointer_sized_uint = unsigned int

An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it.

## Function Documentation

## ◆ operator<<()

OutputStream &JUCE_CALLTYPE operator<< | ( | OutputStream & | stream,
|  | const BigInteger & | value )

Writes a BigInteger to an OutputStream as a UTF8 decimal string.

## ◆ ignoreUnused()

template<typename... Types>

void ignoreUnused | ( | Types && | ... | ) |
| noexcept

Handy function for avoiding unused variables warning.

Referenced by juce_isfinite(), and RectangleList< ValueType >::subtract().

## ◆ numElementsInArray()

template<typename Type , size_t N>

constexpr int numElementsInArray | ( | Type(&) | [N] | ) |
| constexpr noexcept

Handy function for getting the number of elements in a simple const C array.

E.g.

static int myArray[] = { 1, 2, 3 };
int numElements = numElementsInArray (myArray) // returns 3
numElementsInArray
constexpr int numElementsInArray(Type(&)[N]) noexcept
Handy function for getting the number of elements in a simple const C array.
Definition juce_MathsFunctions.h:104

Referenced by AudioBuffer< Type >::AudioBuffer(), and AudioBuffer< Type >::operator=().

## ◆ juce_hypot()

template<typename Type >

Type juce_hypot | ( | Type | a,
|  | Type | b )
| noexcept

Using juce_hypot is easier than dealing with the different types of hypot function that are provided by the various platforms and compilers.

Referenced by Point< ValueType >::getDistanceFrom(), Point< ValueType >::getDistanceFromOrigin(), and Line< ValueType >::getPointAlongLine().

## ◆ degreesToRadians()

template<typename FloatType >

constexpr FloatType degreesToRadians | ( | FloatType | degrees | ) |
| constexpr noexcept

Converts an angle in degrees to radians.

## ◆ radiansToDegrees()

template<typename FloatType >

constexpr FloatType radiansToDegrees | ( | FloatType | radians | ) |
| constexpr noexcept

Converts an angle in radians to degrees.

## ◆ juce_isfinite()

template<typename NumericType >

bool juce_isfinite | ( | NumericType | value | ) |
| noexcept

The isfinite() method seems to vary between platforms, so this is a platform-independent function for it.

References ignoreUnused().

Referenced by StatisticsAccumulator< FloatType >::addValue(), Point< ValueType >::isFinite(), and Rectangle< ValueType >::isFinite().

## ◆ exactlyEqual()

template<typename Type >

constexpr bool exactlyEqual | ( | Type | a,
|  | Type | b )
| constexpr

Equivalent to operator==, but suppresses float-equality warnings.

This allows code to be explicit about float-equality checks that are known to have the correct semantics.

References JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE, and JUCE_END_IGNORE_WARNINGS_GCC_LIKE.

Referenced by Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::contains(), NormalisableRange< ValueType >::convertFrom0to1(), NormalisableRange< ValueType >::convertTo0to1(), Rectangle< ValueType >::enlargeIfAdjacent(), UnitTest::expectEquals(), UnitTest::expectNotEquals(), Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::indexOf(), Range< ValueType >::isEmpty(), ArrayBase< ElementType, TypeOfCriticalSectionToUse >::operator==(), CachedValue< Type >::setValue(), and String::toDecimalStringWithSignificantFigures().

## ◆ approximatelyEqual() [1/2]

template<typename Type , std::enable_if_t< std::is_floating_point_v< Type >, int > = 0>

constexpr bool approximatelyEqual | ( | Type | a,
|  | Type | b,
|  | Tolerance< Type > | tolerance = Tolerance<Type>{} .withAbsolute (std::numeric_limits<Type>::min()) .withRelative (std::numeric_limits<Type>::epsilon()) )
| constexpr

Returns true if the two floating-point numbers are approximately equal.

If either a or b are not finite, returns exactlyEqual (a, b).

The default absolute tolerance is equal to the minimum normal value. This ensures differences that are subnormal are always considered equal. It is highly recommend this value is reviewed depending on the calculation being carried out. In general specifying an absolute value is useful when considering values close to zero. For example you might expect sin (pi) to return 0, but what it actually returns is close to the error of the value pi. Therefore, in this example it might be better to set the absolute tolerance to sin (pi).

The default relative tolerance is equal to the machine epsilon which is the difference between 1.0 and the next floating-point value that can be represented by Type. In most cases this value is probably reasonable. This value is multiplied by the largest absolute value of a and b so as to scale relatively according to the input parameters. For example, specifying a relative value of 0.05 will ensure values return equal if the difference between them is less than or equal to 5% of the larger of the two absolute values.

Parameters

  a | The first number to compare.
  b | The second number to compare.
  tolerance | An object that represents both absolute and relative tolerances when evaluating if a and b are equal.

See also
  exactlyEqual

Referenced by AudioBuffer< Type >::addFrom(), AudioBuffer< Type >::addFrom(), AudioBuffer< Type >::addFromWithRamp(), AudioBuffer< Type >::applyGain(), AudioBuffer< Type >::applyGainRamp(), AudioBuffer< Type >::copyFrom(), AudioBuffer< Type >::copyFromWithRamp(), Line< ValueType >::getPointAlongLine(), AudioProcessorGraph::Node::isBypassed(), juce::AnimatedPositionBehaviours::ContinuousWithMomentum::isStopped(), jmap(), juce::dsp::Bias< FloatType >::setRampDurationSeconds(), juce::dsp::Gain< FloatType >::setRampDurationSeconds(), SmoothedValue< FloatType, SmoothingType >::setTargetValue(), juce::dsp::LogRampedValue< FloatType >::setTargetValue(), and SmoothedValue< FloatType, SmoothingType >::SmoothedValue().

## ◆ approximatelyEqual() [2/2]

template<typename Type , std::enable_if_t<! std::is_floating_point_v< Type >, int > = 0>

constexpr bool approximatelyEqual | ( | Type | a,
|  | Type | b )
| constexpr

Special case for non-floating-point types that returns true if both are exactly equal.

## ◆ nextFloatUp()

template<typename FloatType >

FloatType nextFloatUp | ( | FloatType | value | ) |
| noexcept

Returns the next representable value by FloatType in the direction of the largest representable value.

## ◆ nextFloatDown()

template<typename FloatType >

FloatType nextFloatDown | ( | FloatType | value | ) |
| noexcept

Returns the next representable value by FloatType in the direction of the lowest representable value.

## ◆ jmax() [1/3]

template<typename Type >

constexpr Type jmax | ( | Type | a,
|  | Type | b )
| constexpr

Returns the larger of two values.

Referenced by Rectangle< ValueType >::enlargeIfAdjacent(), Rectangle< ValueType >::expand(), Rectangle< ValueType >::expanded(), Rectangle< ValueType >::findAreaContainingPoints(), Decibels::gainToDecibels(), Decibels::gainWithLowerBound(), RectangleList< ValueType >::getBounds(), Rectangle< ValueType >::getIntersection(), Range< ValueType >::getIntersectionWith(), AudioBuffer< Type >::getMagnitude(), AudioBuffer< Type >::getMagnitude(), juce::dsp::Polynomial< FloatingType >::getProductWith(), Rectangle< ValueType >::getUnion(), Range< ValueType >::getUnionWith(), Range< ValueType >::getUnionWith(), Rectangle< ValueType >::intersectRectangle(), Rectangle< ValueType >::intersectRectangles(), jmax(), juce::dsp::Chorus< SampleType >::process(), juce::dsp::FIR::Filter< SampleType >::reset(), ResizableBorderComponent::Zone::resizeRectangleBy(), Rectangle< ValueType >::setLeft(), Range< ValueType >::setLength(), TextEditor::setLineSpacing(), Draggable3DOrientation::setRadius(), Rectangle< ValueType >::setTop(), StandalonePluginHolder::showAudioSettingsDialog(), Rectangle< ValueType >::transformedBy(), Rectangle< ValueType >::withBottom(), Rectangle< ValueType >::withHeight(), Rectangle< ValueType >::withLeft(), Rectangle< ValueType >::withRight(), Rectangle< ValueType >::withSize(), Range< ValueType >::withStart(), Rectangle< ValueType >::withTop(), and Rectangle< ValueType >::withWidth().

## ◆ jmax() [2/3]

template<typename Type >

constexpr Type jmax | ( | Type | a,
|  | Type | b,
|  | Type | c )
| constexpr

Returns the larger of three values.

## ◆ jmax() [3/3]

template<typename Type >

constexpr Type jmax | ( | Type | a,
|  | Type | b,
|  | Type | c,
|  | Type | d )
| constexpr

Returns the larger of four values.

References jmax().

## ◆ jmin() [1/3]

template<typename Type >

constexpr Type jmin | ( | Type | a,
|  | Type | b )
| constexpr

Returns the smaller of two values.

Referenced by Rectangle< ValueType >::constrainedWithin(), juce::dsp::AudioBlock< SampleType >::copyTo(), SelectedItemSet< SelectableItemType >::deselectAll(), Rectangle< ValueType >::enlargeIfAdjacent(), Rectangle< ValueType >::findAreaContainingPoints(), RectangleList< ValueType >::getBounds(), Rectangle< ValueType >::getIntersection(), Range< ValueType >::getIntersectionWith(), Rectangle< ValueType >::getUnion(), Range< ValueType >::getUnionWith(), Range< ValueType >::getUnionWith(), Rectangle< ValueType >::intersectRectangle(), Rectangle< ValueType >::intersectRectangles(), jmin(), juce::dsp::ProcessorDuplicator< MonoProcessorType, StateType >::process(), juce::dsp::Oscillator< SampleType >::process(), juce::dsp::Phaser< SampleType >::process(), SingleThreadedAbstractFifo::read(), Rectangle< ValueType >::removeFromBottom(), Rectangle< ValueType >::removeFromLeft(), Rectangle< ValueType >::removeFromRight(), Rectangle< ValueType >::removeFromTop(), ResizableBorderComponent::Zone::resizeRectangleBy(), SelectedItemSet< SelectableItemType >::selectOnly(), Rectangle< ValueType >::setBottom(), Rectangle< ValueType >::setRight(), AudioBuffer< Type >::setSize(), Rectangle< ValueType >::transformedBy(), PixelARGB::unpremultiply(), Rectangle< ValueType >::withBottom(), Range< ValueType >::withEnd(), Rectangle< ValueType >::withRight(), Line< ValueType >::withShortenedEnd(), Line< ValueType >::withShortenedStart(), and SingleThreadedAbstractFifo::write().

## ◆ jmin() [2/3]

template<typename Type >

constexpr Type jmin | ( | Type | a,
|  | Type | b,
|  | Type | c )
| constexpr

Returns the smaller of three values.

## ◆ jmin() [3/3]

template<typename Type >

constexpr Type jmin | ( | Type | a,
|  | Type | b,
|  | Type | c,
|  | Type | d )
| constexpr

Returns the smaller of four values.

References jmin().

## ◆ jmap() [1/2]

template<typename Type >

constexpr Type jmap | ( | Type | value0To1,
|  | Type | targetRangeMin,
|  | Type | targetRangeMax )
| constexpr

Remaps a normalised value (between 0 and 1) to a target range.

This effectively returns (targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin)).

Referenced by juce::dsp::LogRampedValue< FloatType >::getNextValue(), juce::dsp::LookupTable< FloatType >::getUnchecked(), and juce::dsp::LogRampedValue< FloatType >::skip().

## ◆ jmap() [2/2]

template<typename Type >

Type jmap | ( | Type | sourceValue,
|  | Type | sourceRangeMin,
|  | Type | sourceRangeMax,
|  | Type | targetRangeMin,
|  | Type | targetRangeMax )

Remaps a value from a source range to a target range.

References approximatelyEqual(), and jassert.

## ◆ mapToLog10()

template<typename Type >

Type mapToLog10 | ( | Type | value0To1,
|  | Type | logRangeMin,
|  | Type | logRangeMax )

Remaps a normalised value (between 0 and 1) to a logarithmic target range.

The entire target range must be greater than zero.

See also
  mapFromLog10

mapToLog10 (0.5, 0.4, 40.0) == 4.0
mapToLog10
Type mapToLog10(Type value0To1, Type logRangeMin, Type logRangeMax)
Remaps a normalised value (between 0 and 1) to a logarithmic target range.
Definition juce_MathsFunctions.h:391

References jassert.

Referenced by juce::dsp::Phaser< SampleType >::process().

## ◆ mapFromLog10()

template<typename Type >

Type mapFromLog10 | ( | Type | valueInLogRange,
|  | Type | logRangeMin,
|  | Type | logRangeMax )

Remaps a logarithmic value in a target range to a normalised value (between 0 and 1).

The entire target range must be greater than zero.

See also
  mapToLog10

mapFromLog10 (4.0, 0.4, 40.0) == 0.5
mapFromLog10
Type mapFromLog10(Type valueInLogRange, Type logRangeMin, Type logRangeMax)
Remaps a logarithmic value in a target range to a normalised value (between 0 and 1).
Definition juce_MathsFunctions.h:413

References jassert.

## ◆ findMinimum()

template<typename Type , typename Size >

Type findMinimum | ( | const Type * | data,
|  | Size | numValues )

Scans an array of values, returning the minimum value that it contains.

## ◆ findMaximum()

template<typename Type , typename Size >

Type findMaximum | ( | const Type * | values,
|  | Size | numValues )

Scans an array of values, returning the maximum value that it contains.

## ◆ findMinAndMax()

template<typename Type >

void findMinAndMax | ( | const Type * | values,
|  | int | numValues,
|  | Type & | lowest,
|  | Type & | highest )

Scans an array of values, returning the minimum and maximum values that it contains.

Referenced by AudioData::Pointer< SampleFormat, Endianness, InterleavingType, Constness >::findMinAndMax().

## ◆ jlimit()

template<typename Type >

Type jlimit | ( | Type | lowerLimit,
|  | Type | upperLimit,
|  | Type | valueToConstrain )
| noexcept

Constrains a value to keep it within a given range.

This will check that the specified value lies between the lower and upper bounds specified, and if not, will return the nearest value that would be in-range. Effectively, it's like calling jmax (lowerLimit, jmin (upperLimit, value)).

Note that it expects that lowerLimit <= upperLimit. If this isn't true, the results will be unpredictable.

Parameters

  lowerLimit | the minimum value to return
  upperLimit | the maximum value to return
  valueToConstrain | the value to try to return

Returns
  the closest value to valueToConstrain which lies between lowerLimit and upperLimit (inclusive)

See also
  jmin, jmax, jmap

References jassert.

Referenced by Range< ValueType >::clipValue(), Range< ValueType >::constrainRange(), Line< ValueType >::findNearestProportionalPositionTo(), Rectangle< ValueType >::getConstrainedPoint(), juce::dsp::Phaser< SampleType >::process(), juce::dsp::LookupTableTransform< FloatType >::processSample(), Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::removeRange(), ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::removeRange(), OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::removeRange(), MPEKeyboardComponent::setLift(), MPEKeyboardComponent::setPressure(), and MPEKeyboardComponent::setVelocity().

## ◆ isPositiveAndBelow() [1/2]

template<typename Type1 , typename Type2 >

bool isPositiveAndBelow | ( | Type1 | valueToTest,
|  | Type2 | upperLimit )
| noexcept

Returns true if a value is at least zero, and also below a specified upper limit.

This is basically a quicker way to write:

valueToTest >= 0 && valueToTest < upperLimit

References jassert.

Referenced by AudioBuffer< Type >::addFrom(), AudioBuffer< Type >::addFrom(), AudioBuffer< Type >::addFromWithRamp(), juce::dsp::AudioBlock< SampleType >::addSample(), AudioBuffer< Type >::addSample(), AudioBuffer< Type >::applyGain(), AudioBuffer< Type >::applyGainRamp(), AudioBuffer< Type >::clear(), AudioBuffer< Type >::copyFrom(), AudioBuffer< Type >::copyFrom(), AudioBuffer< Type >::copyFrom(), AudioBuffer< Type >::copyFromWithRamp(), AudioBuffer< Type >::findMinMax(), AudioBuffer< Type >::getMagnitude(), AudioProcessor::BusesLayout::getNumChannels(), AudioBuffer< Type >::getReadPointer(), AudioBuffer< Type >::getReadPointer(), AudioBuffer< Type >::getRMSLevel(), AudioBuffer< Type >::getSample(), juce::dsp::AudioBlock< SampleType >::getSample(), juce::dsp::LookupTable< FloatType >::getUnchecked(), ArrayBase< ElementType, TypeOfCriticalSectionToUse >::getValueWithDefault(), AudioBuffer< Type >::getWritePointer(), AudioBuffer< Type >::getWritePointer(), EdgeTable::iterate(), ArrayBase< ElementType, TypeOfCriticalSectionToUse >::move(), ArrayBase< ElementType, TypeOfCriticalSectionToUse >::operator[](), ArrayBase< ElementType, TypeOfCriticalSectionToUse >::operator[](), juce::dsp::LookupTableTransform< FloatType >::processSample(), Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::remove(), Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::remove(), ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::remove(), OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::remove(), Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::removeAndReturn(), OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::removeAndReturn(), ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::removeAndReturn(), AudioBuffer< Type >::reverse(), juce::dsp::AudioBlock< SampleType >::setSample(), AudioBuffer< Type >::setSample(), Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::setUnchecked(), ArrayBase< ElementType, TypeOfCriticalSectionToUse >::swap(), ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::swap(), and juce::midi_ci::ChannelAddress::withGroup().

## ◆ isPositiveAndBelow() [2/2]

template<typename Type >

bool isPositiveAndBelow | ( | int | valueToTest,
|  | Type | upperLimit )
| noexcept

References jassert.

## ◆ isPositiveAndNotGreaterThan() [1/2]

template<typename Type1 , typename Type2 >

bool isPositiveAndNotGreaterThan | ( | Type1 | valueToTest,
|  | Type2 | upperLimit )
| noexcept

Returns true if a value is at least zero, and also less than or equal to a specified upper limit.

This is basically a quicker way to write:

valueToTest >= 0 && valueToTest <= upperLimit

References jassert.

Referenced by Thread::RealtimeOptions::withPriority().

## ◆ isPositiveAndNotGreaterThan() [2/2]

template<typename Type >

bool isPositiveAndNotGreaterThan | ( | int | valueToTest,
|  | Type | upperLimit )
| noexcept

References jassert.

## ◆ isWithin()

template<typename Type >

bool isWithin | ( | Type | a,
|  | Type | b,
|  | Type | tolerance )
| noexcept

Computes the absolute difference between two values and returns true if it is less than or equal to a given tolerance, otherwise it returns false.

## ◆ roundToInt() [1/2]

template<typename FloatType >

int roundToInt | ( | const FloatType | value | ) |
| noexcept

Fast floating-point-to-integer conversion.

This is faster than using the normal c++ cast to convert a float to an int, and it will round the value to the nearest integer, rather than rounding it down like the normal cast does.

Note that this routine gets its speed at the expense of some accuracy, and when rounding values whose floating point component is exactly 0.5, odd numbers and even numbers will be rounded up or down differently.

Referenced by AudioParameterInt::get(), AudioParameterChoice::getIndex(), roundToIntAccurate(), Rectangle< ValueType >::toNearestInt(), and Rectangle< ValueType >::toNearestIntEdges().

## ◆ roundToInt() [2/2]

int roundToInt | ( | int | value | ) |
| noexcept

## ◆ roundToIntAccurate()

int roundToIntAccurate | ( | double | value | ) |
| noexcept

Fast floating-point-to-integer conversion.

This is a slightly slower and slightly more accurate version of roundToInt(). It works fine for values above zero, but negative numbers are rounded the wrong way.

References roundToInt().

## ◆ truncatePositiveToUnsignedInt()

template<typename FloatType >

unsigned int truncatePositiveToUnsignedInt | ( | FloatType | value | ) |
| noexcept

Truncates a positive floating-point number to an unsigned int.

This is generally faster than static_cast<unsigned int> (std::floor (x)) but it only works for positive numbers small enough to be represented as an unsigned int.

References jassert.

Referenced by juce::dsp::LookupTable< FloatType >::getUnchecked().

## ◆ isPowerOfTwo()

template<typename IntegerType >

constexpr bool isPowerOfTwo | ( | IntegerType | value | ) |
| constexpr

Returns true if the specified integer is a power-of-two.

Referenced by SingleThreadedAbstractFifo::SingleThreadedAbstractFifo().

## ◆ nextPowerOfTwo()

int nextPowerOfTwo | ( | int | n | ) |
| noexcept

Returns the smallest power-of-two which is equal to or greater than the given integer.

## ◆ findHighestSetBit()

int findHighestSetBit | ( | uint32 | n | ) |
| noexcept

Returns the index of the highest set bit in a (non-zero) number.

So for n=3 this would return 1, for n=7 it returns 2, etc. An input value of 0 is illegal!

## ◆ countNumberOfBits() [1/2]

constexpr int countNumberOfBits | ( | uint32 | n | ) |
| constexpr noexcept

Returns the number of bits in a 32-bit integer.

Referenced by countNumberOfBits().

## ◆ countNumberOfBits() [2/2]

constexpr int countNumberOfBits | ( | uint64 | n | ) |
| constexpr noexcept

Returns the number of bits in a 64-bit integer.

References countNumberOfBits().

## ◆ negativeAwareModulo()

template<typename IntegerType >

IntegerType negativeAwareModulo | ( | IntegerType | dividend,
|  | const IntegerType | divisor )
| noexcept

Performs a modulo operation, but can cope with the dividend being negative.

The divisor must be greater than zero.

References jassert.

## ◆ square()

template<typename NumericType >

constexpr NumericType square | ( | NumericType | n | ) |
| constexpr noexcept

Returns the square of its argument.

## ◆ writeLittleEndianBitsInBuffer()

void writeLittleEndianBitsInBuffer | ( | void * | targetBuffer,
|  | uint32 | startBit,
|  | uint32 | numBits,
|  | uint32 | value )
| noexcept

Writes a number of bits into a memory buffer at a given bit index.

The buffer is treated as a sequence of 8-bit bytes, and the value is encoded in little-endian order, so for example if startBit = 10, and numBits = 11 then the lower 6 bits of the value would be written into bits 2-8 of targetBuffer[1], and the upper 5 bits of value into bits 0-5 of targetBuffer[2].

See also
  readLittleEndianBitsInBuffer

## ◆ readLittleEndianBitsInBuffer()

uint32 readLittleEndianBitsInBuffer | ( | const void * | sourceBuffer,
|  | uint32 | startBit,
|  | uint32 | numBits )
| noexcept

Reads a number of bits from a buffer at a given bit index.

The buffer is treated as a sequence of 8-bit bytes, and the value is encoded in little-endian order, so for example if startBit = 10, and numBits = 11 then the lower 6 bits of the result would be read from bits 2-8 of sourceBuffer[1], and the upper 5 bits of the result from bits 0-5 of sourceBuffer[2].

See also
  writeLittleEndianBitsInBuffer

## ◆ toUnderlyingType()

template<typename T >

constexpr auto toUnderlyingType | ( | T | t | ) | -> std::enable_if_t<std::is_enum_v<T>, std::underlying_type_t<T>>
| constexpr

Converts an enum to its underlying integral type.

Similar to std::to_underlying, which is only available in C++23 and above.

Referenced by juce::midi_ci::operator<().