JUCE: maths

JUCE

Macros | Typedefs | Functions | Variables
maths
juce_core

## 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 >
JUCE_CONSTEXPR Type | jmax (Type a, Type b)
| Returns the larger of two values. More...
template<typename Type >
JUCE_CONSTEXPR Type | jmax (Type a, Type b, Type c)
| Returns the larger of three values. More...
template<typename Type >
JUCE_CONSTEXPR Type | jmax (Type a, Type b, Type c, Type d)
| Returns the larger of four values. More...
template<typename Type >
JUCE_CONSTEXPR Type | jmin (Type a, Type b)
| Returns the smaller of two values. More...
template<typename Type >
JUCE_CONSTEXPR Type | jmin (Type a, Type b, Type c)
| Returns the smaller of three values. More...
template<typename Type >
JUCE_CONSTEXPR Type | jmin (Type a, Type b, Type c, Type d)
| Returns the smaller of four values. More...
template<typename Type >
JUCE_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 | findMinimum (const Type *data, int numValues)
| Scans an array of values, returning the minimum value that it contains. More...
template<typename Type >
Type | findMaximum (const Type *values, int 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>
JUCE_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 >
JUCE_CONSTEXPR FloatType | degreesToRadians (FloatType degrees) noexcept
| Converts an angle in degrees to radians. More...
template<typename FloatType >
JUCE_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 >
JUCE_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 >
JUCE_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...

## Variables
static const FloatType | MathConstants< FloatType >::pi = static_cast<FloatType> (3.141592653589793238L)
| A predefined value for Pi. More...
static const FloatType | MathConstants< FloatType >::twoPi = static_cast<FloatType> (2 * 3.141592653589793238L)
| A predefined value for 2 * Pi. More...
static const FloatType | MathConstants< FloatType >::halfPi = static_cast<FloatType> (3.141592653589793238L / 2)
| A predefined value for Pi / 2. More...
static const FloatType | MathConstants< FloatType >::euler = static_cast<FloatType> (2.71828182845904523536L)
| A predefined value for Euler's number. More...
static const FloatType | MathConstants< FloatType >::sqrt2 = static_cast<FloatType> (1.4142135623730950488L)
| A predefined value for sqrt(2) 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 >

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

Returns the larger of two values.

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

## ◆ jmax() [2/3]

template<typename Type >

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

Returns the larger of three values.

## ◆ jmax() [3/3]

template<typename Type >

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

Returns the larger of four values.

References jmax().

## ◆ jmin() [1/3]

template<typename Type >

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

Returns the smaller of two values.

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

## ◆ jmin() [2/3]

template<typename Type >

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

Returns the smaller of three values.

## ◆ jmin() [3/3]

template<typename Type >

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

Returns the smaller of four values.

References jmin().

## ◆ jmap() [1/2]

template<typename Type >

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

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< Type >::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.

## ◆ findMinimum()

template<typename Type >

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

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

## ◆ findMaximum()

template<typename Type >

Type findMaximum | ( | const Type * | values,
|  | int | 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< int64 >::clipValue(), Range< int64 >::constrainRange(), Line< ValueType >::findNearestProportionalPositionTo(), BlocksProtocol::IntegerWithBitSize< 8 >::fromBipolarFloat(), BlocksProtocol::IntegerWithBitSize< 8 >::fromUnipolarFloat(), Rectangle< int >::getConstrainedPoint(), dsp::LookupTableTransform< Type >::processSample(), OwnedArray< DragImageComponent >::removeRange(), ReferenceCountedArray< AudioProcessorGraph::Node >::removeRange(), and Array< OSCBundle::Element >::removeRange().

## ◆ 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< float >::addFrom(), AudioBuffer< float >::addFromWithRamp(), dsp::AudioBlock< const SampleType >::addSample(), AudioBuffer< float >::addSample(), AudioBuffer< float >::applyGain(), AudioBuffer< float >::applyGainRamp(), AudioBuffer< float >::clear(), AudioBuffer< float >::copyFrom(), AudioBuffer< float >::copyFromWithRamp(), AudioBuffer< float >::findMinMax(), AudioBuffer< float >::getMagnitude(), AudioProcessor::BusesLayout::getNumChannels(), AudioBuffer< float >::getReadPointer(), AudioBuffer< float >::getRMSLevel(), dsp::AudioBlock< const SampleType >::getSample(), AudioBuffer< float >::getSample(), dsp::LookupTable< Type >::getUnchecked(), ArrayBase< PushNotifications::Notification::Action, DummyCriticalSection >::getValueWithDefault(), AudioBuffer< float >::getWritePointer(), EdgeTable::iterate(), ArrayBase< PushNotifications::Notification::Action, DummyCriticalSection >::move(), ArrayBase< PushNotifications::Notification::Action, DummyCriticalSection >::operator[](), dsp::LookupTableTransform< Type >::processSample(), OwnedArray< DragImageComponent >::remove(), ReferenceCountedArray< AudioProcessorGraph::Node >::remove(), Array< OSCBundle::Element >::remove(), OwnedArray< DragImageComponent >::removeAndReturn(), ReferenceCountedArray< AudioProcessorGraph::Node >::removeAndReturn(), Array< OSCBundle::Element >::removeAndReturn(), AudioBuffer< float >::reverse(), dsp::AudioBlock< const SampleType >::setSample(), AudioBuffer< float >::setSample(), Array< OSCBundle::Element >::setUnchecked(), ArrayBase< PushNotifications::Notification::Action, DummyCriticalSection >::swap(), and ReferenceCountedArray< AudioProcessorGraph::Node >::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 abs().

## ◆ 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 abs(), max(), and min().

## ◆ ignoreUnused()

template<typename... Types>

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

Handy function for avoiding unused variables warning.

Referenced by AudioProcessorValueTreeState::ParameterLayout::add(), OwnedArray< DragImageComponent >::addSorted(), StandalonePluginHolder::askUserToLoadState(), StandalonePluginHolder::askUserToSaveState(), AudioProcessor::canAddBus(), AudioProcessor::canRemoveBus(), UndoableAction::createCoalescedAction(), PushNotifications::Listener::deliveredNotificationsListReceived(), ContainerDeletePolicy< ObjectType >::destroy(), PushNotifications::Listener::deviceTokenRefreshed(), PushNotifications::Listener::handleNotification(), PushNotifications::Listener::handleNotificationAction(), MidiInputCallback::handlePartialSysexMessage(), VSTCallbackHandler::handleVstHostCallbackAvailable(), VSTCallbackHandler::handleVstPluginCanDo(), OwnedArray< DragImageComponent >::indexOfSorted(), ReferenceCountedArray< AudioProcessorGraph::Node >::indexOfSorted(), Array< OSCBundle::Element >::indexOfSorted(), PushNotifications::Listener::localNotificationDismissedByUser(), MPEInstrument::Listener::noteAdded(), MPEInstrument::Listener::noteKeyStateChanged(), MPEInstrument::Listener::notePitchbendChanged(), MPEInstrument::Listener::notePressureChanged(), MPEInstrument::Listener::noteReleased(), MPEInstrument::Listener::noteTimbreChanged(), PushNotifications::Listener::notificationSettingsReceived(), PushNotifications::Listener::pendingLocalNotificationsListReceived(), dsp::FIR::Filter< SampleType >::prepare(), PositionableAudioSource::setLooping(), OwnedArray< DragImageComponent >::sort(), ReferenceCountedArray< AudioProcessorGraph::Node >::sort(), Array< OSCBundle::Element >::sort(), AudioPlayHead::transportPlay(), AudioPlayHead::transportRecord(), PushNotifications::Listener::upstreamMessageSendingError(), and PushNotifications::Listener::upstreamMessageSent().

## ◆ numElementsInArray()

template<typename Type , size_t N>

JUCE_CONSTEXPR int numElementsInArray | ( | Type(&) | [N] | ) |
| 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

Referenced by AudioBuffer< float >::AudioBuffer(), and AudioBuffer< float >::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< int >::getDistanceFrom(), Point< int >::getDistanceFromOrigin(), and Line< ValueType >::getPointAlongLine().

## ◆ degreesToRadians()

template<typename FloatType >

JUCE_CONSTEXPR FloatType degreesToRadians | ( | FloatType | degrees | ) |
| noexcept

Converts an angle in degrees to radians.

## ◆ radiansToDegrees()

template<typename FloatType >

JUCE_CONSTEXPR FloatType radiansToDegrees | ( | FloatType | radians | ) |
| noexcept

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< int >::isFinite(), and Rectangle< int >::isFinite().

## ◆ juce_isfinite() [2/3]

template<>

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

## ◆ juce_isfinite() [3/3]

template<>

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

## ◆ 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(), Point< int >::roundToInt(), roundToIntAccurate(), Rectangle< int >::toNearestInt(), and Rectangle< int >::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, and max().

Referenced by dsp::LookupTable< Type >::getUnchecked().

## ◆ isPowerOfTwo()

template<typename IntegerType >

JUCE_CONSTEXPR bool isPowerOfTwo | ( | IntegerType | value | ) |

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

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

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

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

Referenced by countNumberOfBits().

## ◆ countNumberOfBits() [2/2]

int countNumberOfBits | ( | uint64 | n | ) |
| 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 >

JUCE_CONSTEXPR NumericType square | ( | NumericType | n | ) |
| 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

Referenced by littlefoot::LittleFootRemoteHeap< ImplementationClass >::setBits().

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

Referenced by littlefoot::Runner< programAndHeapSpace, stackAndGlobalsSpace >::getHeapBits(), and littlefoot::LittleFootRemoteHeap< ImplementationClass >::setBits().

## Variable Documentation

## ◆ pi

template<typename FloatType >

const FloatType MathConstants< FloatType >::pi = static_cast<FloatType> (3.141592653589793238L)
| static

A predefined value for Pi.

## ◆ twoPi

template<typename FloatType >

const FloatType MathConstants< FloatType >::twoPi = static_cast<FloatType> (2 * 3.141592653589793238L)
| static

A predefined value for 2 * Pi.

## ◆ halfPi

template<typename FloatType >

const FloatType MathConstants< FloatType >::halfPi = static_cast<FloatType> (3.141592653589793238L / 2)
| static

A predefined value for Pi / 2.

## ◆ euler

template<typename FloatType >

const FloatType MathConstants< FloatType >::euler = static_cast<FloatType> (2.71828182845904523536L)
| static

A predefined value for Euler's number.

## ◆ sqrt2

template<typename FloatType >

const FloatType MathConstants< FloatType >::sqrt2 = static_cast<FloatType> (1.4142135623730950488L)
| static

A predefined value for sqrt(2)

numElementsInArray
JUCE_CONSTEXPR int numElementsInArray(Type(&)[N]) noexcept
Handy function for getting the number of elements in a simple const C array.
Definition: juce_MathsFunctions.h:301