3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2016 Christian Schoenebeck * |
* Copyright (C) 2005 - 2019 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
107 |
#endif |
#endif |
108 |
} |
} |
109 |
|
|
110 |
|
bool RTMathBase::fEqual32(float a, float b) { |
111 |
|
if (isinf(a) || isinf(b)) |
112 |
|
return isinf(a) == isinf(b); |
113 |
|
if (isnan(a) || isnan(b)) |
114 |
|
return isnan(a) == isnan(b); |
115 |
|
|
116 |
|
const int bits = 23 /* float32 type fraction bits */ - 4 /* arbitrarily reduced bit tolerance */; |
117 |
|
|
118 |
|
if (a == 0.f) |
119 |
|
return fabs(b) < (1.0 / pow(2, bits)); |
120 |
|
if (b == 0.f) |
121 |
|
return fabs(a) < (1.0 / pow(2, bits)); |
122 |
|
|
123 |
|
const double epsilon = fabs(a / pow(2.0, bits)); |
124 |
|
return fabs(b - a) <= epsilon; |
125 |
|
} |
126 |
|
|
127 |
|
bool RTMathBase::fEqual64(double a, double b) { |
128 |
|
if (isinf(a) || isinf(b)) |
129 |
|
return isinf(a) == isinf(b); |
130 |
|
if (isnan(a) || isnan(b)) |
131 |
|
return isnan(a) == isnan(b); |
132 |
|
|
133 |
|
const int bits = 52 /* float64 type fraction bits */ - 4 /* arbitrarily reduced bit tolerance */; |
134 |
|
|
135 |
|
if (a == 0.f) |
136 |
|
return fabs(b) < (1.0 / pow(2, bits)); |
137 |
|
if (b == 0.f) |
138 |
|
return fabs(a) < (1.0 / pow(2, bits)); |
139 |
|
|
140 |
|
const double epsilon = fabs(a / pow(2.0, bits)); |
141 |
|
return fabs(b - a) <= epsilon; |
142 |
|
} |
143 |
|
|
144 |
/** |
/** |
145 |
* Will automatically be called once to initialize the 'Cents to frequency |
* Will automatically be called once to initialize the 'Cents to frequency |
146 |
* ratio' table. |
* ratio' table. |