3

So I'm doing taylor expansion for exp(11.2). When I print all terms, I find some terms have 15 digits but some have 17 digits. I wonder why is that happening?

Yunwei Lu
  • 31
  • 1
  • From https://en.wikipedia.org/wiki/Double-precision_floating-point_format : "The 53-bit significand precision gives from 15 to 17 significant decimal digits precision (2−53 ≈ 1.11 × 10−16)." I think, but am not sure, that the exact precision depends on the number's value, hence the 15-17 decimal place variation. If you find this sort of thing interesting, check out Bruce Dawson's blog, https://randomascii.wordpress.com/ – Rory Yorke Nov 09 '21 at 17:56
  • 3
    Assuming that your coefficients are NumPy `np.float64` objects, it's because NumPy (since version 1.14.0) prints the shortest decimal representation that converts back to the original float under normal round-ties-to-even rounding. See release notes here: https://numpy.org/doc/stable/release/1.14.0-notes.html#many-changes-to-array-printing-disableable-with-the-new-legacy-printing-mode. It can be shown that (assuming IEEE 754 binary64 format), 17 digits are always enough to recover the value exactly, but sometimes you can get away with fewer. – Mark Dickinson Nov 09 '21 at 18:04
  • This answer may help: https://stackoverflow.com/a/55727933/270986 – Mark Dickinson Nov 09 '21 at 18:08
  • It has [53 significant _binary_ digits](https://en.wikipedia.org/wiki/Double-precision_floating-point_format#IEEE_754_double-precision_binary_floating-point_format:_binary64). That manifests itself as 15 to 17 _decimal_ digits. When printing, best to print to 17 significant digits to distinguish possible results. – chux - Reinstate Monica Nov 09 '21 at 20:54

0 Answers0