29 #ifndef JUCE_MATHSFUNCTIONS_H_INCLUDED
30 #define JUCE_MATHSFUNCTIONS_H_INCLUDED
55 typedef __int64
int64;
57 typedef unsigned __int64
uint64;
71 #define literal64bit(longLiteral) (longLiteral##LL)
99 template <
typename Type>
100 inline Type
jmax (
const Type a,
const Type
b) {
return (a < b) ? b : a; }
103 template <
typename Type>
104 inline Type
jmax (
const Type a,
const Type
b,
const Type c) {
return (a < b) ? ((b < c) ? c : b) : ((a < c) ? c : a); }
107 template <
typename Type>
108 inline Type
jmax (
const Type a,
const Type
b,
const Type c,
const Type d) {
return jmax (a,
jmax (b, c, d)); }
111 template <
typename Type>
112 inline Type
jmin (
const Type a,
const Type
b) {
return (b < a) ? b : a; }
115 template <
typename Type>
116 inline Type
jmin (
const Type a,
const Type
b,
const Type c) {
return (b < a) ? ((c <
b) ? c : b) : ((c < a) ? c : a); }
119 template <
typename Type>
120 inline Type
jmin (
const Type a,
const Type
b,
const Type c,
const Type d) {
return jmin (a,
jmin (b, c, d)); }
125 template <
class Type>
126 static Type jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)
128 return targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin);
132 template <
class Type>
133 static Type jmap (Type sourceValue, Type sourceRangeMin, Type sourceRangeMax, Type targetRangeMin, Type targetRangeMax)
135 return targetRangeMin + ((targetRangeMax - targetRangeMin) * (sourceValue - sourceRangeMin)) / (sourceRangeMax - sourceRangeMin);
139 template <
typename Type>
145 Type result (*data++);
147 while (--numValues > 0)
149 const Type& v = *data++;
150 if (v < result) result = v;
157 template <
typename Type>
163 Type result (*values++);
165 while (--numValues > 0)
167 const Type& v = *values++;
168 if (result < v) result = v;
175 template <
typename Type>
176 void findMinAndMax (
const Type* values,
int numValues, Type& lowest, Type& highest)
188 while (--numValues > 0)
190 const Type& v = *values++;
219 template <
typename Type>
220 inline Type
jlimit (
const Type lowerLimit,
221 const Type upperLimit,
222 const Type valueToConstrain)
noexcept
224 jassert (lowerLimit <= upperLimit);
226 return (valueToConstrain < lowerLimit) ? lowerLimit
227 : ((upperLimit < valueToConstrain) ? upperLimit
236 template <
typename Type>
239 jassert (Type() <= upperLimit);
240 return Type() <= valueToTest && valueToTest < upperLimit;
247 return static_cast <
unsigned int> (valueToTest) < static_cast <unsigned int> (upperLimit);
255 template <
typename Type>
258 jassert (Type() <= upperLimit);
259 return Type() <= valueToTest && valueToTest <= upperLimit;
266 return static_cast <
unsigned int> (valueToTest) <= static_cast <unsigned int> (upperLimit);
271 template <
typename Type>
274 std::swap (variable1, variable2);
278 template <
typename Type1>
281 template <
typename Type1,
typename Type2>
284 template <
typename Type1,
typename Type2,
typename Type3>
287 template <
typename Type1,
typename Type2,
typename Type3,
typename Type4>
298 template <
typename Type,
int N>
302 (
void)
sizeof (0[array]);
311 template <
typename Type>
314 #ifndef IGNORE_JUCE_HYPOT
316 return static_cast<Type
> (_hypot (a,
b));
318 return static_cast<Type
> (hypot (a,
b));
328 return (_hypotf (a,
b));
330 return (hypotf (a,
b));
338 return (n >= 0) ? n : -n;
341 #if JUCE_MSVC && ! defined (DOXYGEN) // The MSVC libraries omit these functions for some reason...
342 template<
typename Type> Type asinh (Type x)
noexcept {
return std::log (x + std::sqrt (x * x + (Type) 1)); }
343 template<
typename Type> Type acosh (Type x)
noexcept {
return std::log (x + std::sqrt (x * x - (Type) 1)); }
344 template<
typename Type> Type atanh (Type x)
noexcept {
return (std::log (x + (Type) 1) - std::log (((Type) 1) - x)) / (Type) 2; }
351 const double double_Pi = 3.1415926535897932384626433832795;
360 template <
typename FloatType>
364 template <
typename FloatType>
372 template <
typename NumericType>
381 #if JUCE_WINDOWS && !JUCE_MINGW
382 return _finite (value) != 0;
384 return std::isfinite (value);
391 #if JUCE_WINDOWS && !JUCE_MINGW
392 return _finite (value) != 0;
394 return std::isfinite (value);
400 #pragma optimize ("t", off)
401 #ifndef __INTEL_COMPILER
402 #pragma float_control (precise, on, push)
416 template <
typename FloatType>
419 #ifdef __INTEL_COMPILER
420 #pragma float_control (precise, on, push)
423 union {
int asInt[2];
double asDouble; } n;
424 n.asDouble = ((double) value) + 6755399441055744.0;
439 #ifndef __INTEL_COMPILER
440 #pragma float_control (pop)
442 #pragma optimize ("", on) // resets optimisations to the project defaults
452 #ifdef __INTEL_COMPILER
453 #pragma float_control (pop)
492 template <
typename IntegerType>
495 return (value & (value - 1)) == 0;
513 n -= ((n >> 1) & 0x55555555);
514 n = (((n >> 2) & 0x33333333) + (n & 0x33333333));
515 n = (((n >> 4) + n) & 0x0f0f0f0f);
518 return (
int) (n & 0x3f);
530 template <
typename IntegerType>
535 return (dividend < 0) ? (dividend + divisor) : dividend;
539 template <
typename NumericType>
547 #if JUCE_INTEL || defined (DOXYGEN)
552 #define JUCE_UNDENORMALISE(x) { (x) += 0.1f; (x) -= 0.1f; }
554 #define JUCE_UNDENORMALISE(x)
562 #if JUCE_VC8_OR_EARLIER
563 #define PARAMETER_TYPE(type) const type&
600 #define PARAMETER_TYPE(a) typename TypeHelpers::ParameterType<a>::type
614 #endif // JUCE_MATHSFUNCTIONS_H_INCLUDED
int numElementsInArray(Type(&array)[N])
Definition: juce_MathsFunctions.h:299
double type
Definition: juce_MathsFunctions.h:608
Type juce_hypot(Type a, Type b) noexcept
Definition: juce_MathsFunctions.h:312
const Type & type
Definition: juce_MathsFunctions.h:577
Definition: juce_MathsFunctions.h:577
Definition: juce_MathsFunctions.h:560
unsigned long type
Definition: juce_MathsFunctions.h:589
const double double_Pi
Definition: juce_MathsFunctions.h:351
int pointer_sized_int
Definition: juce_MathsFunctions.h:86
const Type findMinimum(const Type *data, int numValues)
Definition: juce_MathsFunctions.h:140
int nextPowerOfTwo(int n) noexcept
Definition: juce_MathsFunctions.h:499
#define noexcept
Definition: juce_CompilerSupport.h:141
signed short int16
Definition: juce_MathsFunctions.h:45
short type
Definition: juce_MathsFunctions.h:584
unsigned short uint16
Definition: juce_MathsFunctions.h:47
Type jmax(const Type a, const Type b)
Definition: juce_MathsFunctions.h:100
bool isPositiveAndBelow(Type valueToTest, Type upperLimit) noexcept
Definition: juce_MathsFunctions.h:237
bool isPowerOfTwo(IntegerType value)
Definition: juce_MathsFunctions.h:493
NumericType square(NumericType n) noexcept
Definition: juce_MathsFunctions.h:540
unsigned char type
Definition: juce_MathsFunctions.h:583
int roundFloatToInt(const float value) noexcept
Definition: juce_MathsFunctions.h:485
int countNumberOfBits(uint32 n) noexcept
Definition: juce_MathsFunctions.h:511
int roundDoubleToInt(const double value) noexcept
Definition: juce_MathsFunctions.h:470
long b
Definition: jpegint.h:371
const float float_Pi
Definition: juce_MathsFunctions.h:356
float type
Definition: juce_MathsFunctions.h:593
Type jmin(const Type a, const Type b)
Definition: juce_MathsFunctions.h:112
uint64 type
Definition: juce_MathsFunctions.h:591
Definition: juce_MathsFunctions.h:607
FloatType radiansToDegrees(FloatType radians) noexcept
Definition: juce_MathsFunctions.h:365
void findMinAndMax(const Type *values, int numValues, Type &lowest, Type &highest)
Definition: juce_MathsFunctions.h:176
double type
Definition: juce_MathsFunctions.h:594
char type
Definition: juce_MathsFunctions.h:582
int type
Definition: juce_MathsFunctions.h:586
int64 type
Definition: juce_MathsFunctions.h:590
int64 abs64(const int64 n) noexcept
Definition: juce_MathsFunctions.h:336
unsigned long long uint64
Definition: juce_MathsFunctions.h:62
unsigned int uint32
Definition: juce_MathsFunctions.h:51
unsigned int type
Definition: juce_MathsFunctions.h:587
int roundToInt(const FloatType value) noexcept
Definition: juce_MathsFunctions.h:417
bool juce_isfinite(NumericType) noexcept
Definition: juce_MathsFunctions.h:373
FloatType degreesToRadians(FloatType degrees) noexcept
Definition: juce_MathsFunctions.h:361
IntegerType negativeAwareModulo(IntegerType dividend, const IntegerType divisor) noexcept
Definition: juce_MathsFunctions.h:531
void ignoreUnused(const Type1 &) noexcept
Definition: juce_MathsFunctions.h:279
bool type
Definition: juce_MathsFunctions.h:592
long long int64
Definition: juce_MathsFunctions.h:60
bool isPositiveAndNotGreaterThan(Type valueToTest, Type upperLimit) noexcept
Definition: juce_MathsFunctions.h:256
Type jlimit(const Type lowerLimit, const Type upperLimit, const Type valueToConstrain) noexcept
Definition: juce_MathsFunctions.h:220
Type & type
Definition: juce_MathsFunctions.h:580
signed char int8
Definition: juce_MathsFunctions.h:41
Type * type
Definition: juce_MathsFunctions.h:581
float type
Definition: juce_MathsFunctions.h:607
int roundToIntAccurate(const double value) noexcept
Definition: juce_MathsFunctions.h:450
void
Definition: juce_PNGLoader.cpp:1173
JSAMPIMAGE data
Definition: jpeglib.h:945
const Type findMaximum(const Type *values, int numValues)
Definition: juce_MathsFunctions.h:158
unsigned char uint8
Definition: juce_MathsFunctions.h:43
void swapVariables(Type &variable1, Type &variable2)
Definition: juce_MathsFunctions.h:272
unsigned int pointer_sized_uint
Definition: juce_MathsFunctions.h:88
unsigned short type
Definition: juce_MathsFunctions.h:585
long type
Definition: juce_MathsFunctions.h:588
signed int int32
Definition: juce_MathsFunctions.h:49