26#ifndef WATER_MATHSFUNCTIONS_H_INCLUDED
27#define WATER_MATHSFUNCTIONS_H_INCLUDED
31#include "CarlaUtils.hpp"
47template <
typename Type>
48Type
jmax (
const Type
a,
const Type
b) {
return (
a <
b) ?
b :
a; }
51template <
typename Type>
52Type
jmax (
const Type
a,
const Type
b,
const Type
c) {
return (
a <
b) ? ((
b <
c) ?
c :
b) : ((
a <
c) ?
c :
a); }
55template <
typename Type>
59template <
typename Type>
60Type
jmin (
const Type
a,
const Type
b) {
return (
b <
a) ?
b :
a; }
63template <
typename Type>
64Type
jmin (
const Type
a,
const Type
b,
const Type
c) {
return (
b <
a) ? ((
c <
b) ?
c :
b) : ((
c <
a) ?
c :
a); }
67template <
typename Type>
73template <
typename Type>
74Type
jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)
76 return targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin);
80template <
typename Type>
81Type
jmap (Type sourceValue, Type sourceRangeMin, Type sourceRangeMax, Type targetRangeMin, Type targetRangeMax)
83 wassert (sourceRangeMax != sourceRangeMin);
84 return targetRangeMin + ((targetRangeMax - targetRangeMin) * (sourceValue - sourceRangeMin)) / (sourceRangeMax - sourceRangeMin);
88template <
typename Type>
96 while (--numValues > 0)
98 const Type&
v = *
data++;
106template <
typename Type>
114 while (--numValues > 0)
116 const Type&
v = *values++;
124template <
typename Type>
125void findMinAndMax (
const Type* values,
int numValues, Type& lowest, Type& highest)
137 while (--numValues > 0)
139 const Type&
v = *values++;
168template <
typename Type>
170 const Type upperLimit,
171 const Type valueToConstrain)
noexcept
176 return (valueToConstrain < lowerLimit) ? lowerLimit
177 : ((upperLimit < valueToConstrain) ? upperLimit
186template <
typename Type>
192 return Type() <= valueToTest && valueToTest < upperLimit;
201 return static_cast<unsigned int> (valueToTest) <
static_cast<unsigned int> (upperLimit);
209template <
typename Type>
215 return Type() <= valueToTest && valueToTest <= upperLimit;
224 return static_cast<unsigned int> (valueToTest) <=
static_cast<unsigned int> (upperLimit);
229template <
typename Type>
232 std::swap (variable1, variable2);
236template <
typename Type1>
239template <
typename Type1,
typename Type2>
242template <
typename Type1,
typename Type2,
typename Type3>
243void ignoreUnused (
const Type1&,
const Type2&,
const Type3&)
noexcept {}
245template <
typename Type1,
typename Type2,
typename Type3,
typename Type4>
246void ignoreUnused (
const Type1&,
const Type2&,
const Type3&,
const Type4&)
noexcept {}
256template <
typename Type,
size_t N>
260 (
void)
sizeof (0[array]);
269template <
typename Type>
272 return static_cast<Type
> (hypot (
a,
b));
278 return hypotf (
a,
b);
284 return (
n >= 0) ?
n : -
n;
291const double double_Pi = 3.1415926535897932384626433832795;
316template <
typename NumericType>
325 return std::isfinite (
value);
331 return std::isfinite (
value);
345template <
typename FloatType>
348 union {
int asInt[2];
double asDouble; }
n;
349 n.asDouble = ((double)
value) + 6755399441055744.0;
351 #if defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
406template <
typename IntegerType>
433 n -= ((
n >> 1) & 0x55555555);
434 n = (((
n >> 2) & 0x33333333) + (
n & 0x33333333));
435 n = (((
n >> 4) +
n) & 0x0f0f0f0f);
438 return (
int) (
n & 0x3f);
450template <
typename IntegerType>
455 return (dividend < 0) ? (dividend + divisor) : dividend;
459template <
typename NumericType>
#define CARLA_SAFE_ASSERT_RETURN(cond, ret)
Definition CarlaDefines.h:190
uint8_t a
Definition Spc_Cpu.h:141
unsigned v[N_MAX]
Definition inflate.c:1584
unsigned d
Definition inflate.c:940
static PuglViewHint int value
Definition pugl.h:1708
JSAMPIMAGE data
Definition jpeglib.h:945
#define wassert(expression)
Definition AudioSampleBuffer.h:33
unsigned int uint32
Definition water.h:98
IntegerType negativeAwareModulo(IntegerType dividend, const IntegerType divisor) noexcept
Definition MathsFunctions.h:451
bool isPositiveAndNotGreaterThan(Type valueToTest, Type upperLimit) noexcept
Definition MathsFunctions.h:210
int roundToInt(const FloatType value) noexcept
Definition MathsFunctions.h:346
void writeLittleEndianBitsInBuffer(void *targetBuffer, uint32 startBit, uint32 numBits, uint32 value) noexcept
const double double_Pi
Definition MathsFunctions.h:291
bool water_isfinite(NumericType) noexcept
Definition MathsFunctions.h:317
int roundToIntAccurate(double value) noexcept
Definition MathsFunctions.h:368
void findMinAndMax(const Type *values, int numValues, Type &lowest, Type &highest)
Definition MathsFunctions.h:125
Type jmin(const Type a, const Type b)
Definition MathsFunctions.h:60
float radiansToDegrees(float radians) noexcept
Definition MathsFunctions.h:306
unsigned long long uint64
Definition water.h:102
bool isPositiveAndBelow(Type valueToTest, Type upperLimit) noexcept
Definition MathsFunctions.h:187
Type jmap(Type value0To1, Type targetRangeMin, Type targetRangeMax)
Definition MathsFunctions.h:74
Type findMinimum(const Type *data, int numValues)
Definition MathsFunctions.h:89
int64 abs64(const int64 n) noexcept
Definition MathsFunctions.h:282
void swapVariables(Type &variable1, Type &variable2)
Definition MathsFunctions.h:230
void ignoreUnused(const Type1 &) noexcept
Definition MathsFunctions.h:237
int roundFloatToInt(float value) noexcept
Definition MathsFunctions.h:399
Type findMaximum(const Type *values, int numValues)
Definition MathsFunctions.h:107
float degreesToRadians(float degrees) noexcept
Definition MathsFunctions.h:300
long long int64
Definition water.h:100
uint32 readLittleEndianBitsInBuffer(const void *sourceBuffer, uint32 startBit, uint32 numBits) noexcept
bool isPowerOfTwo(IntegerType value)
Definition MathsFunctions.h:407
int findHighestSetBit(uint32 n) noexcept
int nextPowerOfTwo(int n) noexcept
Definition MathsFunctions.h:413
Type jmax(const Type a, const Type b)
Definition MathsFunctions.h:48
int countNumberOfBits(uint32 n) noexcept
Definition MathsFunctions.h:431
Type jlimit(const Type lowerLimit, const Type upperLimit, const Type valueToConstrain) noexcept
Definition MathsFunctions.h:169
Type water_hypot(Type a, Type b) noexcept
Definition MathsFunctions.h:270
size_t numElementsInArray(Type(&array)[N])
Definition MathsFunctions.h:257
const float float_Pi
Definition MathsFunctions.h:296
NumericType square(NumericType n) noexcept
Definition MathsFunctions.h:460
int roundDoubleToInt(double value) noexcept
Definition MathsFunctions.h:384
#define N
Definition nseel-cfunc.c:36
int n
Definition crypt.c:458
return c
Definition crypt.c:175
int result
Definition process.c:1455
#define void
Definition unzip.h:396