39 using int8 =
signed char;
41 using uint8 =
unsigned char;
43 using int16 =
signed short;
45 using uint16 =
unsigned short;
47 using int32 =
signed int;
49 using 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;
97 template <
typename Type>
98 JUCE_CONSTEXPR Type jmax (Type a, Type b) {
return a < b ? b : a; }
101 template <
typename Type>
102 JUCE_CONSTEXPR Type jmax (Type a, Type b, Type c) {
return a < b ? (b < c ? c : b) : (a < c ? c : a); }
105 template <
typename Type>
106 JUCE_CONSTEXPR Type jmax (Type a, Type b, Type c, Type d) {
return jmax (a, jmax (b, c, d)); }
109 template <
typename Type>
110 JUCE_CONSTEXPR Type jmin (Type a, Type b) {
return b < a ? b : a; }
113 template <
typename Type>
114 JUCE_CONSTEXPR Type jmin (Type a, Type b, Type c) {
return b < a ? (c < b ? c : b) : (c < a ? c : a); }
117 template <
typename Type>
118 JUCE_CONSTEXPR Type jmin (Type a, Type b, Type c, Type d) {
return jmin (a, jmin (b, c, d)); }
123 template <
typename Type>
124 JUCE_CONSTEXPR Type jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)
126 return targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin);
130 template <
typename Type>
131 Type jmap (Type sourceValue, Type sourceRangeMin, Type sourceRangeMax, Type targetRangeMin, Type targetRangeMax)
133 jassert (sourceRangeMax != sourceRangeMin);
134 return targetRangeMin + ((targetRangeMax - targetRangeMin) * (sourceValue - sourceRangeMin)) / (sourceRangeMax - sourceRangeMin);
138 template <
typename Type>
139 Type findMinimum (
const Type* data,
int numValues)
144 auto result = *data++;
146 while (--numValues > 0)
158 template <
typename Type>
159 Type findMaximum (
const Type* values,
int numValues)
164 auto result = *values++;
166 while (--numValues > 0)
178 template <
typename Type>
179 void findMinAndMax (
const Type* values,
int numValues, Type& lowest, Type& highest)
191 while (--numValues > 0)
221 template <
typename Type>
222 Type jlimit (Type lowerLimit,
224 Type valueToConstrain) noexcept
226 jassert (lowerLimit <= upperLimit);
228 return valueToConstrain < lowerLimit ? lowerLimit
229 : (upperLimit < valueToConstrain ? upperLimit
238 template <
typename Type1,
typename Type2>
239 bool isPositiveAndBelow (Type1 valueToTest, Type2 upperLimit) noexcept
241 jassert (Type1() <= static_cast<Type1> (upperLimit));
242 return Type1() <= valueToTest && valueToTest < static_cast<Type1> (upperLimit);
245 template <
typename Type>
246 bool isPositiveAndBelow (
int valueToTest, Type upperLimit) noexcept
248 jassert (upperLimit >= 0);
249 return static_cast<unsigned int> (valueToTest) < static_cast<unsigned int> (upperLimit);
257 template <
typename Type1,
typename Type2>
258 bool isPositiveAndNotGreaterThan (Type1 valueToTest, Type2 upperLimit) noexcept
260 jassert (Type1() <= static_cast<Type1> (upperLimit));
261 return Type1() <= valueToTest && valueToTest <= static_cast<Type1> (upperLimit);
264 template <
typename Type>
265 bool isPositiveAndNotGreaterThan (
int valueToTest, Type upperLimit) noexcept
267 jassert (upperLimit >= 0);
268 return static_cast<unsigned int> (valueToTest) <= static_cast<unsigned int> (upperLimit);
274 template <
typename Type>
275 bool isWithin (Type a, Type b, Type tolerance) noexcept
277 return std::abs (a - b) <= tolerance;
283 template <
typename Type>
284 bool 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();
292 template <
typename... Types>
293 void ignoreUnused (Types&&...) noexcept {}
303 template <
typename Type,
size_t N>
304 JUCE_CONSTEXPR
int numElementsInArray (Type (&)[N]) noexcept {
return N; }
311 template <
typename Type>
312 Type juce_hypot (Type a, Type b) noexcept
315 return static_cast<Type
> (_hypot (a, b));
317 return static_cast<Type
> (hypot (a, b));
323 inline float juce_hypot (
float a,
float b) noexcept
326 return _hypotf (a, b);
328 return hypotf (a, b);
334 #if JUCE_HAS_CONSTEXPR 340 template <
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);
365 template <
typename FloatType>
369 static const FloatType
pi;
384 template <
typename FloatType>
387 template <
typename FloatType>
390 template <
typename FloatType>
393 template <
typename FloatType>
396 template <
typename FloatType>
418 template <
typename FloatType>
419 JUCE_CONSTEXPR FloatType degreesToRadians (FloatType degrees) noexcept {
return degrees * (MathConstants<FloatType>::pi / FloatType (180)); }
422 template <
typename FloatType>
423 JUCE_CONSTEXPR FloatType radiansToDegrees (FloatType radians) noexcept {
return radians * (FloatType (180) / MathConstants<FloatType>::pi); }
430 template <
typename NumericType>
431 bool juce_isfinite (NumericType) noexcept
437 inline bool juce_isfinite (
float value) noexcept
439 #if JUCE_WINDOWS && ! JUCE_MINGW 440 return _finite (value) != 0;
442 return std::isfinite (value);
447 inline 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) 474 template <
typename FloatType>
475 int 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;
491 inline int roundToInt (
int value) noexcept
497 #ifndef __INTEL_COMPILER 498 #pragma float_control (pop) 500 #pragma optimize ("", on) // resets optimisations to the project defaults 508 inline int roundToIntAccurate (
double value) noexcept
510 #ifdef __INTEL_COMPILER 511 #pragma float_control (pop) 514 return roundToInt (value + 1.5e-8);
524 template <
typename FloatType>
525 unsigned 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);
535 template <
typename IntegerType>
536 JUCE_CONSTEXPR
bool isPowerOfTwo (IntegerType value)
538 return (value & (value - 1)) == 0;
542 inline int nextPowerOfTwo (
int n) noexcept
557 int findHighestSetBit (uint32 n) noexcept;
560 inline 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);
571 inline int countNumberOfBits (uint64 n) noexcept
573 return countNumberOfBits ((uint32) n) + countNumberOfBits ((uint32) (n >> 32));
579 template <
typename IntegerType>
580 IntegerType negativeAwareModulo (IntegerType dividend,
const IntegerType divisor) noexcept
582 jassert (divisor > 0);
584 return (dividend < 0) ? (dividend + divisor) : dividend;
588 template <
typename NumericType>
589 inline JUCE_CONSTEXPR NumericType square (NumericType n) noexcept
602 void writeLittleEndianBitsInBuffer (
void* targetBuffer, uint32 startBit, uint32 numBits, uint32 value) noexcept;
611 uint32 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) 628 namespace TypeHelpers
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; };
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); }
These templates are designed to take an integer type, and return an unsigned int version with the sam...
These templates are designed to take a type, and if it's a double, they return a double type; for any...
static const FloatType pi
A predefined value for Pi.
The ParameterType struct is used to find the best type to use when passing some kind of object as a p...
static const FloatType halfPi
A predefined value for Pi / 2.
static const FloatType euler
A predefined value for Euler's number.
static const FloatType sqrt2
A predefined value for sqrt(2)
static const FloatType twoPi
A predefined value for 2 * Pi.
Commonly used mathematical constants.