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