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,697 of 57,431   
   Tim Rentsch to Julio Di Egidio   
   Re: A little puzzle.   
   29 Nov 22 04:29:42   
   
   From: tr.17687@z991.linuxsc.com   
      
   Julio Di Egidio  writes:   
      
   > On Monday, 28 November 2022 at 16:22:38 UTC+1, Tim Rentsch wrote:   
   >   
   >> Julio Di Egidio  writes:   
   >>   
   >>>>> On Monday, 21 November 2022 at 21:45:34 UTC+1, Ben Bacarisse wrote:   
      
   [...]   
      
   >>>>>> Consider any ordered measure that "wraps round" -- bearings in   
   >>>>>> degrees, minutes in the hour, indeed hours in either the 12 or   
   >>>>>> 24 hour clock.  The problem is to determine if a given value is   
   >>>>>> in the sub-range specified by a start and an en value.   
   >>>   
   >>> Argh!  But you should not have snipped that "beware   
   >>> of bugs", that was the most important part!! ;)   
   >>   
   >> It's your job to beware of bugs, not mine.   
   >   
   > I didn't know you were paying me for production level code:   
      
   You are under no obligation to post bug-free code.  Similarly I   
   am under no obligation to correct bugs in your code.  But if you   
   want your postings to be taken seriously it's important to put   
   more thought into what is posted and make an effort to avoid   
   careless mistakes.   
      
   > in that case, I'd have asked for the technical requirements,   
   > not just the functional ones...   
   >   
   > IOW, I have have given a mathematical spec written in some   
   > simply-typed functional language, can be functions on the real   
   > numbers.  Which is often step one in functional/algorithmic   
   > design.  Beside that point, one needs technical requirements,   
   > i.e. info on the concrete numeric types available as a minimum.   
      
   Part of the challenge is to figure out what the interface should   
   be.  The problem is not just a coding exercise.   
      
   >>> This one should do the trick:   
   >>>   
   >>> ```ts   
   >>> /** Returns whether x in [lo, hi[ (mod m). */   
   >>> function inOpenModRange(   
   >>> x:  number, lo:  number, hi:  number, m:  number   
   >>> ): boolean {   
   >>> let x_ = MOD(x - lo, m);   
   >>> let hi_ = MOD(hi - lo, m);   
   >>> return x_ < hi_;   
   >>> }   
   >>> ```   
   >>   
   >> This scheme looks like it will work, as long as the values given   
   >> don't get too near the edges of representation.  JavaScript   
   >> represents numeric values using floating point, and that choice   
   >> leads to some unexpected results when working with large numbers.   
   >>   
   >> However, this approach is more complicated than it needs to be.   
   >> Have you tried looking at the other answers?   
   >   
   > That is complicated??  Maybe I haven't looked well enough   
   > but, honestly, I have not seen anything that is even vaguely as   
   > clear, and efficient, and to the point.  Have I missed it?   
      
   The question can be answered without using any of subtraction,   
   remainder, or mod, and more than one solution has been posted   
   demonstrating that property.  Perhaps you missed those answers.   
      
   --- 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