35 using int8 =
signed char;
37 using uint8 =
unsigned char;
39 using int16 =
signed short;
41 using uint16 =
unsigned short;
43 using int32 =
signed int;
45 using 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;
93 template <
typename Type>
94 JUCE_CONSTEXPR Type jmax (Type a, Type b) {
return a < b ? b : a; }
97 template <
typename Type>
98 JUCE_CONSTEXPR Type jmax (Type a, Type b, Type c) {
return a < b ? (b < c ? c : b) : (a < c ? c : a); }
101 template <
typename Type>
102 JUCE_CONSTEXPR Type jmax (Type a, Type b, Type c, Type d) {
return jmax (a, jmax (b, c, d)); }
105 template <
typename Type>
106 JUCE_CONSTEXPR Type jmin (Type a, Type b) {
return b < a ? b : a; }
109 template <
typename Type>
110 JUCE_CONSTEXPR Type jmin (Type a, Type b, Type c) {
return b < a ? (c < b ? c : b) : (c < a ? c : a); }
113 template <
typename Type>
114 JUCE_CONSTEXPR Type jmin (Type a, Type b, Type c, Type d) {
return jmin (a, jmin (b, c, d)); }
119 template <
typename Type>
120 JUCE_CONSTEXPR Type jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)
122 return targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin);
126 template <
typename Type>
127 Type jmap (Type sourceValue, Type sourceRangeMin, Type sourceRangeMax, Type targetRangeMin, Type targetRangeMax)
129 jassert (sourceRangeMax != sourceRangeMin);
130 return targetRangeMin + ((targetRangeMax - targetRangeMin) * (sourceValue - sourceRangeMin)) / (sourceRangeMax - sourceRangeMin);
134 template <
typename Type>
135 Type findMinimum (
const Type* data,
int numValues)
140 auto result = *data++;
142 while (--numValues > 0)
154 template <
typename Type>
155 Type findMaximum (
const Type* values,
int numValues)
160 auto result = *values++;
162 while (--numValues > 0)
174 template <
typename Type>
175 void findMinAndMax (
const Type* values,
int numValues, Type& lowest, Type& highest)
187 while (--numValues > 0)
217 template <
typename Type>
218 Type jlimit (Type lowerLimit,
220 Type valueToConstrain) noexcept
222 jassert (lowerLimit <= upperLimit);
224 return valueToConstrain < lowerLimit ? lowerLimit
225 : (upperLimit < valueToConstrain ? upperLimit
234 template <
typename Type1,
typename Type2>
235 bool isPositiveAndBelow (Type1 valueToTest, Type2 upperLimit) noexcept
237 jassert (Type1() <=
static_cast<Type1
> (upperLimit));
238 return Type1() <= valueToTest && valueToTest < static_cast<Type1> (upperLimit);
241 template <
typename Type>
242 bool isPositiveAndBelow (
int valueToTest, Type upperLimit) noexcept
244 jassert (upperLimit >= 0);
245 return static_cast<unsigned int> (valueToTest) <
static_cast<unsigned int> (upperLimit);
253 template <
typename Type1,
typename Type2>
254 bool isPositiveAndNotGreaterThan (Type1 valueToTest, Type2 upperLimit) noexcept
256 jassert (Type1() <=
static_cast<Type1
> (upperLimit));
257 return Type1() <= valueToTest && valueToTest <= static_cast<Type1> (upperLimit);
260 template <
typename Type>
261 bool isPositiveAndNotGreaterThan (
int valueToTest, Type upperLimit) noexcept
263 jassert (upperLimit >= 0);
264 return static_cast<unsigned int> (valueToTest) <=
static_cast<unsigned int> (upperLimit);
270 template <
typename Type>
271 bool isWithin (Type a, Type b, Type tolerance) noexcept
273 return std::abs (a - b) <= tolerance;
279 template <
typename Type>
280 bool 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();
288 template <
typename... Types>
289 void ignoreUnused (Types&&...) noexcept {}
299 template <
typename Type,
size_t N>
300 JUCE_CONSTEXPR
int numElementsInArray (Type (&)[N]) noexcept {
return N; }
307 template <
typename Type>
308 Type juce_hypot (Type a, Type b) noexcept
311 return static_cast<Type
> (_hypot (a, b));
313 return static_cast<Type
> (hypot (a, b));
319 inline float juce_hypot (
float a,
float b) noexcept
322 return _hypotf (a, b);
324 return hypotf (a, b);
330 #if JUCE_HAS_CONSTEXPR
336 template <
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);
361 template <
typename FloatType>
365 static const FloatType
pi;
380 template <
typename FloatType>
383 template <
typename FloatType>
386 template <
typename FloatType>
389 template <
typename FloatType>
392 template <
typename FloatType>
414 template <
typename FloatType>
415 JUCE_CONSTEXPR FloatType degreesToRadians (FloatType degrees) noexcept {
return degrees * (
MathConstants<FloatType>::pi / FloatType (180)); }
418 template <
typename FloatType>
419 JUCE_CONSTEXPR FloatType radiansToDegrees (FloatType radians) noexcept {
return radians * (FloatType (180) /
MathConstants<FloatType>::pi); }
426 template <
typename NumericType>
427 bool juce_isfinite (NumericType) noexcept
433 inline bool juce_isfinite (
float value) noexcept
435 #if JUCE_WINDOWS && ! JUCE_MINGW
436 return _finite (value) != 0;
438 return std::isfinite (value);
443 inline 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)
470 template <
typename FloatType>
471 int 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;
487 inline int roundToInt (
int value) noexcept
493 #ifndef __INTEL_COMPILER
494 #pragma float_control (pop)
496 #pragma optimize ("", on)
504 inline int roundToIntAccurate (
double value) noexcept
506 #ifdef __INTEL_COMPILER
507 #pragma float_control (pop)
510 return roundToInt (value + 1.5e-8);
520 template <
typename FloatType>
521 unsigned 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);
531 template <
typename IntegerType>
532 JUCE_CONSTEXPR
bool isPowerOfTwo (IntegerType value)
534 return (value & (value - 1)) == 0;
538 inline int nextPowerOfTwo (
int n) noexcept
553 int findHighestSetBit (uint32 n) noexcept;
556 inline 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);
567 inline int countNumberOfBits (uint64 n) noexcept
569 return countNumberOfBits ((uint32) n) + countNumberOfBits ((uint32) (n >> 32));
575 template <
typename IntegerType>
576 IntegerType negativeAwareModulo (IntegerType dividend,
const IntegerType divisor) noexcept
578 jassert (divisor > 0);
580 return (dividend < 0) ? (dividend + divisor) : dividend;
584 template <
typename NumericType>
585 inline JUCE_CONSTEXPR NumericType square (NumericType n) noexcept
598 void writeLittleEndianBitsInBuffer (
void* targetBuffer, uint32 startBit, uint32 numBits, uint32 value) noexcept;
607 uint32 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)
624 namespace TypeHelpers
637 template <
typename Type>
struct ParameterType {
using type =
const Type&; };
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