From ruipb@rr@d@@ @ending from @@po@pt  Mon Sep  3 10:58:34 2018
From: ruipb@rr@d@@ @ending from @@po@pt (Rui Barradas)
Date: Mon, 3 Sep 2018 09:58:34 +0100
Subject: [Rd] compairing doubles
In-Reply-To: <CAJXDcw3CJsDoLN_=_jf7Ud554Cm6DikHOhwQLWw9aUOycuuy5A@mail.gmail.com>
References: <AM0PR0502MB387404BC690F9AF421B6F5EAD6080@AM0PR0502MB3874.eurprd05.prod.outlook.com>
 <CALEXWq3wSS4uaYu33oA-KUu7gSBuqKYF0ESemwvsbmp6KktOJg@mail.gmail.com>
 <95F39593-22F4-46B6-A766-8FF60F608C0C@dans.knaw.nl>
 <CAOKDuOgykFYMA-ZT4kUxr_NKXBEBsxZV8s-3sAuQ3Motc5M_Fw@mail.gmail.com>
 <CALEXWq2ke081QLqbv89z=yfTuoocLw9dzQWx6-05gzSFqAD3vQ@mail.gmail.com>
 <CAOKDuOg5bA0Uf5bmQX_9ZP6qbnO=hewb7cVbjEEZEvu5KOGC5w@mail.gmail.com>
 <e275b09d-39c8-a7e2-fc11-30c00034d1e4@insa-toulouse.fr>
 <CALEXWq3hNdLZwf9v=YZNTJ1FjTJfN6xuuUeSZ-zyZq1Sp+8yKA@mail.gmail.com>
 <CAJXDcw3CJsDoLN_=_jf7Ud554Cm6DikHOhwQLWw9aUOycuuy5A@mail.gmail.com>
Message-ID: <d89880dd-5cdd-6fc8-0716-6c036507eb9c@sapo.pt>

Hello,

Watch out for operator precedence.



all.equal(0.3, 0.1*3)
#[1] TRUE


`%~~%` <- function (e1, e2)  all.equal(e1, e2)

0.3 %~~% 0.1*3
#Error in 0.3 %~~% 0.1 * 3 : argumento n?o-num?rico para operador bin?rio


0.3 %~~% (0.1*3)
#[1] TRUE


Now with isTRUE. The problem changes a bit.


isTRUE(all.equal(0.3, 0.1*3))
#[1] TRUE


`%~~%` <- function (e1, e2)  isTRUE(all.equal(e1, e2))

0.3 %~~% 0.1*3
#[1] 0

0.3 %~~% (0.1*3)
#[1] TRUE


Hope this helps,

Rui Barradas

?s 08:20 de 03/09/2018, Juan Telleria Ruiz de Aguirre escreveu:
> Maybe a new Operator could be defined for a fast and easy double
> Comparison: `~~`
> 
> `~~` <- function (e1, e2)  all.equal(e1, e2)
> 
> And document it properly.
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] compairing doubles
Rui Barradas