The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

637 lines
24KB

  1. /*
  2. ==============================================================================
  3. This file is part of the juce_core module of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. or without fee is hereby granted, provided that the above copyright notice and this
  7. permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  9. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  10. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  11. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  12. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. ------------------------------------------------------------------------------
  15. NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
  16. All other JUCE modules are covered by a dual GPL/commercial license, so if you are
  17. using any other modules, be sure to check that you also comply with their license.
  18. For more details, visit www.juce.com
  19. ==============================================================================
  20. */
  21. #ifndef JUCE_MATHSFUNCTIONS_H_INCLUDED
  22. #define JUCE_MATHSFUNCTIONS_H_INCLUDED
  23. //==============================================================================
  24. /*
  25. This file sets up some handy mathematical typdefs and functions.
  26. */
  27. //==============================================================================
  28. // Definitions for the int8, int16, int32, int64 and pointer_sized_int types.
  29. /** A platform-independent 8-bit signed integer type. */
  30. typedef signed char int8;
  31. /** A platform-independent 8-bit unsigned integer type. */
  32. typedef unsigned char uint8;
  33. /** A platform-independent 16-bit signed integer type. */
  34. typedef signed short int16;
  35. /** A platform-independent 16-bit unsigned integer type. */
  36. typedef unsigned short uint16;
  37. /** A platform-independent 32-bit signed integer type. */
  38. typedef signed int int32;
  39. /** A platform-independent 32-bit unsigned integer type. */
  40. typedef unsigned int uint32;
  41. #if JUCE_MSVC
  42. /** A platform-independent 64-bit integer type. */
  43. typedef __int64 int64;
  44. /** A platform-independent 64-bit unsigned integer type. */
  45. typedef unsigned __int64 uint64;
  46. #else
  47. /** A platform-independent 64-bit integer type. */
  48. typedef long long int64;
  49. /** A platform-independent 64-bit unsigned integer type. */
  50. typedef unsigned long long uint64;
  51. #endif
  52. #ifndef DOXYGEN
  53. /** A macro for creating 64-bit literals.
  54. Historically, this was needed to support portability with MSVC6, and is kept here
  55. so that old code will still compile, but nowadays every compiler will support the
  56. LL and ULL suffixes, so you should use those in preference to this macro.
  57. */
  58. #define literal64bit(longLiteral) (longLiteral##LL)
  59. #endif
  60. #if JUCE_64BIT
  61. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  62. typedef int64 pointer_sized_int;
  63. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  64. typedef uint64 pointer_sized_uint;
  65. #elif JUCE_MSVC
  66. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  67. typedef _W64 int pointer_sized_int;
  68. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  69. typedef _W64 unsigned int pointer_sized_uint;
  70. #else
  71. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  72. typedef int pointer_sized_int;
  73. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  74. typedef unsigned int pointer_sized_uint;
  75. #endif
  76. #if JUCE_WINDOWS && ! JUCE_MINGW
  77. typedef pointer_sized_int ssize_t;
  78. #endif
  79. //==============================================================================
  80. // Some indispensable min/max functions
  81. /** Returns the larger of two values. */
  82. template <typename Type>
  83. Type jmax (const Type a, const Type b) { return (a < b) ? b : a; }
  84. /** Returns the larger of three values. */
  85. template <typename Type>
  86. Type jmax (const Type a, const Type b, const Type c) { return (a < b) ? ((b < c) ? c : b) : ((a < c) ? c : a); }
  87. /** Returns the larger of four values. */
  88. template <typename Type>
  89. Type jmax (const Type a, const Type b, const Type c, const Type d) { return jmax (a, jmax (b, c, d)); }
  90. /** Returns the smaller of two values. */
  91. template <typename Type>
  92. Type jmin (const Type a, const Type b) { return (b < a) ? b : a; }
  93. /** Returns the smaller of three values. */
  94. template <typename Type>
  95. Type jmin (const Type a, const Type b, const Type c) { return (b < a) ? ((c < b) ? c : b) : ((c < a) ? c : a); }
  96. /** Returns the smaller of four values. */
  97. template <typename Type>
  98. Type jmin (const Type a, const Type b, const Type c, const Type d) { return jmin (a, jmin (b, c, d)); }
  99. /** Remaps a normalised value (between 0 and 1) to a target range.
  100. This effectively returns (targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin)).
  101. */
  102. template <typename Type>
  103. Type jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)
  104. {
  105. return targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin);
  106. }
  107. /** Remaps a value from a source range to a target range. */
  108. template <typename Type>
  109. Type jmap (Type sourceValue, Type sourceRangeMin, Type sourceRangeMax, Type targetRangeMin, Type targetRangeMax)
  110. {
  111. jassert (sourceRangeMax != sourceRangeMin); // mapping from a range of zero will produce NaN!
  112. return targetRangeMin + ((targetRangeMax - targetRangeMin) * (sourceValue - sourceRangeMin)) / (sourceRangeMax - sourceRangeMin);
  113. }
  114. /** Scans an array of values, returning the minimum value that it contains. */
  115. template <typename Type>
  116. Type findMinimum (const Type* data, int numValues)
  117. {
  118. if (numValues <= 0)
  119. return Type();
  120. Type result (*data++);
  121. while (--numValues > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  122. {
  123. const Type& v = *data++;
  124. if (v < result) result = v;
  125. }
  126. return result;
  127. }
  128. /** Scans an array of values, returning the maximum value that it contains. */
  129. template <typename Type>
  130. Type findMaximum (const Type* values, int numValues)
  131. {
  132. if (numValues <= 0)
  133. return Type();
  134. Type result (*values++);
  135. while (--numValues > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  136. {
  137. const Type& v = *values++;
  138. if (result < v) result = v;
  139. }
  140. return result;
  141. }
  142. /** Scans an array of values, returning the minimum and maximum values that it contains. */
  143. template <typename Type>
  144. void findMinAndMax (const Type* values, int numValues, Type& lowest, Type& highest)
  145. {
  146. if (numValues <= 0)
  147. {
  148. lowest = Type();
  149. highest = Type();
  150. }
  151. else
  152. {
  153. Type mn (*values++);
  154. Type mx (mn);
  155. while (--numValues > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  156. {
  157. const Type& v = *values++;
  158. if (mx < v) mx = v;
  159. if (v < mn) mn = v;
  160. }
  161. lowest = mn;
  162. highest = mx;
  163. }
  164. }
  165. //==============================================================================
  166. /** Constrains a value to keep it within a given range.
  167. This will check that the specified value lies between the lower and upper bounds
  168. specified, and if not, will return the nearest value that would be in-range. Effectively,
  169. it's like calling jmax (lowerLimit, jmin (upperLimit, value)).
  170. Note that it expects that lowerLimit <= upperLimit. If this isn't true,
  171. the results will be unpredictable.
  172. @param lowerLimit the minimum value to return
  173. @param upperLimit the maximum value to return
  174. @param valueToConstrain the value to try to return
  175. @returns the closest value to valueToConstrain which lies between lowerLimit
  176. and upperLimit (inclusive)
  177. @see jmin, jmax, jmap
  178. */
  179. template <typename Type>
  180. Type jlimit (const Type lowerLimit,
  181. const Type upperLimit,
  182. const Type valueToConstrain) noexcept
  183. {
  184. jassert (lowerLimit <= upperLimit); // if these are in the wrong order, results are unpredictable..
  185. return (valueToConstrain < lowerLimit) ? lowerLimit
  186. : ((upperLimit < valueToConstrain) ? upperLimit
  187. : valueToConstrain);
  188. }
  189. /** Returns true if a value is at least zero, and also below a specified upper limit.
  190. This is basically a quicker way to write:
  191. @code valueToTest >= 0 && valueToTest < upperLimit
  192. @endcode
  193. */
  194. template <typename Type>
  195. bool isPositiveAndBelow (Type valueToTest, Type upperLimit) noexcept
  196. {
  197. jassert (Type() <= upperLimit); // makes no sense to call this if the upper limit is itself below zero..
  198. return Type() <= valueToTest && valueToTest < upperLimit;
  199. }
  200. template <>
  201. inline bool isPositiveAndBelow (const int valueToTest, const int upperLimit) noexcept
  202. {
  203. jassert (upperLimit >= 0); // makes no sense to call this if the upper limit is itself below zero..
  204. return static_cast<unsigned int> (valueToTest) < static_cast<unsigned int> (upperLimit);
  205. }
  206. /** Returns true if a value is at least zero, and also less than or equal to a specified upper limit.
  207. This is basically a quicker way to write:
  208. @code valueToTest >= 0 && valueToTest <= upperLimit
  209. @endcode
  210. */
  211. template <typename Type>
  212. bool isPositiveAndNotGreaterThan (Type valueToTest, Type upperLimit) noexcept
  213. {
  214. jassert (Type() <= upperLimit); // makes no sense to call this if the upper limit is itself below zero..
  215. return Type() <= valueToTest && valueToTest <= upperLimit;
  216. }
  217. template <>
  218. inline bool isPositiveAndNotGreaterThan (const int valueToTest, const int upperLimit) noexcept
  219. {
  220. jassert (upperLimit >= 0); // makes no sense to call this if the upper limit is itself below zero..
  221. return static_cast<unsigned int> (valueToTest) <= static_cast<unsigned int> (upperLimit);
  222. }
  223. //==============================================================================
  224. /** Handy function to swap two values. */
  225. template <typename Type>
  226. void swapVariables (Type& variable1, Type& variable2)
  227. {
  228. std::swap (variable1, variable2);
  229. }
  230. /** Handy function for avoiding unused variables warning. */
  231. template <typename Type1>
  232. void ignoreUnused (const Type1&) noexcept {}
  233. template <typename Type1, typename Type2>
  234. void ignoreUnused (const Type1&, const Type2&) noexcept {}
  235. template <typename Type1, typename Type2, typename Type3>
  236. void ignoreUnused (const Type1&, const Type2&, const Type3&) noexcept {}
  237. template <typename Type1, typename Type2, typename Type3, typename Type4>
  238. void ignoreUnused (const Type1&, const Type2&, const Type3&, const Type4&) noexcept {}
  239. /** Handy function for getting the number of elements in a simple const C array.
  240. E.g.
  241. @code
  242. static int myArray[] = { 1, 2, 3 };
  243. int numElements = numElementsInArray (myArray) // returns 3
  244. @endcode
  245. */
  246. template <typename Type, int N>
  247. int numElementsInArray (Type (&array)[N])
  248. {
  249. ignoreUnused (array);
  250. (void) sizeof (0[array]); // This line should cause an error if you pass an object with a user-defined subscript operator
  251. return N;
  252. }
  253. //==============================================================================
  254. // Some useful maths functions that aren't always present with all compilers and build settings.
  255. /** Using juce_hypot is easier than dealing with the different types of hypot function
  256. that are provided by the various platforms and compilers. */
  257. template <typename Type>
  258. Type juce_hypot (Type a, Type b) noexcept
  259. {
  260. #if JUCE_MSVC
  261. return static_cast<Type> (_hypot (a, b));
  262. #else
  263. return static_cast<Type> (hypot (a, b));
  264. #endif
  265. }
  266. #ifndef DOXYGEN
  267. template <>
  268. inline float juce_hypot (float a, float b) noexcept
  269. {
  270. #if JUCE_MSVC
  271. return _hypotf (a, b);
  272. #else
  273. return hypotf (a, b);
  274. #endif
  275. }
  276. #endif
  277. /** 64-bit abs function. */
  278. inline int64 abs64 (const int64 n) noexcept
  279. {
  280. return (n >= 0) ? n : -n;
  281. }
  282. #if JUCE_MSVC && ! defined (DOXYGEN) // The MSVC libraries omit these functions for some reason...
  283. template<typename Type> Type asinh (Type x) { return std::log (x + std::sqrt (x * x + (Type) 1)); }
  284. template<typename Type> Type acosh (Type x) { return std::log (x + std::sqrt (x * x - (Type) 1)); }
  285. template<typename Type> Type atanh (Type x) { return (std::log (x + (Type) 1) - std::log (((Type) 1) - x)) / (Type) 2; }
  286. #endif
  287. //==============================================================================
  288. /** A predefined value for Pi, at double-precision.
  289. @see float_Pi
  290. */
  291. const double double_Pi = 3.1415926535897932384626433832795;
  292. /** A predefined value for Pi, at single-precision.
  293. @see double_Pi
  294. */
  295. const float float_Pi = 3.14159265358979323846f;
  296. /** Converts an angle in degrees to radians. */
  297. inline float degreesToRadians (float degrees) noexcept { return degrees * (float_Pi / 180.0f); }
  298. /** Converts an angle in degrees to radians. */
  299. inline double degreesToRadians (double degrees) noexcept { return degrees * (double_Pi / 180.0); }
  300. /** Converts an angle in radians to degrees. */
  301. inline float radiansToDegrees (float radians) noexcept { return radians * (180.0f / float_Pi); }
  302. /** Converts an angle in radians to degrees. */
  303. inline double radiansToDegrees (double radians) noexcept { return radians * (180.0 / double_Pi); }
  304. //==============================================================================
  305. /** The isfinite() method seems to vary between platforms, so this is a
  306. platform-independent function for it.
  307. */
  308. template <typename NumericType>
  309. bool juce_isfinite (NumericType) noexcept
  310. {
  311. return true; // Integer types are always finite
  312. }
  313. template <>
  314. inline bool juce_isfinite (float value) noexcept
  315. {
  316. #if JUCE_WINDOWS && ! JUCE_MINGW
  317. return _finite (value) != 0;
  318. #else
  319. return std::isfinite (value);
  320. #endif
  321. }
  322. template <>
  323. inline bool juce_isfinite (double value) noexcept
  324. {
  325. #if JUCE_WINDOWS && ! JUCE_MINGW
  326. return _finite (value) != 0;
  327. #else
  328. return std::isfinite (value);
  329. #endif
  330. }
  331. //==============================================================================
  332. #if JUCE_MSVC
  333. #pragma optimize ("t", off)
  334. #ifndef __INTEL_COMPILER
  335. #pragma float_control (precise, on, push)
  336. #endif
  337. #endif
  338. /** Fast floating-point-to-integer conversion.
  339. This is faster than using the normal c++ cast to convert a float to an int, and
  340. it will round the value to the nearest integer, rather than rounding it down
  341. like the normal cast does.
  342. Note that this routine gets its speed at the expense of some accuracy, and when
  343. rounding values whose floating point component is exactly 0.5, odd numbers and
  344. even numbers will be rounded up or down differently.
  345. */
  346. template <typename FloatType>
  347. int roundToInt (const FloatType value) noexcept
  348. {
  349. #ifdef __INTEL_COMPILER
  350. #pragma float_control (precise, on, push)
  351. #endif
  352. union { int asInt[2]; double asDouble; } n;
  353. n.asDouble = ((double) value) + 6755399441055744.0;
  354. #if JUCE_BIG_ENDIAN
  355. return n.asInt [1];
  356. #else
  357. return n.asInt [0];
  358. #endif
  359. }
  360. inline int roundToInt (int value) noexcept
  361. {
  362. return value;
  363. }
  364. #if JUCE_MSVC
  365. #ifndef __INTEL_COMPILER
  366. #pragma float_control (pop)
  367. #endif
  368. #pragma optimize ("", on) // resets optimisations to the project defaults
  369. #endif
  370. /** Fast floating-point-to-integer conversion.
  371. This is a slightly slower and slightly more accurate version of roundDoubleToInt(). It works
  372. fine for values above zero, but negative numbers are rounded the wrong way.
  373. */
  374. inline int roundToIntAccurate (const double value) noexcept
  375. {
  376. #ifdef __INTEL_COMPILER
  377. #pragma float_control (pop)
  378. #endif
  379. return roundToInt (value + 1.5e-8);
  380. }
  381. /** Fast floating-point-to-integer conversion.
  382. This is faster than using the normal c++ cast to convert a double to an int, and
  383. it will round the value to the nearest integer, rather than rounding it down
  384. like the normal cast does.
  385. Note that this routine gets its speed at the expense of some accuracy, and when
  386. rounding values whose floating point component is exactly 0.5, odd numbers and
  387. even numbers will be rounded up or down differently. For a more accurate conversion,
  388. see roundDoubleToIntAccurate().
  389. */
  390. inline int roundDoubleToInt (const double value) noexcept
  391. {
  392. return roundToInt (value);
  393. }
  394. /** Fast floating-point-to-integer conversion.
  395. This is faster than using the normal c++ cast to convert a float to an int, and
  396. it will round the value to the nearest integer, rather than rounding it down
  397. like the normal cast does.
  398. Note that this routine gets its speed at the expense of some accuracy, and when
  399. rounding values whose floating point component is exactly 0.5, odd numbers and
  400. even numbers will be rounded up or down differently.
  401. */
  402. inline int roundFloatToInt (const float value) noexcept
  403. {
  404. return roundToInt (value);
  405. }
  406. //==============================================================================
  407. /** Returns true if the specified integer is a power-of-two. */
  408. template <typename IntegerType>
  409. bool isPowerOfTwo (IntegerType value)
  410. {
  411. return (value & (value - 1)) == 0;
  412. }
  413. /** Returns the smallest power-of-two which is equal to or greater than the given integer. */
  414. inline int nextPowerOfTwo (int n) noexcept
  415. {
  416. --n;
  417. n |= (n >> 1);
  418. n |= (n >> 2);
  419. n |= (n >> 4);
  420. n |= (n >> 8);
  421. n |= (n >> 16);
  422. return n + 1;
  423. }
  424. /** Returns the number of bits in a 32-bit integer. */
  425. inline int countNumberOfBits (uint32 n) noexcept
  426. {
  427. n -= ((n >> 1) & 0x55555555);
  428. n = (((n >> 2) & 0x33333333) + (n & 0x33333333));
  429. n = (((n >> 4) + n) & 0x0f0f0f0f);
  430. n += (n >> 8);
  431. n += (n >> 16);
  432. return (int) (n & 0x3f);
  433. }
  434. /** Returns the number of bits in a 64-bit integer. */
  435. inline int countNumberOfBits (uint64 n) noexcept
  436. {
  437. return countNumberOfBits ((uint32) n) + countNumberOfBits ((uint32) (n >> 32));
  438. }
  439. /** Performs a modulo operation, but can cope with the dividend being negative.
  440. The divisor must be greater than zero.
  441. */
  442. template <typename IntegerType>
  443. IntegerType negativeAwareModulo (IntegerType dividend, const IntegerType divisor) noexcept
  444. {
  445. jassert (divisor > 0);
  446. dividend %= divisor;
  447. return (dividend < 0) ? (dividend + divisor) : dividend;
  448. }
  449. /** Returns the square of its argument. */
  450. template <typename NumericType>
  451. NumericType square (NumericType n) noexcept
  452. {
  453. return n * n;
  454. }
  455. //==============================================================================
  456. /** Writes a number of bits into a memory buffer at a given bit index.
  457. The buffer is treated as a sequence of 8-bit bytes, and the value is encoded in little-endian order,
  458. so for example if startBit = 10, and numBits = 11 then the lower 6 bits of the value would be written
  459. into bits 2-8 of targetBuffer[1], and the upper 5 bits of value into bits 0-5 of targetBuffer[2].
  460. @see readLittleEndianBitsInBuffer
  461. */
  462. void writeLittleEndianBitsInBuffer (void* targetBuffer, uint32 startBit, uint32 numBits, uint32 value) noexcept;
  463. /** Reads a number of bits from a buffer at a given bit index.
  464. The buffer is treated as a sequence of 8-bit bytes, and the value is encoded in little-endian order,
  465. so for example if startBit = 10, and numBits = 11 then the lower 6 bits of the result would be read
  466. from bits 2-8 of sourceBuffer[1], and the upper 5 bits of the result from bits 0-5 of sourceBuffer[2].
  467. @see writeLittleEndianBitsInBuffer
  468. */
  469. uint32 readLittleEndianBitsInBuffer (const void* sourceBuffer, uint32 startBit, uint32 numBits) noexcept;
  470. //==============================================================================
  471. #if JUCE_INTEL || defined (DOXYGEN)
  472. /** This macro can be applied to a float variable to check whether it contains a denormalised
  473. value, and to normalise it if necessary.
  474. On CPUs that aren't vulnerable to denormalisation problems, this will have no effect.
  475. */
  476. #define JUCE_UNDENORMALISE(x) { (x) += 0.1f; (x) -= 0.1f; }
  477. #else
  478. #define JUCE_UNDENORMALISE(x)
  479. #endif
  480. //==============================================================================
  481. /** This namespace contains a few template classes for helping work out class type variations.
  482. */
  483. namespace TypeHelpers
  484. {
  485. #if JUCE_VC8_OR_EARLIER
  486. #define PARAMETER_TYPE(type) const type&
  487. #else
  488. /** The ParameterType struct is used to find the best type to use when passing some kind
  489. of object as a parameter.
  490. Of course, this is only likely to be useful in certain esoteric template situations.
  491. Because "typename TypeHelpers::ParameterType<SomeClass>::type" is a bit of a mouthful, there's
  492. a PARAMETER_TYPE(SomeClass) macro that you can use to get the same effect.
  493. E.g. "myFunction (PARAMETER_TYPE (int), PARAMETER_TYPE (MyObject))"
  494. would evaluate to "myfunction (int, const MyObject&)", keeping any primitive types as
  495. pass-by-value, but passing objects as a const reference, to avoid copying.
  496. */
  497. template <typename Type> struct ParameterType { typedef const Type& type; };
  498. #if ! DOXYGEN
  499. template <typename Type> struct ParameterType <Type&> { typedef Type& type; };
  500. template <typename Type> struct ParameterType <Type*> { typedef Type* type; };
  501. template <> struct ParameterType <char> { typedef char type; };
  502. template <> struct ParameterType <unsigned char> { typedef unsigned char type; };
  503. template <> struct ParameterType <short> { typedef short type; };
  504. template <> struct ParameterType <unsigned short> { typedef unsigned short type; };
  505. template <> struct ParameterType <int> { typedef int type; };
  506. template <> struct ParameterType <unsigned int> { typedef unsigned int type; };
  507. template <> struct ParameterType <long> { typedef long type; };
  508. template <> struct ParameterType <unsigned long> { typedef unsigned long type; };
  509. template <> struct ParameterType <int64> { typedef int64 type; };
  510. template <> struct ParameterType <uint64> { typedef uint64 type; };
  511. template <> struct ParameterType <bool> { typedef bool type; };
  512. template <> struct ParameterType <float> { typedef float type; };
  513. template <> struct ParameterType <double> { typedef double type; };
  514. #endif
  515. /** A helpful macro to simplify the use of the ParameterType template.
  516. @see ParameterType
  517. */
  518. #define PARAMETER_TYPE(a) typename TypeHelpers::ParameterType<a>::type
  519. #endif
  520. /** These templates are designed to take a type, and if it's a double, they return a double
  521. type; for anything else, they return a float type.
  522. */
  523. template <typename Type> struct SmallestFloatType { typedef float type; };
  524. template <> struct SmallestFloatType <double> { typedef double type; };
  525. }
  526. //==============================================================================
  527. #endif // JUCE_MATHSFUNCTIONS_H_INCLUDED