Commit 88240f88 authored by Jonas Stienen's avatar Jonas Stienen

Substituting minus infinity with numeric_limits infinity() for float and double

parent 4510d825
......@@ -51,15 +51,6 @@ namespace ITAConstants
// Epsilon (distance quantization)
static float EPS_F_L = 1.0e-5f; // 10 micro meter
static double EPS_D_L = 1.0e-5f; // 10 micro meter
// Symbolische Konstante für den Verstärkungsfaktor -oo dB
/* TODO: Dies ist hardgecodet eine verdammt große Double-Zahl.
Laut Internet ist die größte negative Zahl -1.79769313486231570 x 10^308.
Am besten wäre hier eine symbolische Minus-Unendlich.
Da muss noch geprüft werden, ob sich so etwas mit double
realisieren lässt [fwe]. */
const double DECIBEL_MINUS_INFINITY = -1.5E-308;
};
#endif // INCLUDE_WATCHER_ITA_CONSTANTS
This diff is collapsed.
......@@ -3,6 +3,8 @@
#include <ITAConstants.h>
#include <ITAException.h>
#include <numeric>
using namespace ITAConstants;
int getExp2(unsigned int x) {
......@@ -117,26 +119,34 @@ float correctAngle360(float phi) {
return fmodf(phi, 360.0f);
}
double db10_to_ratio(double db) {
return (db == DECIBEL_MINUS_INFINITY ? 0 : pow(10, db/10.0));
double db10_to_ratio( const double db )
{
return ( db == -std::numeric_limits< double >::infinity() ? 0.0f : pow( 10.0f, db / 10.0f ) );
}
double ratio_to_db10(double r) {
if (r < 0) ITA_EXCEPT0(INVALID_PARAMETER);
return (r == 0 ? DECIBEL_MINUS_INFINITY : 10*log10(r));
double db20_to_ratio( const double db )
{
return ( db == -std::numeric_limits< double >::infinity() ? 0.0f : pow( 10.0f, db / 20.0f ) );
}
double db20_to_ratio(double db) {
return (db == DECIBEL_MINUS_INFINITY ? 0 : pow(10, db/20.0));
double ratio_to_db10( const double r )
{
if( r < 0.0f )
ITA_EXCEPT1( INVALID_PARAMETER, "Conversion to decibel not possible for negative values" );
if( r == 0.0f )
return -std::numeric_limits< double >::infinity();
else
return 10.0f * log10( r );
}
double ratio_to_db20( double r )
double ratio_to_db20( const double r )
{
if( r < 0.0f )
ITA_EXCEPT1( INVALID_PARAMETER, "Conversion to decibel not possible for negative values" );
if( r == 0.0f )
return DECIBEL_MINUS_INFINITY;
return -std::numeric_limits< double >::infinity();
else
return 20.0f * log10( r );
}
......
This diff is collapsed.
......@@ -50,10 +50,20 @@ void test_ratio_to_db()
CITAThirdOctaveMagnitudeSpectrum oTOSpectrumConvertToRatio;
oTOSpectrumConvertToRatio.SetName( "Test unit gain spectrum to db" );
oTOSpectrumConvertToRatio.SetValueUnit( "(gain)" );
oTOSpectrumConvertToRatio.SetZero();
oTOSpectrumConvertToRatio.SetIdentity(); // db -> all zeros
for( int n = 0; n < oTOSpectrumConvertToRatio.GetNumBands(); n++ )
oTOSpectrumConvertToRatio[ n ] = ratio_to_db10( oTOSpectrumConvertToRatio[ n ] ); // zero to db -> -inf
oTOSpectrumConvertToRatio.SetValueUnit( "dB" );
cout << oTOSpectrumConvertToRatio << endl;
// Convert gains "1"
oTOSpectrumConvertToRatio.SetIdentity(); // db -> all zeros
oTOSpectrumConvertToRatio.Add( 1.0f ); // gains now all 1.0
for( int n = 0; n < oTOSpectrumConvertToRatio.GetNumBands(); n++ )
oTOSpectrumConvertToRatio[ n ] = ratio_to_db10( oTOSpectrumConvertToRatio[ n ] );
oTOSpectrumConvertToRatio[ n ] = ratio_to_db10( oTOSpectrumConvertToRatio[ n ] ); // ratio 1 to db -> 0
oTOSpectrumConvertToRatio.SetValueUnit( "dB" );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment