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,660 of 57,431   
   Tim Rentsch to Paul N   
   Re: A little puzzle.   
   22 Nov 22 05:48:17   
   
   From: tr.17687@z991.linuxsc.com   
      
   Paul N  writes:   
      
   > On Tuesday, November 22, 2022 at 12:53:47 PM UTC, Ben Bacarisse wrote:   
   >   
   >> Richard Heathfield  writes:   
      
   [...]   
      
   >>> although of course in C the problem would be far better solved as:   
   >>>   
   >>> int inrange(int lo, int hi, int k)   
   >>> {   
   >>> return (lo <= k) && (k < hi);   
   >>> }   
   >>>   
   >>> or even as a macro.   
   >>>   
   >>> I must confess I'm not entirely certain I have correctly interpreted   
   >>> your puzzle, which I have taken to mean "is this a given value in the   
   >>> given range", but this seems just a bit too easy for you to make a   
   >>> hash of, but I'm sure I've made hashes of worse.  I've missed   
   >>> something, haven't I?   
   >>   
   >> The circular wrapping.  On a clock, 55 is in the range of minutes that   
   >> starts at 45 and ends at 5.   
   >   
   > What's wrong with - subtract start from both end and value, add the   
   > modulus if either is negative, and compare?   
      
   Suppose start is 9223372036854775800 and end is -9223372036854775800   
   (or the corresponding values for type 'int', those values are for a   
   64-bit signed integer type).  The subtraction gives undefined behavior.   
      
   --- 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