rational solution in R [Software]

posted by mittyri – Russia, 2020-12-21 12:49 (33 d 23:00 ago) – Posting: # 22152
Views: 592

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:

Activity
 Admin contact
21,310 posts in 4,445 threads, 1,489 registered users;
online 2 (0 registered, 2 guests [including 2 identified bots]).
Forum time: Sunday 11:50 UTC (Europe/Vienna)

Every man gets a narrower and narrower field of knowledge
in which he must be an expert in order to compete with other people.
The specialist knows more and more about less and less
and finally knows everything about nothing.    Konrad Lorenz

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