c - Defining floating point constants, how many digits are useful? -


when define constants in c cannot accurately represented in decimal system, example π, how many digits taken account compiler creating float or double in memory?

for example:

/* overkill? */ const float pi_f = 3.1415926535897932384626433832795f;  /* few digits? */ const double pi_d = 3.14159; 

assuming ieee 754 standard floating point numbers, commonplace nowadays, 7.22 digits of accuracy float , 15.95 double, aim 7 digits after decimal point float π constant , 15 double on safe side. 128-bit long double gives 34.02 precision, 33 positions after decimal point in π.(*)

however, excess precision won't hurt, compiler cut off.

(*) note long double quite not ieee format; x86-32 typically has 80-bit, not 128-bit, long double. in msvc, it's apparently synonym double, 64-bit.


Comments

Popular posts from this blog

c++ - list<myClass<int> * > sort -

C# Apple Bonjour - how to monitor service records within Windows -