Classes | Defines | Typedefs | Functions | Variables

juce_MathsFunctions.h File Reference

Classes

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

Defines

#define literal64bit(longLiteral)   (longLiteral##LL)
 A platform-independent macro for writing 64-bit literals, needed because different compilers have different syntaxes for this.
#define JUCE_UNDENORMALISE(x)   x += 1.0f; x -= 1.0f;
 This macro can be applied to a float variable to check whether it contains a denormalised value, and to normalise it if necessary.
#define PARAMETER_TYPE(a)   typename TypeHelpers::ParameterType<a>::type
 A helpful macro to simplify the use of the ParameterType template.

Typedefs

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

Functions

template<typename Type >
Type jmax (const Type a, const Type b)
 Returns the larger of two values.
template<typename Type >
Type jmax (const Type a, const Type b, const Type c)
 Returns the larger of three values.
template<typename Type >
Type jmax (const Type a, const Type b, const Type c, const Type d)
 Returns the larger of four values.
template<typename Type >
Type jmin (const Type a, const Type b)
 Returns the smaller of two values.
template<typename Type >
Type jmin (const Type a, const Type b, const Type c)
 Returns the smaller of three values.
template<typename Type >
Type jmin (const Type a, const Type b, const Type c, const Type d)
 Returns the smaller of four values.
template<typename Type >
const Type findMinimum (const Type *data, int numValues)
 Scans an array of values, returning the minimum value that it contains.
template<typename Type >
const Type findMaximum (const Type *values, int numValues)
 Scans an array of values, returning the minimum 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 (const Type lowerLimit, const Type upperLimit, const Type valueToConstrain) noexcept
 Constrains a value to keep it within a given range.
template<typename Type >
bool isPositiveAndBelow (Type valueToTest, Type upperLimit) noexcept
 Returns true if a value is at least zero, and also below a specified upper limit.
template<>
bool isPositiveAndBelow (const int valueToTest, const int upperLimit) noexcept
template<typename Type >
bool isPositiveAndNotGreaterThan (Type valueToTest, Type upperLimit) noexcept
 Returns true if a value is at least zero, and also less than or equal to a specified upper limit.
template<>
bool isPositiveAndNotGreaterThan (const int valueToTest, const int upperLimit) noexcept
template<typename Type >
void swapVariables (Type &variable1, Type &variable2)
 Handy function to swap two values.
template<typename Type , int N>
int numElementsInArray (Type(&array)[N])
 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.
int64 abs64 (const int64 n) noexcept
 64-bit abs function.
template<typename Type >
Type juce_negate (Type n) noexcept
 This templated negate function will negate pointers as well as integers.
template<typename Type >
Type * juce_negate (Type *n) noexcept
 This templated negate function will negate pointers as well as integers.
template<typename FloatingPointType >
bool juce_isfinite (FloatingPointType value)
 The isfinite() method seems to vary between platforms, so this is a platform-independent function for it.
template<typename FloatType >
int roundToInt (const FloatType value) noexcept
 Fast floating-point-to-integer conversion.
int roundToIntAccurate (const double value) noexcept
 Fast floating-point-to-integer conversion.
int roundDoubleToInt (const double value) noexcept
 Fast floating-point-to-integer conversion.
int roundFloatToInt (const float value) noexcept
 Fast floating-point-to-integer conversion.

Variables

const double double_Pi = 3.1415926535897932384626433832795
 A predefined value for Pi, at double-precision.
const float float_Pi = 3.14159265358979323846f
 A predefined value for Pi, at sngle-precision.

Define Documentation

#define literal64bit (   longLiteral )    (longLiteral##LL)

A platform-independent macro for writing 64-bit literals, needed because different compilers have different syntaxes for this.

E.g. writing literal64bit (0x1000000000) will translate to 0x1000000000LL for GCC, or 0x1000000000 for MSVC.

#define JUCE_UNDENORMALISE (   x )    x += 1.0f; x -= 1.0f;

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.

#define PARAMETER_TYPE (   a )    typename TypeHelpers::ParameterType<a>::type

A helpful macro to simplify the use of the ParameterType template.

See also:
ParameterType

Typedef Documentation

typedef signed char int8

A platform-independent 8-bit signed integer type.

typedef unsigned char uint8

A platform-independent 8-bit unsigned integer type.

typedef signed short int16

A platform-independent 16-bit signed integer type.

typedef unsigned short uint16

A platform-independent 16-bit unsigned integer type.

typedef signed int int32

A platform-independent 32-bit signed integer type.

typedef unsigned int uint32

A platform-independent 32-bit unsigned integer type.

typedef long long int64

A platform-independent 64-bit integer type.

typedef unsigned long long uint64

A platform-independent 64-bit unsigned integer type.

typedef int pointer_sized_int

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

typedef unsigned int pointer_sized_uint

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


Function Documentation

template<typename Type >
Type jmax ( const Type  a,
const Type  b 
)
template<typename Type >
Type jmax ( const Type  a,
const Type  b,
const Type  c 
)

Returns the larger of three values.

template<typename Type >
Type jmax ( const Type  a,
const Type  b,
const Type  c,
const Type  d 
)

Returns the larger of four values.

References jmax().

