rational solution in R [Software]

posted by mittyri – Russia, 2020-12-21 14:49 (1220 d 14:35 ago) – Posting: # 22152
Views: 8,514

Hi Helmut,

❝ At least consistently giving not zero. ;-)

library(Rmpfr)

❝ prec <- 64

❝ x <- mpfr(0.5, prec) - mpfr(0.4, prec) - mpfr(0.1, prec)

❝ x

1 'mpfr' number of precision  64   bits

❝ [1] -2.77555756156289135106e-17

❝ y <- mpfr(-0.4, prec) - mpfr(0.1, prec) + mpfr(0.5, prec)

❝ y

1 'mpfr' number of precision  64   bits

❝ [1] -2.77555756156289135106e-17



I think the right solution is
install.packages("remotes")
remotes::install_github("bertcarnell/rational")
library(rational)
(rational(5L, 10L) - rational(4L, 10L) - rational(1L, 10L)) == 0
[1] TRUE


Interestingly but I did not find good solution using CRAN

Kind regards,
Mittyri

Complete thread:

UA Flag
Activity
 Admin contact
22,993 posts in 4,828 threads, 1,656 registered users;
109 visitors (0 registered, 109 guests [including 3 identified bots]).
Forum time: 06:25 CEST (Europe/Vienna)

Never never never never use Excel.
Not even for calculation of arithmetic means.    Martin Wolfsegger

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5