Code: Select all
#include <iostream>
#include <iomanip>
#include <cmath>
int main()
{
// Set precision to std::cout's output
std::cout << std::setprecision (8);
float minus6dbFS = -6.0205999f;
float a = powf(10.f, minus6dbFS / 20.f);
std::cout << minus6dbFS << " dbFS is represented as a factor of " << a << std::endl;
float plus6dbFS = 6.0205999f;
float b = powf(10.f, plus6dbFS / 20.f);
std::cout << plus6dbFS << " dbFS is represented as a factor of " << b << std::endl;
float assumedUnity = a * b;
std::cout << "Multiplying both yields " << assumedUnity << std::endl;
float assumedUnityAsDbFS = 20.f * log10(assumedUnity);
std::cout << "This is " << assumedUnityAsDbFS << " dbFS shy of the expected 1.0f" << std::endl;
}
Code: Select all
-6.0205998 dbFS is represented as a factor of 0.5
6.0205998 dbFS is represented as a factor of 1.9999999
Multiplying both yields 0.99999994
This is -5.177194e-07 dbFS shy of the expected 1.0f
