delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/29/06:45:30

From: "A. Sinan Unur" <sinan DOT unur AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: djgpp/rhide acting strange
Date: Wed, 28 Jan 1998 08:21:27 -0500
Organization: Cornell University (http://www.cornell.edu/)
Lines: 32
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <34CF30D7.65C1B97D@cornell.edu>
References: <199801272138 DOT KAA03406 AT cirrostratus DOT netaccess DOT co DOT nz> <34CEFDB8 DOT FC82DF59 AT LSTM DOT Ruhr-UNI-Bochum DOT De>
NNTP-Posting-Host: cu-dialup-0043.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Thomas Demmer wrote:

> Simple optimization: Common Subexpression Evaluation (CSE):
> double dx2,dy2, dxy;
>    dx2= (x1-x2)*(x1-x2);
>    dy2= (y1-y2)*(y1-y2);
>    dxy= (x1-x2)*(y1-y2);
> a dumb compiler does exactly what you want. A smart one, too, but
> in a different way. The expressions in parantheses are evaluated
> only once, stored in a register, or a unnamed variable, and used.
> Makes code faster, and slightly shorter.
> Next lines:
>   R = dx2+dy2+dxy;
>   return R;

i am not very proficient in the intricacies of floating point
arithmetic, and this is probably off-topic but both CSE and keeping
interim values in registers can cause subtle but serious problems when
dealing with floting point.

see
http://www.wam.umd.edu/whats_new/workshop3.0/common-tools/numerical_comp_guide/goldberg1.doc.html

for more information.
-- 
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA

mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019