35using int8 =
signed char;
37using uint8 =
unsigned char;
39using int16 =
signed short;
41using uint16 =
unsigned short;
43using int32 =
signed int;
45using uint32 =
unsigned int;
49 using int64 = __int64;
51 using uint64 =
unsigned __int64;
54 using int64 =
long long;
56 using uint64 =
unsigned long long;
65 #define literal64bit(longLiteral) (longLiteral##LL)
70 using pointer_sized_int = int64;
72 using pointer_sized_uint = uint64;
75 using pointer_sized_int = _W64 int;
77 using pointer_sized_uint = _W64
unsigned int;
81 using pointer_sized_int = intptr_t;
83 using pointer_sized_uint = uintptr_t;
86#if JUCE_WINDOWS && ! JUCE_MINGW
87 using ssize_t = pointer_sized_int;
94template <
typename Type>
95JUCE_CONSTEXPR Type jmax (Type a, Type b) {
return a < b ? b : a; }
98template <
typename Type>
99JUCE_CONSTEXPR Type jmax (Type a, Type b, Type c) {
return a < b ? (b < c ? c : b) : (a < c ? c : a); }
102template <
typename Type>
103JUCE_CONSTEXPR Type jmax (Type a, Type b, Type c, Type d) {
return jmax (a, jmax (b, c, d)); }
106template <
typename Type>
107JUCE_CONSTEXPR Type jmin (Type a, Type b) {
return b < a ? b : a; }
110template <
typename Type>
111JUCE_CONSTEXPR Type jmin (Type a, Type b, Type c) {
return b < a ? (c < b ? c : b) : (c < a ? c : a); }
114template <
typename Type>
115JUCE_CONSTEXPR Type jmin (Type a, Type b, Type c, Type d) {
return jmin (a, jmin (b, c, d)); }
120template <
typename Type>
121JUCE_CONSTEXPR Type jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)
123 return targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin);
127template <
typename Type>
128Type jmap (Type sourceValue, Type sourceRangeMin, Type sourceRangeMax, Type targetRangeMin, Type targetRangeMax)
130 jassert (sourceRangeMax != sourceRangeMin);
131 return targetRangeMin + ((targetRangeMax - targetRangeMin) * (sourceValue - sourceRangeMin)) / (sourceRangeMax - sourceRangeMin);
135template <
typename Type>
136Type findMinimum (
const Type* data,
int numValues)
141 auto result = *data++;
143 while (--numValues > 0)
155template <
typename Type>
156Type findMaximum (
const Type* values,
int numValues)
161 auto result = *values++;
163 while (--numValues > 0)
175template <
typename Type>
176void findMinAndMax (
const Type* values,
int numValues, Type& lowest, Type& highest)
188 while (--numValues > 0)
218template <
typename Type>
219Type jlimit (Type lowerLimit,
221 Type valueToConstrain)
noexcept
223 jassert (lowerLimit <= upperLimit);
225 return valueToConstrain < lowerLimit ? lowerLimit
226 : (upperLimit < valueToConstrain ? upperLimit
235template <
typename Type1,
typename Type2>
236bool isPositiveAndBelow (Type1 valueToTest, Type2 upperLimit)
noexcept
238 jassert (Type1() <=
static_cast<Type1
> (upperLimit));
239 return Type1() <= valueToTest && valueToTest < static_cast<Type1> (upperLimit);
242template <
typename Type>
243bool isPositiveAndBelow (
int valueToTest, Type upperLimit)
noexcept
245 jassert (upperLimit >= 0);
246 return static_cast<unsigned int> (valueToTest) <
static_cast<unsigned int> (upperLimit);
254template <
typename Type1,
typename Type2>
255bool isPositiveAndNotGreaterThan (Type1 valueToTest, Type2 upperLimit)
noexcept
257 jassert (Type1() <=
static_cast<Type1
> (upperLimit));
258 return Type1() <= valueToTest && valueToTest <= static_cast<Type1> (upperLimit);
261template <
typename Type>
262bool isPositiveAndNotGreaterThan (
int valueToTest, Type upperLimit)
noexcept
264 jassert (upperLimit >= 0);
265 return static_cast<unsigned int> (valueToTest) <=
static_cast<unsigned int> (upperLimit);
271template <
typename Type>
272bool isWithin (Type a, Type b, Type tolerance)
noexcept
274 return std::abs (a - b) <= tolerance;
280template <
typename Type>
281bool approximatelyEqual (Type a, Type b)
noexcept
283 return std::abs (a - b) <= (std::numeric_limits<Type>::epsilon() * std::max (a, b))
284 || std::abs (a - b) < std::numeric_limits<Type>::min();
289template <
typename... Types>
290void ignoreUnused (Types&&...) noexcept {}
300template <
typename Type,
size_t N>
301JUCE_CONSTEXPR
int numElementsInArray (Type (&)[N])
noexcept {
return N; }
308template <
typename Type>
309Type juce_hypot (Type a, Type b)
noexcept
312 return static_cast<Type
> (_hypot (a, b));
314 return static_cast<Type
> (hypot (a, b));
320inline float juce_hypot (
float a,
float b)
noexcept
323 return _hypotf (a, b);
325 return hypotf (a, b);
331#if JUCE_HAS_CONSTEXPR
337template <
typename FloatType>
341 static constexpr FloatType
pi =
static_cast<FloatType
> (3.141592653589793238L);
344 static constexpr FloatType
twoPi =
static_cast<FloatType
> (2 * 3.141592653589793238L);
347 static constexpr FloatType
halfPi =
static_cast<FloatType
> (3.141592653589793238L / 2);
350 static constexpr FloatType
euler =
static_cast<FloatType
> (2.71828182845904523536L);
353 static constexpr FloatType
sqrt2 =
static_cast<FloatType
> (1.4142135623730950488L);
362template <
typename FloatType>
366 static const FloatType
pi;
381template <
typename FloatType>
384template <
typename FloatType>
387template <
typename FloatType>
390template <
typename FloatType>
393template <
typename FloatType>
415template <
typename FloatType>
416JUCE_CONSTEXPR FloatType degreesToRadians (FloatType degrees)
noexcept {
return degrees * (
MathConstants<FloatType>::pi / FloatType (180)); }
419template <
typename FloatType>
420JUCE_CONSTEXPR FloatType radiansToDegrees (FloatType radians)
noexcept {
return radians * (FloatType (180) /
MathConstants<FloatType>::pi); }
427template <
typename NumericType>
428bool juce_isfinite (NumericType)
noexcept
434inline bool juce_isfinite (
float value)
noexcept
436 #if JUCE_WINDOWS && ! JUCE_MINGW
437 return _finite (value) != 0;
439 return std::isfinite (value);
444inline bool juce_isfinite (
double value)
noexcept
446 #if JUCE_WINDOWS && ! JUCE_MINGW
447 return _finite (value) != 0;
449 return std::isfinite (value);
455 #pragma optimize ("t", off)
456 #ifndef __INTEL_COMPILER
457 #pragma float_control (precise, on, push)
471template <
typename FloatType>
472int roundToInt (
const FloatType value)
noexcept
474 #ifdef __INTEL_COMPILER
475 #pragma float_control (precise, on, push)
478 union {
int asInt[2];
double asDouble; } n;
479 n.asDouble = ((double) value) + 6755399441055744.0;
488inline int roundToInt (
int value)
noexcept
494 #ifndef __INTEL_COMPILER
495 #pragma float_control (pop)
497 #pragma optimize ("", on)
505inline int roundToIntAccurate (
double value)
noexcept
507 #ifdef __INTEL_COMPILER
508 #pragma float_control (pop)
511 return roundToInt (value + 1.5e-8);
521template <
typename FloatType>
522unsigned int truncatePositiveToUnsignedInt (FloatType value)
noexcept
524 jassert (value >=
static_cast<FloatType
> (0));
525 jassert (
static_cast<FloatType
> (value) <= std::numeric_limits<unsigned int>::max());
527 return static_cast<unsigned int> (value);
532template <
typename IntegerType>
533JUCE_CONSTEXPR
bool isPowerOfTwo (IntegerType value)
535 return (value & (value - 1)) == 0;
539inline int nextPowerOfTwo (
int n)
noexcept
554int findHighestSetBit (uint32 n)
noexcept;
557inline int countNumberOfBits (uint32 n)
noexcept
559 n -= ((n >> 1) & 0x55555555);
560 n = (((n >> 2) & 0x33333333) + (n & 0x33333333));
561 n = (((n >> 4) + n) & 0x0f0f0f0f);
564 return (
int) (n & 0x3f);
568inline int countNumberOfBits (uint64 n)
noexcept
570 return countNumberOfBits ((uint32) n) + countNumberOfBits ((uint32) (n >> 32));
576template <
typename IntegerType>
577IntegerType negativeAwareModulo (IntegerType dividend,
const IntegerType divisor)
noexcept
579 jassert (divisor > 0);
581 return (dividend < 0) ? (dividend + divisor) : dividend;
585template <
typename NumericType>
586inline JUCE_CONSTEXPR NumericType square (NumericType n)
noexcept
599void writeLittleEndianBitsInBuffer (
void* targetBuffer, uint32 startBit, uint32 numBits, uint32 value)
noexcept;
608uint32 readLittleEndianBitsInBuffer (
const void* sourceBuffer, uint32 startBit, uint32 numBits)
noexcept;
612#if JUCE_INTEL || defined (DOXYGEN)
617 #define JUCE_UNDENORMALISE(x) { (x) += 0.1f; (x) -= 0.1f; }
619 #define JUCE_UNDENORMALISE(x)
638 template <
typename Type>
struct ParameterType {
using type =
const Type&; };
641 template <
typename Type>
struct ParameterType <Type&> {
using type = Type&; };
642 template <
typename Type>
struct ParameterType <Type*> {
using type = Type*; };
643 template <>
struct ParameterType <char> {
using type = char; };
644 template <>
struct ParameterType <unsigned char> {
using type =
unsigned char; };
645 template <>
struct ParameterType <short> {
using type = short; };
646 template <>
struct ParameterType <unsigned short> {
using type =
unsigned short; };
647 template <>
struct ParameterType <int> {
using type = int; };
648 template <>
struct ParameterType <unsigned int> {
using type =
unsigned int; };
649 template <>
struct ParameterType <long> {
using type = long; };
650 template <>
struct ParameterType <unsigned long> {
using type =
unsigned long; };
651 template <>
struct ParameterType <int64> {
using type = int64; };
652 template <>
struct ParameterType <uint64> {
using type = uint64; };
653 template <>
struct ParameterType <bool> {
using type = bool; };
654 template <>
struct ParameterType <float> {
using type = float; };
655 template <>
struct ParameterType <double> {
using type = double; };
678 template <>
struct UnsignedTypeWithSize<2> {
using type = uint16; };
679 template <>
struct UnsignedTypeWithSize<4> {
using type = uint32; };
680 template <>
struct UnsignedTypeWithSize<8> {
using type = uint64; };
687 JUCE_DEPRECATED_ATTRIBUTE
inline int roundDoubleToInt (
double value)
noexcept {
return roundToInt (value); }
688 JUCE_DEPRECATED_ATTRIBUTE
inline int roundFloatToInt (
float value)
noexcept {
return roundToInt (value); }
691 JUCE_DEPRECATED_ATTRIBUTE
inline int64 abs64 (int64 n)
noexcept {
return std::abs (n); }
static const FloatType euler
static const FloatType twoPi
static const FloatType sqrt2
static const FloatType halfPi
static const FloatType pi