Re: [ROOT] Sin(150/100)??

From: cstrato (aon.912121399@aon.at)
Date: Thu Aug 21 2003 - 22:52:05 MEST


Dear Justin

Thank you for this extensive explanation.
I forgot that C was not intended to be a high level language but 
something like a macro-assembler.
BTW, around the same time N. Wirth has developed Pascal, which has its 
own operator for integer division, e.g. i := 150 div 100.

Best regards
Christian

Justin Findlay wrote:

>Hi Christian,
>
>In C++ the binary mathematical operators, +, -, *, and /, are defined for
>builtin types, int, double, etc., so that a statement of a binary
>operation involving two values of the same type will return an instance of
>that same type even if the mathematically correct result can only be
>stored by another type.  If you divide one integer by another integer the
>return value will be an integer.
>
>int i;
>i = 150 / 100; // result, 1.5, is truncated at the decimal point, so i = 1 
>TMath::Sin( i ); // sin( 1 )
>
>If you have different types in a binary expression, then the "lesser" type 
>is implicitly "promoted" so that the same-type rule mentioned above is 
>always obeyed.
>
>double i;
>c = 150.0 / 100; // same as 150.0 / static_cast<double>( 100 )
>TMath::Sin( i );
>
>
>Justin
>
>On Thu, 21 Aug 2003, cstrato wrote:
>
>  
>
>>Dear Rooters
>>
>>By chance I came across the following problem:
>>root [13] TMath::Sin(100/100)
>>(Double_t)8.41470984807896505e-01
>>root [14] TMath::Sin(150/100)
>>(Double_t)8.41470984807896505e-01
>>root [15] TMath::Sin(1)      
>>(Double_t)8.41470984807896505e-01
>>root [16] TMath::Sin(1.5)
>>(Double_t)9.97494986604054446e-01
>>root [23] TMath::Sin(150.0/100)
>>(Double_t)9.97494986604054446e-01
>>
>>Although 150 and 100 are integers, 150/100 should be
>>recognized as real.
>>
>>(I am using root 3.10/00 for MacOS X)
>>
>>Best regards
>>Christian
>>_._._._._._._._._._._._._._._._
>>C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a
>>V.i.e.n.n.a       A.u.s.t.r.i.a
>>_._._._._._._._._._._._._._._._
>>
>>
>>
>>    
>>
>
>
>
>
>  
>



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:15 MET