home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.programming      Programming issues that transcend langua      57,431 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 56,772 of 57,431   
   Richard Heathfield to Dmitry A. Kazakov   
   Re: Another little puzzle   
   14 Dec 22 16:13:17   
   
   From: rjh@cpax.org.uk   
      
   On 14/12/2022 3:41 pm, Dmitry A. Kazakov wrote:   
   > On 2022-12-14 16:18, Richard Heathfield wrote:   
   >   
   >>> BTW, averaging floats is a nasty problem too. A naive   
   >>> implementation quickly loses precision.   
   >>   
   >> We're dealing with 'o'clock' and "HH:MM", and nowadays we have   
   >> 64-bit integer types and there are even 128-bit integers   
   >> mooching around looking for a reason to exist. You'd have to   
   >> average a hell of a lot of times even to /need/ floats, let   
   >> alone lose significant precision.   
   >   
   > I never suggested float for averaging time stamps,   
      
   Yes, you did.   
      
   > I pointed out   
   > that averaging is not a simple problem.   
      
   Yes, it is.   
      
   > E.g. try this one:   
   >   
   >     function Average (X : Float; N : Positive) return Float is   
   >        Sum : Float := 0.0;   
   >     begin   
   >        for Index in 1..N loop   
   >           Sum := Sum + X;   
   >        end loop;   
   >        return Sum / Float (N);   
   >     end Average;   
   >   
   > The function does naive averaging. For simplicity it just sums up   
   > the same number X N times and divides by N.   
      
   You're not being naïve /enough/. The average of N instances of X   
   is X, so just return X.   
      
   Yes, if you try hard enough, you can screw anything up. So what?   
      
   --   
   Richard Heathfield   
   Email: rjh at cpax dot org dot uk   
   "Usenet is a strange place" - dmr 29 July 1999   
   Sig line 4 vacant - apply within   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca