Re: a simple arithmetic(?)

From: Ingo Strauch (strauch@toots.physik.rwth-aachen.de)
Date: Tue Feb 22 2000 - 13:10:08 MET


Rene Brun wrote:
> 
> This is the expected result.
> Replace
> a = (Double_t)((b-c)/b)
> by
> a = (Double_t)(b-c)/b

Maybe you should explain...

(Double_t)((b-c)/b) means: convert the result of the calculation (b-c)/b to
double.
But since b and c are both integers, the result will be integer too. And since
b-c is less than b the outcome is zero. An integer zero of course will be
transformed to a double zero.
But when you covert b-c to double BEFORE the division, the result will be a
double. Now you have a double (b-c) mixed with an integer (b), in such a case
the result will always be of the more precise type.

Ingo Strauch

----------------------------------------------------------------------------
Ingo Strauch       Budapester Str. 30, 20359 Hamburg, Tel.: +49 40 7421 4722
Office:         DESY, Group H1/AAC1, Room 1c354, Notkestr. 85, 22607 Hamburg
                strauch@mail.desy.de                   Tel. +49 40 8998 2312
http://www-h1.desy.de/~strauch/                        FAX  +49 40 8998 4385
 I. Phys. Institut RWTH Aachen, Room 28B210, Sommerfeldstr. 14, 52056 Aachen
 strauch@toots.physik.rwth-aachen.de                    Tel. +49 241 80 7183
http://www-users.rwth-aachen.de/Ingo.Strauch/          FAX. +49 241 8888 661
----------------------------------------------------------------------------



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:19 MET