39using int8 =
signed char;
41using uint8 =
unsigned char;
43using int16 =
signed short;
45using uint16 =
unsigned short;
47using int32 =
signed int;
49using uint32 =
unsigned int;
53 using int64 = __int64;
55 using uint64 =
unsigned __int64;
58 using int64 =
long long;
60 using uint64 =
unsigned long long;
69 #define literal64bit(longLiteral) (longLiteral##LL)
74 using pointer_sized_int = int64;
76 using pointer_sized_uint = uint64;
79 using pointer_sized_int = _W64 int;
81 using pointer_sized_uint = _W64
unsigned int;
84 using pointer_sized_int = int;
86 using pointer_sized_uint =
unsigned int;
89#if JUCE_WINDOWS && ! JUCE_MINGW
90 using ssize_t = pointer_sized_int;
97template <
typename Type>
98JUCE_CONSTEXPR Type jmax (Type a, Type b) {
return a < b ? b : a; }
101template <
typename Type>
102JUCE_CONSTEXPR Type jmax (Type a, Type b, Type c) {
return a < b ? (b < c ? c : b) : (a < c ? c : a); }
105template <
typename Type>
106JUCE_CONSTEXPR Type jmax (Type a, Type b, Type c, Type d) {
return jmax (a, jmax (b, c, d)); }
109template <
typename Type>
110JUCE_CONSTEXPR Type jmin (Type a, Type b) {
return b < a ? b : a; }
113template <
typename Type>
114JUCE_CONSTEXPR Type jmin (Type a, Type b, Type c) {
return b < a ? (c < b ? c : b) : (c < a ? c : a); }
117template <
typename Type>
118JUCE_CONSTEXPR Type jmin (Type a, Type b, Type c, Type d) {
return jmin (a, jmin (b, c, d)); }
123template <
typename Type>
124JUCE_CONSTEXPR Type jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)
126 return targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin);
130template <
typename Type>
131Type jmap (Type sourceValue, Type sourceRangeMin, Type sourceRangeMax, Type targetRangeMin, Type targetRangeMax)
133 jassert (sourceRangeMax != sourceRangeMin);
134 return targetRangeMin + ((targetRangeMax - targetRangeMin) * (sourceValue - sourceRangeMin)) / (sourceRangeMax - sourceRangeMin);
138template <
typename Type>
139Type findMinimum (
const Type* data,
int numValues)
144 auto result = *data++;
146 while (--numValues > 0)
158template <
typename Type>
159Type findMaximum (
const Type* values,
int numValues)
164 auto result = *values++;
166 while (--numValues > 0)
178template <
typename Type>
179void findMinAndMax (
const Type* values,
int numValues, Type& lowest, Type& highest)
191 while (--numValues > 0)
221template <
typename Type>
222Type jlimit (Type lowerLimit,
224 Type valueToConstrain)
noexcept
226 jassert (lowerLimit <= upperLimit);
228 return valueToConstrain < lowerLimit ? lowerLimit
229 : (upperLimit < valueToConstrain ? upperLimit
238template <
typename Type1,
typename Type2>
239bool isPositiveAndBelow (Type1 valueToTest, Type2 upperLimit)
noexcept
241 jassert (Type1() <=
static_cast<Type1
> (upperLimit));
242 return Type1() <= valueToTest && valueToTest < static_cast<Type1> (upperLimit);
245template <
typename Type>
246bool isPositiveAndBelow (
int valueToTest, Type upperLimit)
noexcept
248 jassert (upperLimit >= 0);
249 return static_cast<unsigned int> (valueToTest) <
static_cast<unsigned int> (upperLimit);
257template <
typename Type1,
typename Type2>
258bool isPositiveAndNotGreaterThan (Type1 valueToTest, Type2 upperLimit)
noexcept
260 jassert (Type1() <=
static_cast<Type1
> (upperLimit));
261 return Type1() <= valueToTest && valueToTest <= static_cast<Type1> (upperLimit);
264template <
typename Type>
265bool isPositiveAndNotGreaterThan (
int valueToTest, Type upperLimit)
noexcept
267 jassert (upperLimit >= 0);
268 return static_cast<unsigned int> (valueToTest) <=
static_cast<unsigned int> (upperLimit);
274template <
typename Type>
275bool isWithin (Type a, Type b, Type tolerance)
noexcept
277 return std::abs (a - b) <= tolerance;
283template <
typename Type>
284bool approximatelyEqual (Type a, Type b)
noexcept
286 return std::abs (a - b) <= (std::numeric_limits<Type>::epsilon() * std::max (a, b))
287 || std::abs (a - b) < std::numeric_limits<Type>::min();
292template <
typename... Types>
293void ignoreUnused (Types&&...) noexcept {}
303template <
typename Type,
size_t N>
304JUCE_CONSTEXPR
int numElementsInArray (Type (&)[N])
noexcept {
return N; }
311template <
typename Type>
312Type juce_hypot (Type a, Type b)
noexcept
315 return static_cast<Type
> (_hypot (a, b));
317 return static_cast<Type
> (hypot (a, b));
323inline float juce_hypot (
float a,
float b)
noexcept
326 return _hypotf (a, b);
328 return hypotf (a, b);
334#if JUCE_HAS_CONSTEXPR
340template <
typename FloatType>
344 static constexpr FloatType
pi =
static_cast<FloatType
> (3.141592653589793238L);
347 static constexpr FloatType
twoPi =
static_cast<FloatType
> (2 * 3.141592653589793238L);
350 static constexpr FloatType
halfPi =
static_cast<FloatType
> (3.141592653589793238L / 2);
353 static constexpr FloatType
euler =
static_cast<FloatType
> (2.71828182845904523536L);
356 static constexpr FloatType
sqrt2 =
static_cast<FloatType
> (1.4142135623730950488L);
365template <
typename FloatType>
369 static const FloatType
pi;
384template <
typename FloatType>
387template <
typename FloatType>
390template <
typename FloatType>
393template <
typename FloatType>
396template <
typename FloatType>
418template <
typename FloatType>
419JUCE_CONSTEXPR FloatType degreesToRadians (FloatType degrees)
noexcept {
return degrees * (
MathConstants<FloatType>::pi / FloatType (180)); }
422template <
typename FloatType>
423JUCE_CONSTEXPR FloatType radiansToDegrees (FloatType radians)
noexcept {
return radians * (FloatType (180) /
MathConstants<FloatType>::pi); }
430template <
typename NumericType>
431bool juce_isfinite (NumericType)
noexcept
437inline bool juce_isfinite (
float value)
noexcept
439 #if JUCE_WINDOWS && ! JUCE_MINGW
440 return _finite (value) != 0;
442 return std::isfinite (value);
447inline bool juce_isfinite (
double value)
noexcept
449 #if JUCE_WINDOWS && ! JUCE_MINGW
450 return _finite (value) != 0;
452 return std::isfinite (value);
458 #pragma optimize ("t", off)
459 #ifndef __INTEL_COMPILER
460 #pragma float_control (precise, on, push)
474template <
typename FloatType>
475int roundToInt (
const FloatType value)
noexcept
477 #ifdef __INTEL_COMPILER
478 #pragma float_control (precise, on, push)
481 union {
int asInt[2];
double asDouble; } n;
482 n.asDouble = ((double) value) + 6755399441055744.0;
491inline int roundToInt (
int value)
noexcept
497 #ifndef __INTEL_COMPILER
498 #pragma float_control (pop)
500 #pragma optimize ("", on)
508inline int roundToIntAccurate (
double value)
noexcept
510 #ifdef __INTEL_COMPILER
511 #pragma float_control (pop)
514 return roundToInt (value + 1.5e-8);
524template <
typename FloatType>
525unsigned int truncatePositiveToUnsignedInt (FloatType value)
noexcept
527 jassert (value >=
static_cast<FloatType
> (0));
528 jassert (
static_cast<FloatType
> (value) <= std::numeric_limits<unsigned int>::max());
530 return static_cast<unsigned int> (value);
535template <
typename IntegerType>
536JUCE_CONSTEXPR
bool isPowerOfTwo (IntegerType value)
538 return (value & (value - 1)) == 0;
542inline int nextPowerOfTwo (
int n)
noexcept
557int findHighestSetBit (uint32 n)
noexcept;
560inline int countNumberOfBits (uint32 n)
noexcept
562 n -= ((n >> 1) & 0x55555555);
563 n = (((n >> 2) & 0x33333333) + (n & 0x33333333));
564 n = (((n >> 4) + n) & 0x0f0f0f0f);
567 return (
int) (n & 0x3f);
571inline int countNumberOfBits (uint64 n)
noexcept
573 return countNumberOfBits ((uint32) n) + countNumberOfBits ((uint32) (n >> 32));
579template <
typename IntegerType>
580IntegerType negativeAwareModulo (IntegerType dividend,
const IntegerType divisor)
noexcept
582 jassert (divisor > 0);
584 return (dividend < 0) ? (dividend + divisor) : dividend;
588template <
typename NumericType>
589inline JUCE_CONSTEXPR NumericType square (NumericType n)
noexcept
602void writeLittleEndianBitsInBuffer (
void* targetBuffer, uint32 startBit, uint32 numBits, uint32 value)
noexcept;
611uint32 readLittleEndianBitsInBuffer (
const void* sourceBuffer, uint32 startBit, uint32 numBits)
noexcept;
615#if JUCE_INTEL || defined (DOXYGEN)
620 #define JUCE_UNDENORMALISE(x) { (x) += 0.1f; (x) -= 0.1f; }
622 #define JUCE_UNDENORMALISE(x)
641 template <
typename Type>
struct ParameterType {
using type =
const Type&; };
644 template <
typename Type>
struct ParameterType <Type&> {
using type = Type&; };
645 template <
typename Type>
struct ParameterType <Type*> {
using type = Type*; };
646 template <>
struct ParameterType <char> {
using type = char; };
647 template <>
struct ParameterType <unsigned char> {
using type =
unsigned char; };
648 template <>
struct ParameterType <short> {
using type = short; };
649 template <>
struct ParameterType <unsigned short> {
using type =
unsigned short; };
650 template <>
struct ParameterType <int> {
using type = int; };
651 template <>
struct ParameterType <unsigned int> {
using type =
unsigned int; };
652 template <>
struct ParameterType <long> {
using type = long; };
653 template <>
struct ParameterType <unsigned long> {
using type =
unsigned long; };
654 template <>
struct ParameterType <int64> {
using type = int64; };
655 template <>
struct ParameterType <uint64> {
using type = uint64; };
656 template <>
struct ParameterType <bool> {
using type = bool; };
657 template <>
struct ParameterType <float> {
using type = float; };
658 template <>
struct ParameterType <double> {
using type = double; };
681 template <>
struct UnsignedTypeWithSize<2> {
using type = uint16; };
682 template <>
struct UnsignedTypeWithSize<4> {
using type = uint32; };
683 template <>
struct UnsignedTypeWithSize<8> {
using type = uint64; };
690 JUCE_DEPRECATED_ATTRIBUTE
inline int roundDoubleToInt (
double value)
noexcept {
return roundToInt (value); }
691 JUCE_DEPRECATED_ATTRIBUTE
inline int roundFloatToInt (
float value)
noexcept {
return roundToInt (value); }
694 JUCE_DEPRECATED_ATTRIBUTE
inline int64 abs64 (int64 n)
noexcept {
return std::abs (n); }
The ParameterType struct is used to find the best type to use when passing some kind of object as a p...
These templates are designed to take a type, and if it's a double, they return a double type; for any...
These templates are designed to take an integer type, and return an unsigned int version with the sam...
Commonly used mathematical constants.
static const FloatType euler
A predefined value for Euler's number.
static const FloatType twoPi
A predefined value for 2 * Pi.
static const FloatType sqrt2
A predefined value for sqrt(2)
static const FloatType halfPi
A predefined value for Pi / 2.
static const FloatType pi
A predefined value for Pi.