[Rcpp-devel] Datetime substraction bug ?

Romain Francois romain at r-enthusiasts.com
Tue Apr 2 17:52:09 CEST 2013


Le 02/04/13 17:43, Robin Girard a écrit :
> I don't have any problem with Dirk's convention, and as Dirk said that should not create such a discussion (and it was not my intention to create one, just to point a problem I had if this can help others).

It obvisouly should not create a discussion like this, because it is 
trivial that the current implementation is non sense.

It should not create a discussion, it should just be "thanks for 
pointing it out, we fixed it".

operator-( left, right ) is supposed to implement left - right, not 
right - left. end of story.

> However I think that your example is designed to miss my point. My point was that the syntax for the use of operator "-" is NOT "-(c(1,3))" but "1-3" which makes the logical assertion "(1-3)>0" true.  This is not what I would call a usual convention.

yes. this is the convention

> Nothing more to say. Still in deep addictive love with Rcpp...

Cool.

> R.
>
>
> ----- Mail original -----
> De: "Patrick Burns" <patrick at burns-stat.com>
> À: rcpp-devel at lists.r-forge.r-project.org
> Envoyé: Mardi 2 Avril 2013 17:34:37
> Objet: Re: [Rcpp-devel] Datetime substraction bug ?
>
> In case Dirk is feeling lonely, I'll side with him.
>
> I think the ultimate issue is abstraction versus
> application.  In a purely abstract setting, then I
> agree that `-`(1, 3) should be negative.  But we
> don't have a purely abstract setting.  I agree with
> Dirk's New Year's/Easter example -- if the dates are
> in order, then the diff should be positive to my
> mind.
>
> Note also:
>
>   > diff(c(1, 3))
> [1] 2
>
> Pat
>
>
> On 02/04/2013 15:33, Romain Francois wrote:
>> Le 30/03/13 00:44, Dirk Eddelbuettel a écrit :
>>>
>>> On 29 March 2013 at 23:37, Robin Girard wrote:
>>> | Hi List
>>> |
>>> | why is it that we have in the Datetime definition
>>> | (here
>>> http://dirk.eddelbuettel.com/code/rcpp/html/Date_8cpp_source.html#l00271
>>> )
>>> |
>>> | double operator-(const Datetime& d1, const Datetime& d2) { return
>>> d2.m_dt - d1.m_dt; }
>>> | bool operator<(const Datetime &d1, const Datetime& d2) { return
>>> d1.m_dt < d2.m_dt; }
>>> |
>>> | I feel there is a contradiction
>>> | substraction shoulb be d1.m_dt - d2.m_dt;  no ?
>>>
>>> It's been a while since I wrote that and I think I followed the
>>> difftime()
>>> convention in R. Or maybe not.  To me d1 comes before d2 in the way the
>>> arguments are given, so d2 is larger and I want to subtract d1 from d2.
>>
>> Well. operator-(a, b) is supposed to implement a-b. See e.g. wikipedia
>> http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
>>
>> The current implementation does not make sense to me. So I second Robin
>> here.
>>
>>> In any event, if it bugs you greatly you are always free to write your
>>> own
>>> function. ;-)
>>>
>>> Dirk
>>
>> wtf. This is the same as saying 3-1 = -2
>>
>> And if i follow your logic, why is the operator< implemented this way
>> (correctly this time).
>>
>>> | Robin
>>> |
>>> | Dr. Girard Robin
>>> | Chargé de Recherche
>>> |
>>> | MINES-ParisTech / Département Energétique et Procédés / PERSEE /
>>> Groupe ERSEI
>>> | Centre Procédés, Energies Renouvelables et Systèmes Energétiques
>>> (PERSEE)
>>> | Center for Processes, Renewables Energies and Energy Systems
>>> | Renewable Energies & Smartgrids (ERSEI)
>>> |
>>> | 1 Rue Claude Daunesse - CS 10207 - F-06904 Sophia Antipolis Cedex
>>> | Tel: +33.4.93.67.89.64 (~99), Fax: +33.4.93.95.75.35
>>> | e-mail : robin.girard at mines-paristech.fr
>>> |
>>> | web page perso
>>> http://www.mines-paristech.fr/Services/Annuaire/&?id=8828
>>> | statoverflow : http://stats.stackexchange.com/users/223/robin-girard
>>> | web page centre PERSEE : http://www.cep.mines-paristech.fr/
>>> | linkedin : http://www.linkedin.com/profile/view?id=14907272&trk=tab_pro
>>> |
>>> | Le lien vaut mieux que le bien.
>>> | ________________________________________________________
>>> |
>>> | CONFIDENTIALITY : This  e-mail  and  any attachments are
>>> | confidential and may be privileged. If  you are not a
>>> | named recipient, please notify the sender immediately and
>>> | do not disclose the contents to another person, use it for
>>> | any purpose or store or copy the information in any medium.
>>> |
>>> | CONFIDENTIALITE : Ce message et les éventuelles pièces
>>> | attachées sontconfidentiels et peuvent être une
>>> | communication protégée. Si vous n'êtes pas dans la liste
>>> | des destinataires, veuillez informer l'expéditeur
>>> | immédiatement et ne pas ouvrir ni divulguer le contenu
>>> | à une tierce personne, ne pas l'utiliser pour quelque
>>> | raison que ce soit, ne pas stocker ou copier l'information
>>> | qu'il contient sur un quelconque support.
>>> |
>>> | _______________________________________________
>>> | Rcpp-devel mailing list
>>> | Rcpp-devel at lists.r-forge.r-project.org
>>> | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>>>
>>
>>
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com

blog:            http://blog.r-enthusiasts.com
|- http://bit.ly/ZTFLDo : Simpler R help tooltips
`- http://bit.ly/YFsziW : R Help tooltips



More information about the Rcpp-devel mailing list