template<typename Type >
Type jmin ( const Type  a,
const Type  b 
)
template<typename Type >
Type jmin ( const Type  a,
const Type  b,
const Type  c 
)

Returns the smaller of three values.

template<typename Type >
Type jmin ( const Type  a,
const Type  b,
const Type  c,
const Type  d 
)

Returns the smaller of four values.

References jmin().

template<typename Type >
const Type findMinimum ( const Type *  data,
int  numValues 
)

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

template<typename Type >
const Type findMaximum ( const Type *  values,
int  numValues 
)

Scans an array of values, returning the minimum 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 ( const Type  lowerLimit,
const Type  upperLimit,
const Type  valueToConstrain 
)

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:
lowerLimitthe minimum value to return
upperLimitthe maximum value to return
valueToConstrainthe value to try to return
Returns:
the closest value to valueToConstrain which lies between lowerLimit and upperLimit (inclusive)
See also:
jlimit0To, jmin, jmax

References jassert.

Referenced by Range< int >::clipValue(), Range< int >::constrainRange(), Line< ValueType >::findNearestProportionalPositionTo(), Rectangle< int >::getConstrainedPoint(), ReferenceCountedArray< SynthesiserSound >::removeRange(), OwnedArray< MidiBuffer >::removeRange(), Array< MidiKeyboardStateListener * >::removeRange(), and CarbonViewWrapperComponent::setOurSizeToEmbeddedViewSize().

template<typename Type >
bool isPositiveAndBelow ( Type  valueToTest,
Type  upperLimit 
)

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 SparseSet< int >::getRange(), SortedSet< ValueTree * >::getReference(), Array< MidiKeyboardStateListener * >::getReference(), AudioSampleBuffer::getSampleData(), SortedSet< ValueTree * >::getUnchecked(), ReferenceCountedArray< SynthesiserSound >::getUnchecked(), OwnedArray< MidiBuffer >::getUnchecked(), Array< MidiKeyboardStateListener * >::getUnchecked(), Array< MidiKeyboardStateListener * >::insert(), Array< MidiKeyboardStateListener * >::insertArray(), Array< MidiKeyboardStateListener * >::insertMultiple(), EdgeTable::iterate(), ReferenceCountedArray< SynthesiserSound >::move(), OwnedArray< MidiBuffer >::move(), Array< MidiKeyboardStateListener * >::move(), SortedSet< ValueTree * >::operator[](), ReferenceCountedArray< SynthesiserSound >::operator[](), OwnedArray< MidiBuffer >::operator[](), Array< MidiKeyboardStateListener * >::operator[](), SortedSet< ValueTree * >::remove(), ReferenceCountedArray< SynthesiserSound >::remove(), OwnedArray< MidiBuffer >::remove(), Array< MidiKeyboardStateListener * >::remove(), ReferenceCountedArray< SynthesiserSound >::removeAndReturn(), OwnedArray< MidiBuffer >::removeAndReturn(), Array< MidiKeyboardStateListener * >::set(), Array< MidiKeyboardStateListener * >::setUnchecked(), ReferenceCountedArray< SynthesiserSound >::swap(), OwnedArray< MidiBuffer >::swap(), and Array< MidiKeyboardStateListener * >::swap().

template<>
bool isPositiveAndBelow ( const int  valueToTest,
const int  upperLimit 
)

References jassert.

template<typename Type >
bool isPositiveAndNotGreaterThan ( Type  valueToTest,
Type  upperLimit 
)

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.

template<>
bool isPositiveAndNotGreaterThan ( const int  valueToTest,
const int  upperLimit 
)

References jassert.

template<typename Type >
void swapVariables ( Type &  variable1,
Type &  variable2 
)
template<typename Type , int N>
int numElementsInArray ( Type(&)  array[N] )

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
template<typename Type >
Type juce_hypot ( Type  a,
Type  b 
)

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().

int64 abs64 ( const int64  n )

64-bit abs function.

template<typename Type >
Type juce_negate ( Type  n )

This templated negate function will negate pointers as well as integers.

Referenced by Atomic< Type >::operator-=().

template<typename Type >
Type* juce_negate ( Type *  n )

This templated negate function will negate pointers as well as integers.

template<typename FloatingPointType >
bool juce_isfinite ( FloatingPointType  value )

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

template<typename FloatType >
int roundToInt ( const FloatType  value )

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 CarbonViewWrapperComponent::getEmbeddedViewSize(), roundDoubleToInt(), roundFloatToInt(), and roundToIntAccurate().

int roundToIntAccurate ( const double  value )

Fast floating-point-to-integer conversion.

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

References roundToInt().

int roundDoubleToInt ( const double  value )

Fast floating-point-to-integer conversion.

This is faster than using the normal c++ cast to convert a double 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. For a more accurate conversion, see roundDoubleToIntAccurate().

References roundToInt().

int roundFloatToInt ( const float  value )

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 roundToInt().


Variable Documentation

const double double_Pi = 3.1415926535897932384626433832795

A predefined value for Pi, at double-precision.

See also:
float_Pi
const float float_Pi = 3.14159265358979323846f

A predefined value for Pi, at sngle-precision.

See also:
double_Pi
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines