65 #define literal64bit(longLiteral) (longLiteral##LL)
85#if JUCE_WINDOWS && ! JUCE_MINGW
91template <
typename...
Types>
102template <
typename Type,
size_t N>
110template <
typename Type>
114 return static_cast<Type
> (
_hypot (a, b));
116 return static_cast<Type
> (
hypot (a, b));
122inline float juce_hypot (
float a,
float b)
noexcept
137template <
typename FloatType>
141 static constexpr FloatType
pi =
static_cast<FloatType
> (3.141592653589793238L);
144 static constexpr FloatType
twoPi =
static_cast<FloatType
> (2 * 3.141592653589793238L);
147 static constexpr FloatType
halfPi =
static_cast<FloatType
> (3.141592653589793238L / 2);
150 static constexpr FloatType
euler =
static_cast<FloatType
> (2.71828182845904523536L);
153 static constexpr FloatType
sqrt2 =
static_cast<FloatType
> (1.4142135623730950488L);
158[[
deprecated (
"This is deprecated in favour of MathConstants<double>::pi.")]]
162[[
deprecated (
"This is deprecated in favour of MathConstants<float>::pi.")]]
167template <
typename FloatType>
171template <
typename FloatType>
178template <
typename NumericType>
200template <
typename Type>
203 JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE (
"-Wfloat-equal")
205 JUCE_END_IGNORE_WARNINGS_GCC_LIKE
214template <
typename Type>
244 [[
nodiscard]] Type getAbsolute()
const {
return absolute; }
245 [[
nodiscard]] Type getRelative()
const {
return relative; }
256template <
typename Type>
266template <
typename Type>
298template <
typename Type, std::enable_if_t<std::is_
floating_po
int_v<Type>,
int> = 0>
307 const auto diff = std::abs (a - b);
314template <
typename Type, std::enable_if_t<! std::is_
floating_po
int_v<Type>,
int> = 0>
322template <
typename FloatType>
329template <
typename FloatType>
339template <
typename Type>
340constexpr Type
jmax (Type a, Type b) {
return a < b ? b : a; }
343template <
typename Type>
344constexpr Type
jmax (Type a, Type b, Type c) {
return a < b ? (b < c ? c : b) : (a < c ? c : a); }
347template <
typename Type>
348constexpr Type
jmax (Type a, Type b, Type c, Type d) {
return jmax (a,
jmax (b, c, d)); }
351template <
typename Type>
352constexpr Type
jmin (Type a, Type b) {
return b < a ? b : a; }
355template <
typename Type>
356constexpr Type
jmin (Type a, Type b, Type c) {
return b < a ? (c < b ? c : b) : (c < a ? c : a); }
359template <
typename Type>
360constexpr Type
jmin (Type a, Type b, Type c, Type d) {
return jmin (a,
jmin (b, c, d)); }
365template <
typename Type>
372template <
typename Type>
389template <
typename Type>
411template <
typename Type>
424template <
typename Type,
typename Size>
430 auto result = *data++;
444template <
typename Type,
typename Size>
450 auto result = *values++;
464template <
typename Type>
507template <
typename Type>
524template <
typename Type1,
typename Type2>
531template <
typename Type>
543template <
typename Type1,
typename Type2>
550template <
typename Type>
560template <
typename Type>
568 #pragma optimize ("t", off)
569 #ifndef __INTEL_COMPILER
570 #pragma float_control (precise, on, push)
584template <
typename FloatType>
587 #ifdef __INTEL_COMPILER
588 #pragma float_control (precise, on, push)
592 n.asDouble = ((
double) value) + 6755399441055744.0;
607 #ifndef __INTEL_COMPILER
608 #pragma float_control (pop)
610 #pragma optimize ("", on)
620 #ifdef __INTEL_COMPILER
621 #pragma float_control (pop)
634template <
typename FloatType>
637 jassert (value >=
static_cast<FloatType
> (0));
638 jassert (
static_cast<FloatType
> (value)
641 return static_cast<unsigned int> (value);
646template <
typename IntegerType>
649 return (value & (value - 1)) == 0;
673 n -= ((n >> 1) & 0x55555555);
674 n = (((n >> 2) & 0x33333333) + (n & 0x33333333));
675 n = (((n >> 4) + n) & 0x0f0f0f0f);
678 return (
int) (n & 0x3f);
690template <
typename IntegerType>
699template <
typename NumericType>
726#if JUCE_INTEL || DOXYGEN
731 #define JUCE_UNDENORMALISE(x) { (x) += 0.1f; (x) -= 0.1f; }
733 #define JUCE_UNDENORMALISE(x)
752 template <
typename Type>
struct ParameterType {
using type =
const Type&; };
755 template <
typename Type>
struct ParameterType <Type&> {
using type = Type&; };
756 template <
typename Type>
struct ParameterType <Type*> {
using type = Type*; };
757 template <>
struct ParameterType <
char> {
using type =
char; };
758 template <>
struct ParameterType <
unsigned char> {
using type =
unsigned char; };
759 template <>
struct ParameterType <
short> {
using type =
short; };
761 template <>
struct ParameterType <
int> {
using type =
int; };
762 template <>
struct ParameterType <
unsigned int> {
using type =
unsigned int; };
763 template <>
struct ParameterType <
long> {
using type =
long; };
764 template <>
struct ParameterType <
unsigned long> {
using type =
unsigned long; };
765 template <>
struct ParameterType <
int64> {
using type =
int64; };
766 template <>
struct ParameterType <
uint64> {
using type =
uint64; };
767 template <>
struct ParameterType <
bool> {
using type =
bool; };
768 template <>
struct ParameterType <
float> {
using type =
float; };
769 template <>
struct ParameterType <
double> {
using type =
double; };
777 template <
typename Type>
785 template <
int bytes>
struct UnsignedTypeWithSize {};
788 template <>
struct UnsignedTypeWithSize<1> {
using type =
uint8; };
789 template <>
struct UnsignedTypeWithSize<2> {
using type =
uint16; };
790 template <>
struct UnsignedTypeWithSize<4> {
using type =
uint32; };
791 template <>
struct UnsignedTypeWithSize<8> {
using type =
uint64; };
A class encapsulating both relative and absolute tolerances for use in floating-point comparisons.
Tolerance withRelative(Type newRelative)
Returns a copy of this Tolerance object with a new relative tolerance.
Tolerance withAbsolute(Type newAbsolute)
Returns a copy of this Tolerance object with a new absolute tolerance.
bool isWithin(Type a, Type b, Type tolerance) noexcept
Computes the absolute difference between two values and returns true if it is less than or equal to a...
Type mapToLog10(Type value0To1, Type logRangeMin, Type logRangeMax)
Remaps a normalised value (between 0 and 1) to a logarithmic target range.
unsigned short uint16
A platform-independent 16-bit unsigned integer type.
uint32 readLittleEndianBitsInBuffer(const void *buffer, uint32 startBit, uint32 numBits) noexcept
Reads a number of bits from a buffer at a given bit index.
int pointer_sized_int
A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it.
constexpr Type jmap(Type value0To1, Type targetRangeMin, Type targetRangeMax)
Remaps a normalised value (between 0 and 1) to a target range.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
void findMinAndMax(const Type *values, int numValues, Type &lowest, Type &highest)
Scans an array of values, returning the minimum and maximum values that it contains.
int findHighestSetBit(uint32 n) noexcept
Returns the index of the highest set bit in a (non-zero) number.
constexpr bool exactlyEqual(Type a, Type b)
Equivalent to operator==, but suppresses float-equality warnings.
int roundToIntAccurate(double value) noexcept
Fast floating-point-to-integer conversion.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
signed short int16
A platform-independent 16-bit signed integer type.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
signed int int32
A platform-independent 32-bit signed integer type.
FloatType nextFloatDown(FloatType value) noexcept
Returns the next representable value by FloatType in the direction of the lowest representable value.
int nextPowerOfTwo(int n) noexcept
Returns the smallest power-of-two which is equal to or greater than the given integer.
constexpr auto toUnderlyingType(T t) -> std::enable_if_t< std::is_enum_v< T >, std::underlying_type_t< T > >
Converts an enum to its underlying integral type.
void writeLittleEndianBitsInBuffer(void *buffer, uint32 startBit, uint32 numBits, uint32 value) noexcept
Writes a number of bits into a memory buffer at a given bit index.
constexpr NumericType square(NumericType n) noexcept
Returns the square of its argument.
void ignoreUnused(Types &&...) noexcept
Handy function for avoiding unused variables warning.
Object withMember(Object copy, Member OtherObject::*member, Other &&value)
Copies an object, sets one of the copy's members to the specified value, and then returns the copy.
constexpr int countNumberOfBits(uint32 n) noexcept
Returns the number of bits in a 32-bit integer.
signed char int8
A platform-independent 8-bit signed integer type.
Type findMaximum(const Type *values, Size numValues)
Scans an array of values, returning the maximum value that it contains.
Type juce_hypot(Type a, Type b) noexcept
Using juce_hypot is easier than dealing with the different types of hypot function that are provided ...
constexpr FloatType radiansToDegrees(FloatType radians) noexcept
Converts an angle in radians to degrees.
unsigned int pointer_sized_uint
An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it...
bool juce_isfinite(NumericType value) noexcept
The isfinite() method seems to vary between platforms, so this is a platform-independent function for...
unsigned long long uint64
A platform-independent 64-bit unsigned integer type.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
FloatType nextFloatUp(FloatType value) noexcept
Returns the next representable value by FloatType in the direction of the largest representable value...
bool isPositiveAndNotGreaterThan(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also less than or equal to a specified upper limit.
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.
constexpr bool isPowerOfTwo(IntegerType value)
Returns true if the specified integer is a power-of-two.
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
constexpr FloatType degreesToRadians(FloatType degrees) noexcept
Converts an angle in degrees to radians.
unsigned int truncatePositiveToUnsignedInt(FloatType value) noexcept
Truncates a positive floating-point number to an unsigned int.
IntegerType negativeAwareModulo(IntegerType dividend, const IntegerType divisor) noexcept
Performs a modulo operation, but can cope with the dividend being negative.
Type findMinimum(const Type *data, Size numValues)
Scans an array of values, returning the minimum value that it contains.
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
constexpr int numElementsInArray(Type(&)[N]) noexcept
Handy function for getting the number of elements in a simple const C array.
long long int64
A platform-independent 64-bit integer type.
Type mapFromLog10(Type valueInLogRange, Type logRangeMin, Type logRangeMax)
Remaps a logarithmic value in a target range to a normalised value (between 0 and 1).
Commonly used mathematical constants.
static constexpr FloatType halfPi
A predefined value for Pi / 2.
static constexpr FloatType twoPi
A predefined value for 2 * Pi.
static constexpr FloatType sqrt2
A predefined value for sqrt (2)
static constexpr FloatType pi
A predefined value for Pi.
static constexpr FloatType euler
A predefined value for Euler's number.