/*
Outputting the number of decimal significant figures supported by each floating point type in C++.
Author: Peter R. Bloomfield.
Web: avidinsight.uk
*/
#include <iostream>
#include <limits>
#include <cmath>
using namespace std;
template <typename T_ty>
void test()
{
int radix = numeric_limits<T_ty>::radix;
int mantissa = numeric_limits<T_ty>::digits;
int figures = static_cast<int>( std::ceil(
mantissa * std::log(radix) / std::log(10.0)
));
cout << " Mantissa contains " << mantissa << " base " << radix << " digits" << endl;
cout << " Significant decimal figures = " << figures << endl;
cout << endl;
}
int main() {
cout << "float:" << endl;
test<float>();
cout << "double:" << endl;
test<double>();
cout << "long double:" << endl;
test<long double>();
return 0;
}
LyoKT3V0cHV0dGluZyB0aGUgbnVtYmVyIG9mIGRlY2ltYWwgc2lnbmlmaWNhbnQgZmlndXJlcyBzdXBwb3J0ZWQgYnkgZWFjaCBmbG9hdGluZyBwb2ludCB0eXBlIGluIEMrKy4KQXV0aG9yOiBQZXRlciBSLiBCbG9vbWZpZWxkLgpXZWI6IGF2aWRpbnNpZ2h0LnVrCiovCgojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxsaW1pdHM+CiNpbmNsdWRlIDxjbWF0aD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlIDx0eXBlbmFtZSBUX3R5Pgp2b2lkIHRlc3QoKQp7CglpbnQgcmFkaXggPSBudW1lcmljX2xpbWl0czxUX3R5Pjo6cmFkaXg7CglpbnQgbWFudGlzc2EgPSBudW1lcmljX2xpbWl0czxUX3R5Pjo6ZGlnaXRzOwoJaW50IGZpZ3VyZXMgPSBzdGF0aWNfY2FzdDxpbnQ+KCBzdGQ6OmNlaWwoCgkJbWFudGlzc2EgKiBzdGQ6OmxvZyhyYWRpeCkgLyBzdGQ6OmxvZygxMC4wKQoJKSk7CgkKCWNvdXQgPDwgIiBNYW50aXNzYSBjb250YWlucyAiIDw8IG1hbnRpc3NhIDw8ICIgYmFzZSAiIDw8IHJhZGl4IDw8ICIgZGlnaXRzIi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