Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!psuvax1!rutgers!cmcl2!lanl!cochiti.lanl.gov!jlg From: jlg@cochiti.lanl.gov (Jim Giles) Newsgroups: comp.arch Subject: Re: Frequency of elementary functions (and other things) Message-ID: <24127@lanl.gov> Date: 21 May 91 14:54:25 GMT References: <104811@sgi.sgi.com> <1991May19.080051.29716@lth.se> <12505@mentor.cc.purdue.edu> <1991May21.010928.20316@lth.se> Sender: news@lanl.gov Organization: Los Alamos National Laboratory Lines: 47 In article <1991May21.010928.20316@lth.se>, bengtl@maths.lth.se (Bengt Larsson) writes: |> In article <12505@mentor.cc.purdue.edu> hrubin@pop.stat.purdue.edu (Herman Rubin) writes: |> [...] |> >The use of the index of a do loop for floating point operations |> >internally is not unusual. |> |> "not unusual"? Prove it. I've been staying out of this thread before, but this is a ridiculous. I suppose if Herman had said that is is not unusual to use the letter 'a' as the first character of a variable name you'd have asked him to prove that too? _OF COURSE_ it's common to use integer iteration variables to drive floating point calculations - it is the _recommended_ way to do so! for (i=0;i<10000;i++){ for (x=0.0;x<100.0;x+=0.01){ x=i*0.01; ... ... } } The left loop is more accurate than the right one. The right one may not even take the right number of steps on some machines (and this becomes more likely as the number of steps increases). |> [...] |> >Many function programs use table lookup. This requires extracting the |> >relevant bits from the floating point number, and frequently obtaining |> >the difference. |> |> Would be interesting to hear from someone who has _written_ such |> "function programs" (assuming you mean subroutine libraries). I have. Yes, you have to extract bits from the floating point values and manipulate them as integer quantities (if you want to get the right answer before hell freezes over). Read any book on numerical methods. Consider, for example "Methods and Programs for Mathematical Functions", by Stephen Moshier, publ. Ellis Horwood Limited in England, publ. John Wiley & Sons in USA and Canada, 1989 (programs written in the book are in C - _really_heavy_ use of frexp, especially in argument reduction). Only people who don't do much numerical programming (or do it badly) think this kind of thing is rare or unusual. Note: Yes, this means that if you want to do _accurate_ and _efficient_ numerical programming, you often have to do machine dependent things. That's the way it is. J. Giles