vignettes/a95-arbitrary-precision-arithmetic.Rmd
a95-arbitrary-precision-arithmetic.Rmd
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
#> c: √2⋅π
N(x)
#> c: 4.44288293815837
N(x, 5)
#> c: 4.4429
N(x, 50)
#> c: 4.4428829381583662470158809900606936986146216893757
as.character(N(x, 50))
#> [1] "4.4428829381583662470158809900606936986146216893757"
As SymPy
requires mpmath
this can be used
directly, for example like this (example due to Hans W Borchers,
thanks!):
mpmath <- reticulate::import('mpmath')
mpmath$mp$dps <- 30
z <- mpmath$mpc(real = '1.0', imag = '63.453')
zeta_z <- mpmath$zeta(z)
zeta_z
#> mpc(real='2.34546406268004345885821002260475', imag='-0.641476965582898402371607967235787')
as.character(zeta_z$real)
#> [1] "2.3454640626800434588582100226"
as.character(zeta_z$imag)
#> [1] "-0.641476965582898402371607967236"