Am Montag, 9. Februar 2004 19:53 schrieb PUYDT Julien: > On lun, 2004-02-09 at 19:12, Stefan Bruens wrote: > > My piece of code: > > + if (width < (unsigned)orig_width) > > + scale_w = (double)width / orig_width; > > + else > > + scale_w = 1; > > The one lurchi proposes: > > + scale_w = (double)width / orig_width; > > Comment: I wanted to be sure to get exactly one in case > width==orig_width... I prefer the smaller version if it doesn't give > something stupid like 0.999999 ... This case is covered by if ((unsigned)orig_width <= width && (unsigned)orig_height <= height) If orig_x is greater than x, you will get a scale which is _really_ smaller than 1. The result of all the code fragments is exactly the same (as you are only interested in the value of scale, not scale_h nor scale_w). The second fragment is clearer in what it does, the third is the shortest. The second and the third should exactly result in the same code, the third only gives no name for the scale_h variable. Stefan PS: Even your version should result in the same code if you have a _really_ good compiler. -- Stefan Brüns / Kastanienweg 6 - Zimmer 1206 / 52074 Aachen mailto:lurch gmx li http://www.kawo1.rwth-aachen.de/~lurchi/ phone: +49 241 169-4206 mobile: +49 160 7532733
Attachment:
pgpSQAA7dpLI7.pgp
Description: signature