In half-precision, values are rounded to 11 significant bits.
In single-precision, values are rounded to 24 significant bits.
In double-precision, values are rounded to 53 significant bits.
In extended-precision, values are rounded to 64 significant bits.
In quadruple-precision, values are rounded to 113 significant bits.
The rounding rule used most often in practice is round-to-nearest, round-half-to-even; that’s the rule I will use. For pi and e, there are no “half to even” cases, since their binary expansions are infinite. This makes the rounding rule simple: if the rounding bit is 0, round down; if the rounding bit is 1, round up.
I will show the correctly rounded approximations of pi and e in these five formats.
This equals 3.140625 in decimal (all binary floating-point numbers have exact decimal representations), which approximates pi accurately to about 4 decimal digits.
This equals 3.1415927410125732421875, which approximates pi accurately to about 8 decimal digits.
This equals 3.141592653589793115997963468544185161590576171875, which approximates pi accurately to about 16 decimal digits.
which approximates pi accurately to about 20 decimal digits.
which approximates pi accurately to about 35 decimal digits.
This equals 2.71875, which approximates e accurately to about 4 decimal digits.
This equals 2.71828174591064453125, which approximates e accurately to about 8 decimal digits.
This equals 2.718281828459045090795598298427648842334747314453125, which approximates e accurately to about 16 decimal digits.
which approximates e accurately to about 20 decimal digits.
which approximates e accurately to about 34 decimal digits.
I wanted to add a new perspective following the publishing of my articles “Number of Digits Required For Round-Trip Conversions” and “Decimal Precision of Binary Floating-Point Numbers”.
The four that changed all have one less digit of precision than I had stated.
You can see that some of the conversions of pi and e are more accurate than their segment allows. For example, the single-precision value of pi is accurate to 8 digits, but only 7 digits of precision are provided in the segment in which it resides. I call this coincidental precision. pi’s proximity to a floating-point number — along with some beneficial rounding — makes its precision look greater than that for numbers in its segment in general.
this is pretty pointless…why does it matter how to convert to different floating point precisions?
This article was a response to regular searches on my site for “pi in binary” and “e in binary”. My approach was to show how they look in binary in a computer, in IEEE floating-point in particular. This allowed me to give examples of correct rounding and to show how different levels of binary precision correspond to different levels of decimal precision. And as a side effect, I’ve given hex constants that can be copied and used in code that requires correctly rounded values of these constants.
how to calculate e in binary ? If we don’t use its decimal digit and then, converting to binary.
If I understand your question, just use a formula that calculates e. Any constants in the formula will be automatically converted to binary, and of course calculations will be done in binary.
reply to Anonymous: it might be pointless to someone not having any idea what is truly behind the floating point numbers representation and what effect it has on the correct calculations. To find out one must do tests for different precisions (single, double, quad). The author made it easier to find out Pi end e down to the last bit for each precision mode rather then for one to reinvent the hot water. I really admire him. He put it so much effort into the article. People like him make a difference.
Pointless? How about it is fun to know and examine.
I first learned binary/quinary numeral systems when I was bored by 4th grade schooling. So I joined the Early bird, science club and went to the library a lot to get it right. Since then I have taught many children as well older people, some could barely read but I was teaching them binary with ease and they still show me they kept learning later and used it in daily life to count instead of our base 10. I Teach mime, knife throwing and martial arts but am intrigued by numbers still and I just turned 70. I continue to search for ways to use binary etc. to ameliorate my life in ways I have not discovered but feel close to something great and fun if not user friendly. I am an explorer and like scientific forms of getting to an answer that is correct. Just want to compliment your approach to teaching. I always use my fingers to teach as there may not be objects or pen and pad to write where I have been. Thank you again, Bernie Bang, Mime.
Finite precision constraints leads to rounding errors. A better understanding of the floating point representation can help avoid pitfalls like comparing floating point numbers or properly ordering floating point operations. What is presented here is a nice reference for defining constants with the correct precision for the primitive type container.
Nothing is useless; people just want others to do the work for them and when it’s not what they expected they have a tantrum.
Like a full page of: 11.1,100,1,101,1001 etc, is what I was hoping for so I could see the distinction in each decimal digit, but I’m sure someone else would have been equally displeased with that lol. No worries. Take care, bro and don’t sweat the small stuff.
I believe combining einsteins theory, laws of thermodynamics, binary code will lead us to a true form of A.I. I do not think we can create true A.I. Because no matter how random we try to make any computational system at it’s very basic level it still must be programmed by us humans. True inspiration I do not believe is still understood or able to be mathematically represented yet.