Hi, I want to use a more accurate value of exp(1). The value given by R is 2.718282. I want a value which has more than 15 decimal places. Can anyone let me know how can I increase the accuracy level. Actually there are some large multipliers of exp(1) in my whole expression, and I want a more accurate result at the last step of my program, and for that I need to use highly accurate value of exp(1). Can anyone help me out? Thanks. Shant [[alternative HTML version deleted]]
On 09/11/2010 8:21 AM, Shant Ch wrote:> Hi, > > I want to use a more accurate value of exp(1). The value given by R is > 2.718282. I want a value which has more than 15 decimal places. Can anyone let > me know how can I increase the accuracy level.The value in R is accurate to approximately 15 decimal places; it only prints to 6 by default.> Actually there are some large multipliers of exp(1) in my whole expression, and > I want a more accurate result at the last step of my program, and for that I > need to use highly accurate value of exp(1).It's really unlikely that this would help. Most computations in R are done in double precision, so having one constant at higher precision won't affect much. You could replace all computation with higher precision by using the gmp package, but it's not a painless procedure, and it would cut you off from code in most packages. I think you probably want to re-think the computation you're doing to figure out how to do it with 15 digit arithmetic. Have you looked at the expm1() and related functions? Duncan Murdoch> Can anyone help me out? Thanks. > > Shant > > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On Nov 9, 2010, at 8:21 AM, Shant Ch wrote:> Hi, > > I want to use a more accurate value of exp(1). The value given by R > is > 2.718282.Well, not really. That is what is printed at the console with the default settings for digits. The internal representation is wider: > format(exp(1), digits=15) [1] "2.71828182845905"> I want a value which has more than 15 decimal places. Can anyone let > me know how can I increase the accuracy level.You already have it.> > Actually there are some large multipliers of exp(1) in my whole > expression, and > I want a more accurate result at the last step of my program, and > for that I > need to use highly accurate value of exp(1). > > Can anyone help me out? Thanks. > > ShantDavid Winsemius, MD West Hartford, CT
On 09-Nov-10 13:21:10, Shant Ch wrote:> Hi, > I want to use a more accurate value of exp(1)._ The value given > by R is 2.718282. I want a value which has more than 15 decimal > places. Can anyone let me know how can I increase the accuracy level. > > Actually there are some large multipliers of exp(1) in my whole > expression, and I want a more accurate result at the last step > of my program, and for that I need to use highly accurate value > of exp(1). > > Can anyone help me out? Thanks. > ShantWhere the value of exp(1) as computed by R is concerned, you have been deceived by what R displays ("prints") on screen. The default is to display any number to 7 digits of accuracy, but that is not the accuracy of the number held internally by R: exp(1) # [1] 2.718282 exp(1) - 2.718282 # [1] -1.715410e-07 You can get a particular result to be displayed to greater accuracy by using print(..., digits=...) (and the "digits" argument is the one in second position, so you don;t necessarily need to use "digits=". Therefore: print(exp(1),17) # [1] 2.718281828459045 (and you will not get greater precision by using more digits, e.g. 18,19,...). print(exp(1)-2.718281828459045,19) [1] 0 So 2.718281828459045 is the greatest accuracy you can get with normal 32-bit R. This is the value which will be computed by R for any instance of exp(1), and which will be stored as the value of Y in: Y <- exp(1) If you want to see all computed results displayed to more than 7 digits of accuracy, you can set the global "digits" option: options(digits=17) exp(1) # [1] 2.718281828459045 pi # [1] 3.141592653589793 See the entry for "digits" in ?options. Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at wlandres.net> Fax-to-email: +44 (0)870 094 0861 Date: 09-Nov-10 Time: 13:42:17 ------------------------------ XFMail ------------------------------
> Where the value of exp(1) as computed by R is concerned, you have > been deceived by what R displays ("prints") on screen. The default > is to display any number to 7 digits of accuracy, but that is not > the accuracy of the number held internally by R: > > ?exp(1) > ?# [1] 2.718282 > ?exp(1) - 2.718282 > ?# [1] -1.715410e-07I encourage anyone confused about this issue to study http://en.wikipedia.org/wiki/The_Treachery_of_Images And to watch http://www.youtube.com/watch?v=ejweI0EQpX8 Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/
2010/11/9 Shant Ch <sha1one@yahoo.com>> Can anyone let > me know how can I increase the accuracy level. >library(Rmpfr)> exp(mpfr(1,128))1 'mpfr' number of precision 128 bits [1] 2.718281828459045235360287471352662497759 -- Mi³ego dnia [[alternative HTML version deleted]]
On 09-Nov-10 13:57:08, Hadley Wickham wrote:>> Where the value of exp(1) as computed by R is concerned, you have >> been deceived by what R displays ("prints") on screen. The default >> is to display any number to 7 digits of accuracy, but that is not >> the accuracy of the number held internally by R: >> >> _exp(1) >> _# [1] 2.718282 >> _exp(1) - 2.718282 >> _# [1] -1.715410e-07 > > I encourage anyone confused about this issue to study > http://en.wikipedia.org/wiki/The_Treachery_of_Images > > And to watch > http://www.youtube.com/watch?v=ejweI0EQpX8 > > Hadley"YES"! And to really clinch the point, have a look at: http://www.preventblindness.org/playitsafe/ teachers_guide_grade3_grade4/paradoxelephant.jpg and perhaps also my own composition at: http://www.zen89632.zen.co.uk/Misc/multinecker.pdf What you *see* in treacherous (or any) images is marks on paper, or on a computer screen, ... What you *perceive* is different. Always. (Well, almost always: you can make a deliberate effort to study the marks on the paper as marks on paper). Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at wlandres.net> Fax-to-email: +44 (0)870 094 0861 Date: 09-Nov-10 Time: 14:57:31 ------------------------------ XFMail ------------------------------