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;
80 using pointer_sized_int = int;
82 using pointer_sized_uint =
unsigned int;
85#if JUCE_WINDOWS && ! JUCE_MINGW
86 using ssize_t = pointer_sized_int;
93template <
typename Type>
94JUCE_CONSTEXPR Type jmax (Type a, Type b) {
return a < b ? b : a; }
97template <
typename Type>
98JUCE_CONSTEXPR Type jmax (Type a, Type b, Type c) {
return a < b ? (b < c ? c : b) : (a < c ? c : a); }
101template <
typename Type>
102JUCE_CONSTEXPR Type jmax (Type a, Type b, Type c, Type d) {
return jmax (a, jmax (b, c, d)); }
105template <
typename Type>
106JUCE_CONSTEXPR Type jmin (Type a, Type b) {
return b < a ? b : a; }
109template <
typename Type>
110JUCE_CONSTEXPR Type jmin (Type a, Type b, Type c) {
return b < a ? (c < b ? c : b) : (c < a ? c : a); }
113template <
typename Type>
114JUCE_CONSTEXPR Type jmin (Type a, Type b, Type c, Type d) {
return jmin (a, jmin (b, c, d)); }
119template <
typename Type>
120JUCE_CONSTEXPR Type jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)
122 return targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin);
126template <
typename Type>
127Type jmap (Type sourceValue, Type sourceRangeMin, Type sourceRangeMax, Type targetRangeMin, Type targetRangeMax)
129 jassert (sourceRangeMax != sourceRangeMin);
130 return targetRangeMin + ((targetRangeMax - targetRangeMin) * (sourceValue - sourceRangeMin)) / (sourceRangeMax - sourceRangeMin);
134template <
typename Type>
135Type findMinimum (
const Type* data,
int numValues)
140 auto result = *data++;
142 while (--numValues > 0)
154template <
typename Type>
155Type findMaximum (
const Type* values,
int numValues)
160 auto result = *values++;
162 while (--numValues > 0)
174template <
typename Type>
175void findMinAndMax (
const Type* values,
int numValues, Type& lowest, Type& highest)
187 while (--numValues > 0)
217template <
typename Type>
218Type jlimit (Type lowerLimit,
220 Type valueToConstrain)
noexcept
222 jassert (lowerLimit <= upperLimit);
224 return valueToConstrain < lowerLimit ? lowerLimit
225 : (upperLimit < valueToConstrain ? upperLimit
234template <
typename Type1,
typename Type2>
235bool isPositiveAndBelow (Type1 valueToTest, Type2 upperLimit)
noexcept
237 jassert (Type1() <=
static_cast<Type1
> (upperLimit));
238 return Type1() <= valueToTest && valueToTest < static_cast<Type1> (upperLimit);
241template <
typename Type>
242bool isPositiveAndBelow (
int valueToTest, Type upperLimit)
noexcept
244 jassert (upperLimit >= 0);
245 return static_cast<unsigned int> (valueToTest) <
static_cast<unsigned int> (upperLimit);
253template <
typename Type1,
typename Type2>
254bool isPositiveAndNotGreaterThan (Type1 valueToTest, Type2 upperLimit)
noexcept
256 jassert (Type1() <=
static_cast<Type1
> (upperLimit));
257 return Type1() <= valueToTest && valueToTest <= static_cast<Type1> (upperLimit);
260template <
typename Type>
261bool isPositiveAndNotGreaterThan (
int valueToTest, Type upperLimit)
noexcept
263 jassert (upperLimit >= 0);
264 return static_cast<unsigned int> (valueToTest) <=
static_cast<unsigned int> (upperLimit);
270template <
typename Type>
271bool isWithin (Type a, Type b, Type tolerance)
noexcept
273 return std::abs (a - b) <= tolerance;
279template <
typename Type>
280bool approximatelyEqual (Type a, Type b)
noexcept
282 return std::abs (a - b) <= (std::numeric_limits<Type>::epsilon() * std::max (a, b))
283 || std::abs (a - b) < std::numeric_limits<Type>::min();
288template <
typename... Types>
289void ignoreUnused (Types&&...) noexcept {}
299template <
typename Type,
size_t N>
300JUCE_CONSTEXPR
int numElementsInArray (Type (&)[N])
noexcept {
return N; }
307template <
typename Type>
308Type juce_hypot (Type a, Type b)
noexcept
311 return static_cast<Type
> (_hypot (a, b));
313 return static_cast<Type
> (hypot (a, b));
319inline float juce_hypot (
float a,
float b)
noexcept
322 return _hypotf (a, b);
324 return hypotf (a, b);
330#if JUCE_HAS_CONSTEXPR
336template <
typename FloatType>
340 static constexpr FloatType
pi =
static_cast<FloatType
> (3.141592653589793238L);
343 static constexpr FloatType
twoPi =
static_cast<FloatType
> (2 * 3.141592653589793238L);
346 static constexpr FloatType
halfPi =
static_cast<FloatType
> (3.141592653589793238L / 2);
349 static constexpr FloatType
euler =
static_cast<FloatType
> (2.71828182845904523536L);
352 static constexpr FloatType
sqrt2 =
static_cast<FloatType
> (1.4142135623730950488L);
361template <
typename FloatType>
365 static const FloatType
pi;
380template <
typename FloatType>
383template <
typename FloatType>
386template <
typename FloatType>
389template <
typename FloatType>
392template <
typename FloatType>
414template <
typename FloatType>
418template <
typename FloatType>
419JUCE_CONSTEXPR FloatType radiansToDegrees (FloatType radians)
noexcept {
return radians * (FloatType (180) /
MathConstants<FloatType>::pi); }
426template <
typename NumericType>
427bool juce_isfinite (NumericType)
noexcept
433inline bool juce_isfinite (
float value)
noexcept
435 #if JUCE_WINDOWS && ! JUCE_MINGW
436 return _finite (value) != 0;
438 return std::isfinite (value);
443inline bool juce_isfinite (
double value)
noexcept
445 #if JUCE_WINDOWS && ! JUCE_MINGW
446 return _finite (value) != 0;
448 return std::isfinite (value);
454 #pragma optimize ("t", off)
455 #ifndef __INTEL_COMPILER
456 #pragma float_control (precise, on, push)
470template <
typename FloatType>
471int roundToInt (
const FloatType value)
noexcept
473 #ifdef __INTEL_COMPILER
474 #pragma float_control (precise, on, push)
477 union {
int asInt[2];
double asDouble; } n;
478 n.asDouble = ((double) value) + 6755399441055744.0;
487inline int roundToInt (
int value)
noexcept
493 #ifndef __INTEL_COMPILER
494 #pragma float_control (pop)
496 #pragma optimize ("", on)
504inline int roundToIntAccurate (
double value)
noexcept
506 #ifdef __INTEL_COMPILER
507 #pragma float_control (pop)
510 return roundToInt (value + 1.5e-8);
520template <
typename FloatType>
521unsigned int truncatePositiveToUnsignedInt (FloatType value)
noexcept
523 jassert (value >=
static_cast<FloatType
> (0));
524 jassert (
static_cast<FloatType
> (value) <= std::numeric_limits<unsigned int>::max());
526 return static_cast<unsigned int> (value);
531template <
typename IntegerType>
532JUCE_CONSTEXPR
bool isPowerOfTwo (IntegerType value)
534 return (value & (value - 1)) == 0;
538inline int nextPowerOfTwo (
int n)
noexcept
553int findHighestSetBit (uint32 n)
noexcept;
556inline int countNumberOfBits (uint32 n)
noexcept
558 n -= ((n >> 1) & 0x55555555);
559 n = (((n >> 2) & 0x33333333) + (n & 0x33333333));
560 n = (((n >> 4) + n) & 0x0f0f0f0f);
563 return (
int) (n & 0x3f);
567inline int countNumberOfBits (uint64 n)
noexcept
569 return countNumberOfBits ((uint32) n) + countNumberOfBits ((uint32) (n >> 32));
575template <
typename IntegerType>
576IntegerType negativeAwareModulo (IntegerType dividend,
const IntegerType divisor)
noexcept
578 jassert (divisor > 0);
580 return (dividend < 0) ? (dividend + divisor) : dividend;
584template <
typename NumericType>
585inline JUCE_CONSTEXPR NumericType square (NumericType n)
noexcept
598void writeLittleEndianBitsInBuffer (
void* targetBuffer, uint32 startBit, uint32 numBits, uint32 value)
noexcept;
607uint32 readLittleEndianBitsInBuffer (
const void* sourceBuffer, uint32 startBit, uint32 numBits)
noexcept;
611#if JUCE_INTEL || defined (DOXYGEN)
616 #define JUCE_UNDENORMALISE(x) { (x) += 0.1f; (x) -= 0.1f; }
618 #define JUCE_UNDENORMALISE(x)
640 template <
typename Type>
struct ParameterType <Type&> {
using type = Type&; };
641 template <
typename Type>
struct ParameterType <Type*> {
using type = Type*; };
642 template <>
struct ParameterType <char> {
using type = char; };
643 template <>
struct ParameterType <unsigned char> {
using type =
unsigned char; };
644 template <>
struct ParameterType <short> {
using type = short; };
645 template <>
struct ParameterType <unsigned short> {
using type =
unsigned short; };
646 template <>
struct ParameterType <int> {
using type = int; };
647 template <>
struct ParameterType <unsigned int> {
using type =
unsigned int; };
648 template <>
struct ParameterType <long> {
using type = long; };
649 template <>
struct ParameterType <unsigned long> {
using type =
unsigned long; };
650 template <>
struct ParameterType <int64> {
using type = int64; };
651 template <>
struct ParameterType <uint64> {
using type = uint64; };
652 template <>
struct ParameterType <bool> {
using type = bool; };
653 template <>
struct ParameterType <float> {
using type = float; };
654 template <>
struct ParameterType <double> {
using type = double; };
677 template <>
struct UnsignedTypeWithSize<2> {
using type = uint16; };
678 template <>
struct UnsignedTypeWithSize<4> {
using type = uint32; };
679 template <>
struct UnsignedTypeWithSize<8> {
using type = uint64; };
686 JUCE_DEPRECATED_ATTRIBUTE
inline int roundDoubleToInt (
double value)
noexcept {
return roundToInt (value); }
687 JUCE_DEPRECATED_ATTRIBUTE
inline int roundFloatToInt (
float value)
noexcept {
return roundToInt (value); }
690 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