--- title: "95 - Arbitrary precision arithmetic" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{95 - Arbitrary precision arithmetic} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` ```{r, message=FALSE} library(caracas) ``` ```{r, include = FALSE} inline_code <- function(x) { x } if (!has_sympy()) { # SymPy not available, so the chunks shall not be evaluated knitr::opts_chunk$set(eval = FALSE) inline_code <- function(x) { deparse(substitute(x)) } } ``` ## An example ```{r} n_2 <- as_sym("2") n_pi <- as_sym("pi", declare_symbols = FALSE) # pi is a constant in SymPy x <- sqrt(n_2) * n_pi x N(x) N(x, 5) N(x, 50) as.character(N(x, 50)) ``` ## Another example As `SymPy` requires [`mpmath`](https://mpmath.org/) this can be used directly, for example like this (example due to Hans W Borchers, thanks!): ```{r} mpmath <- reticulate::import('mpmath') mpmath$mp$dps <- 30 z <- mpmath$mpc(real = '1.0', imag = '63.453') zeta_z <- mpmath$zeta(z) zeta_z as.character(zeta_z$real) as.character(zeta_z$imag) ```