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,679 of 57,431   
   Dmitry A. Kazakov to Tim Rentsch   
   Re: A little puzzle.   
   25 Nov 22 09:30:00   
   
   From: mailbox@dmitry-kazakov.de   
      
   On 2022-11-24 23:51, Tim Rentsch wrote:   
      
   > For the general case we would like to handle any circular measure   
   > (for convenience having coordinates in some integer range).   
      
   Not necessarily circular. The same issue arise with overflowing   
   counters. E.g. the typical case when you have some real-time clock   
   counter which periodically runs over and you have to detect overflows.   
      
   > Exercise: write a function to answer this kind of question for   
   > circular measures in general.  You may assume integer coordinates   
   > and intervals that include the starting point but do not include   
   > the end point.  Give a suitable declaration for the function,   
   > and separately give a function definition to implement the given   
   > interface.   
      
   Usual technique is expanding the range this or that way. E.g.   
      
   - Computing differences in the specified direction and complementing by   
   the modulo when the difference turns negative.   
   - Using large non-modular numbers that never overflow, e.g. with indices   
   of a ring buffer. A 64-bit sequence number I is the new "index." To   
   access elements I mod N is used.   
      
   --   
   Regards,   
   Dmitry A. Kazakov   
   http://www.dmitry-kazakov.de   
      
   --- 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