JUCE: maths

JUCE

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...
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...
struct | TypeHelpers::SmallestFloatType< Type >
| These templates are designed to take a type, and if it's a double, they return a double type; for anything else, they return a float type. 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. More...

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

## Functions
OutputStream &JUCE_CALLTYPE | operator<< (OutputStream &stream, const BigInteger &value)
| Writes a BigInteger to an OutputStream as a UTF8 decimal string. More...
template<typename Type >
constexpr Type | jmax (Type a, Type b)
| Returns the larger of two values. More...
template<typename Type >
constexpr Type | jmax (Type a, Type b, Type c)
| Returns the larger of three values. More...
template<typename Type >
constexpr Type | jmax (Type a, Type b, Type c, Type d)
| Returns the larger of four values. More...
template<typename Type >
constexpr Type | jmin (Type a, Type b)
| Returns the smaller of two values. More...
template<typename Type >
constexpr Type | jmin (Type a, Type b, Type c)
| Returns the smaller of three values. More...
template<typename Type >
constexpr Type | jmin (Type a, Type b, Type c, Type d)
| Returns the smaller of four values. More...
template<typename Type >
constexpr Type | jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)
| Remaps a normalised value (between 0 and 1) to a target range. More...
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. More...
template<typename Type >
Type | mapToLog10 (Type value0To1, Type logRangeMin, Type logRangeMax)
| Remaps a normalised value (between 0 and 1) to a logarithmic target range. More...
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). More...
template<typename Type , typename Size >
Type | findMinimum (const Type *data, Size numValues)
| Scans an array of values, returning the minimum value that it contains. More...
template<typename Type , typename Size >
Type | findMaximum (const Type *values, Size numValues)
| Scans an array of values, returning the maximum value that it contains. More...
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. More...
template<typename Type >
Type | jlimit (Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
| Constrains a value to keep it within a given range. More...
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. More...
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. More...
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. More...
template<typename Type >
bool | approximatelyEqual (Type a, Type b) noexcept
| Returns true if the two numbers are approximately equal. More...
template<typename... Types>
void | ignoreUnused (Types &&...) noexcept
| Handy function for avoiding unused variables warning. More...
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. More...
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. More...
template<typename FloatType >
constexpr FloatType | degreesToRadians (FloatType degrees) noexcept
| Converts an angle in degrees to radians. More...
template<typename FloatType >
constexpr FloatType | radiansToDegrees (FloatType radians) noexcept
| Converts an angle in radians to degrees. More...
template<typename NumericType >
bool | juce_isfinite (NumericType) noexcept
| The isfinite() method seems to vary between platforms, so this is a platform-independent function for it. More...
template<>
bool | juce_isfinite (float value) noexcept
template<>
bool | juce_isfinite (double value) noexcept
template<typename FloatType >
int | roundToInt (const FloatType value) noexcept
| Fast floating-point-to-integer conversion. More...
int | roundToInt (int value) noexcept
int | roundToIntAccurate (double value) noexcept
| Fast floating-point-to-integer conversion. More...
template<typename FloatType >
unsigned int | truncatePositiveToUnsignedInt (FloatType value) noexcept
| Truncates a positive floating-point number to an unsigned int. More...
template<typename IntegerType >
constexpr bool | isPowerOfTwo (IntegerType value)
| Returns true if the specified integer is a power-of-two. More...
int | nextPowerOfTwo (int n) noexcept
| Returns the smallest power-of-two which is equal to or greater than the given integer. More...
int | findHighestSetBit (uint32 n) noexcept
| Returns the index of the highest set bit in a (non-zero) number. More...
int | countNumberOfBits (uint32 n) noexcept
| Returns the number of bits in a 32-bit integer. More...
int | countNumberOfBits (uint64 n) noexcept
| Returns the number of bits in a 64-bit integer. More...
template<typename IntegerType >
IntegerType | negativeAwareModulo (IntegerType dividend, const IntegerType divisor) noexcept
| Performs a modulo operation, but can cope with the dividend being negative. More...
template<typename NumericType >
constexpr NumericType | square (NumericType n) noexcept
| Returns the square of its argument. More...
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. More...
uint32 | readLittleEndianBitsInBuffer (const void *sourceBuffer, uint32 startBit, uint32 numBits) noexcept
| Reads a number of bits from a buffer at a given bit index. More...

## 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.

## ◆ jmax() [1/3]

template<typename Type >

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

Returns the larger of two values.

References gl::a, and gl::b.

Referenced by Rectangle< ValueType >::enlargeIfAdjacent(), Rectangle< ValueType >::expand(), Rectangle< ValueType >::expanded(), Rectangle< ValueType >::findAreaContainingPoints(), Decibels::gainToDecibels(), RectangleList< ValueType >::getBounds(), Rectangle< ValueType >::getIntersection(), Range< ValueType >::getIntersectionWith(), AudioBuffer< Type >::getMagnitude(), dsp::Polynomial< FloatingType >::getProductWith(), Rectangle< ValueType >::getUnion(), Range< ValueType >::getUnionWith(), Rectangle< ValueType >::intersectRectangle(), Rectangle< ValueType >::intersectRectangles(), jmax(), dsp::Chorus< SampleType >::process(), 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.

References gl::a, gl::b, and gl::c.

## ◆ 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 gl::a, gl::b, gl::c, and jmax().

## ◆ jmin() [1/3]

template<typename Type >

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

Returns the smaller of two values.

References gl::a, and gl::b.

Referenced by Rectangle< ValueType >::constrainedWithin(), 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(), Rectangle< ValueType >::intersectRectangle(), Rectangle< ValueType >::intersectRectangles(), jmin(), dsp::ProcessorDuplicator< MonoProcessorType, StateType >::process(), dsp::Oscillator< SampleType >::process(), 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.

References gl::a, gl::b, and gl::c.

## ◆ 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 gl::a, gl::b, gl::c, and 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 dsp::LogRampedValue< FloatType >::getNextValue(), dsp::LookupTable< FloatType >::getUnchecked(), and 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 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:145

References jassert.

Referenced by 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:167

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.

References gl::data, gl::result, and gl::v.

## ◆ 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 dsp::AudioBlock< SampleType >::findMinAndMax(), AudioData::Pointer< SampleFormat, Endianness, InterleavingType, Constness >::findMinAndMax(), and AudioBuffer< Type >::findMinMax().

## ◆ 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(), dsp::Phaser< SampleType >::process(), 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 >::addFromWithRamp(), dsp::AudioBlock< SampleType >::addSample(), AudioBuffer< Type >::addSample(), AudioBuffer< Type >::applyGain(), AudioBuffer< Type >::applyGainRamp(), AudioBuffer< Type >::clear(), AudioBuffer< Type >::copyFrom(), AudioBuffer< Type >::copyFromWithRamp(), AudioBuffer< Type >::findMinMax(), AudioBuffer< Type >::getMagnitude(), AudioProcessor::BusesLayout::getNumChannels(), AudioBuffer< Type >::getReadPointer(), AudioBuffer< Type >::getRMSLevel(), AudioBuffer< Type >::getSample(), dsp::AudioBlock< SampleType >::getSample(), dsp::LookupTable< FloatType >::getUnchecked(), ArrayBase< ElementType, TypeOfCriticalSectionToUse >::getValueWithDefault(), AudioBuffer< Type >::getWritePointer(), EdgeTable::iterate(), ArrayBase< ElementType, TypeOfCriticalSectionToUse >::move(), ArrayBase< ElementType, TypeOfCriticalSectionToUse >::operator[](), dsp::LookupTableTransform< FloatType >::processSample(), 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(), dsp::AudioBlock< SampleType >::setSample(), AudioBuffer< Type >::setSample(), Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::setUnchecked(), ArrayBase< ElementType, TypeOfCriticalSectionToUse >::swap(), and ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::swap().

## ◆ 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.

## ◆ 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.

References gl::a, and gl::b.

## ◆ approximatelyEqual()

template<typename Type >

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

Returns true if the two numbers are approximately equal.

This is useful for floating-point and double comparisons.

References gl::a, and gl::b.

## ◆ ignoreUnused()

template<typename... Types>

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

Handy function for avoiding unused variables warning.

Referenced by AudioProcessorValueTreeState::ParameterLayout::add(), OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::addSorted(), AudioIODeviceCallback::audioDeviceIOCallback(), AudioIODeviceCallback::audioDeviceIOCallbackWithContext(), AudioProcessor::canAddBus(), AudioProcessor::canRemoveBus(), UndoableAction::createCoalescedAction(), PushNotifications::Listener::deliveredNotificationsListReceived(), ContainerDeletePolicy< ObjectType >::destroy(), PushNotifications::Listener::deviceTokenRefreshed(), ARAAudioSourceListener::didAddAudioModificationToAudioSource(), ARADocumentListener::didAddAudioSourceToDocument(), ARADocumentListener::didAddMusicalContextToDocument(), ARAAudioModificationListener::didAddPlaybackRegionToAudioModification(), ARARegionSequenceListener::didAddPlaybackRegionToRegionSequence(), ARADocumentListener::didAddRegionSequenceToDocument(), ARAMusicalContextListener::didAddRegionSequenceToMusicalContext(), ARAAudioModificationListener::didDeactivateAudioModificationForUndoHistory(), ARAAudioSourceListener::didDeactivateAudioSourceForUndoHistory(), ARAAudioSourceListener::didEnableAudioSourceSamplesAccess(), ARADocumentListener::didEndEditing(), ARADocumentListener::didNotifyModelUpdates(), ARADocumentListener::didReorderMusicalContextsInDocument(), ARADocumentListener::didReorderRegionSequencesInDocument(), ARAMusicalContextListener::didReorderRegionSequencesInMusicalContext(), ARAAudioModificationListener::didUpdateAudioModificationContent(), ARAAudioModificationListener::didUpdateAudioModificationProperties(), ARAAudioSourceListener::didUpdateAudioSourceAnalysisProgress(), ARAAudioSourceListener::didUpdateAudioSourceProperties(), ARADocumentListener::didUpdateDocumentProperties(), ARAMusicalContextListener::didUpdateMusicalContextProperties(), ARAPlaybackRegionListener::didUpdatePlaybackRegionContent(), ARAPlaybackRegionListener::didUpdatePlaybackRegionProperties(), ARARegionSequenceListener::didUpdateRegionSequenceProperties(), ARAAudioSourceListener::doUpdateAudioSourceContent(), ARAMusicalContextListener::doUpdateMusicalContextContent(), StandalonePluginHolder::getIAAHostIcon(), PushNotifications::Listener::handleNotification(), PushNotifications::Listener::handleNotificationAction(), MidiInputCallback::handlePartialSysexMessage(), VSTCallbackHandler::handleVstHostCallbackAvailable(), VSTCallbackHandler::handleVstPluginCanDo(), OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::indexOfSorted(), ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::indexOfSorted(), Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::indexOfSorted(), PushNotifications::Listener::localNotificationDismissedByUser(), MidiKeyboardComponent::mouseDownOnKey(), MidiKeyboardComponent::mouseDraggedToKey(), MidiKeyboardComponent::mouseUpOnKey(), WebBrowserComponent::newWindowAttemptingToLoad(), MPEInstrument::Listener::noteAdded(), MPEInstrument::Listener::noteKeyStateChanged(), MPEInstrument::Listener::notePitchbendChanged(), MPEInstrument::Listener::notePressureChanged(), MPEInstrument::Listener::noteReleased(), MPEInstrument::Listener::noteTimbreChanged(), PushNotifications::Listener::notificationSettingsReceived(), ARAEditorView::Listener::onHideRegionSequences(), ARAEditorView::Listener::onNewSelection(), WebBrowserComponent::pageAboutToLoad(), WebBrowserComponent::pageFinishedLoading(), WebBrowserComponent::pageLoadHadNetworkError(), PushNotifications::Listener::pendingLocalNotificationsListReceived(), WebInputStream::Listener::postDataSendProgress(), ARARenderer::prepareToPlay(), ARAEditorRenderer::processBlock(), ARAPlaybackRenderer::processBlock(), PositionableAudioSource::setLooping(), Array< ElementType, TypeOfCriticalSectionToUse, minimumAllocatedSize >::sort(), OwnedArray< ObjectClass, TypeOfCriticalSectionToUse >::sort(), ReferenceCountedArray< ObjectClass, TypeOfCriticalSectionToUse >::sort(), AudioPlayHead::transportPlay(), AudioPlayHead::transportRecord(), PushNotifications::Listener::upstreamMessageSendingError(), PushNotifications::Listener::upstreamMessageSent(), ARADocumentListener::willBeginEditing(), ARAAudioModificationListener::willDeactivateAudioModificationForUndoHistory(), ARAAudioSourceListener::willDeactivateAudioSourceForUndoHistory(), ARAAudioModificationListener::willDestroyAudioModification(), ARAAudioSourceListener::willDestroyAudioSource(), ARADocumentListener::willDestroyDocument(), ARAMusicalContextListener::willDestroyMusicalContext(), ARAPlaybackRegionListener::willDestroyPlaybackRegion(), ARARegionSequenceListener::willDestroyRegionSequence(), ARAAudioSourceListener::willEnableAudioSourceSamplesAccess(), ARADocumentListener::willNotifyModelUpdates(), ARAAudioSourceListener::willRemoveAudioModificationFromAudioSource(), ARADocumentListener::willRemoveAudioSourceFromDocument(), ARADocumentListener::willRemoveMusicalContextFromDocument(), ARAAudioModificationListener::willRemovePlaybackRegionFromAudioModification(), ARARegionSequenceListener::willRemovePlaybackRegionFromRegionSequence(), ARADocumentListener::willRemoveRegionSequenceFromDocument(), ARAMusicalContextListener::willRemoveRegionSequenceFromMusicalContext(), ARAAudioModificationListener::willUpdateAudioModificationProperties(), ARAAudioSourceListener::willUpdateAudioSourceProperties(), ARADocumentListener::willUpdateDocumentProperties(), ARAMusicalContextListener::willUpdateMusicalContextProperties(), ARAPlaybackRegionListener::willUpdatePlaybackRegionProperties(), and ARARegionSequenceListener::willUpdateRegionSequenceProperties().

## ◆ numElementsInArray()

template<typename Type , size_t N>

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

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:345

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.

References gl::a, and gl::b.

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

## ◆ degreesToRadians()

template<typename FloatType >

constexpr FloatType degreesToRadians | ( | FloatType | degrees | ) |
| constexprnoexcept

Converts an angle in degrees to radians.

## ◆ radiansToDegrees()

template<typename FloatType >

constexpr FloatType radiansToDegrees | ( | FloatType | radians | ) |
| constexprnoexcept

Converts an angle in radians to degrees.

## ◆ juce_isfinite() [1/3]

template<typename NumericType >

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

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

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

## ◆ juce_isfinite() [2/3]

template<>

bool juce_isfinite | ( | float | value | ) |
| noexcept

References gl::value.

## ◆ juce_isfinite() [3/3]

template<>

bool juce_isfinite | ( | double | value | ) |
| noexcept

References gl::value.

## ◆ 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.

References gl::n, and gl::value.

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

## ◆ roundToInt() [2/2]

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

References gl::value.

## ◆ 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(), and gl::value.

## ◆ 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, and gl::value.

Referenced by 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.

References gl::value.

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.

References gl::n.

## ◆ 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]

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

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

References gl::n.

Referenced by countNumberOfBits().

## ◆ countNumberOfBits() [2/2]

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

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

References countNumberOfBits(), and gl::n.

## ◆ 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 gl::divisor, and jassert.

## ◆ square()

template<typename NumericType >

constexpr NumericType square | ( | NumericType | n | ) |
| constexprnoexcept

Returns the square of its argument.

References gl::n.

## ◆ 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