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,662 of 57,431   
   David Brown to Tim Rentsch   
   Re: A little puzzle.   
   22 Nov 22 15:31:05   
   
   From: david.brown@hesbynett.no   
      
   On 22/11/2022 14:48, Tim Rentsch wrote:   
   > 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.   
      
   It's all modulo arithmetic - you can do it all as unsigned types.   
      
   Or use Python and be happy - this is, after all, comp.programming and   
   not comp.lang.c !   
      
   --- 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