On Mon, 14 Jan 2013 09:08:15 +0100 Robert Wachinger <pri...@robert-wachinger.de> wrote:
> On Sun, Jan 13, 2013 at 04:12:36PM +0000, Abrolag wrote: > > On Sun, 13 Jan 2013 05:32:55 -0500 > > "D. Michael McIntyre" <rosegarden.trumpe...@gmail.com> wrote: > > > > > > a) fix it (it must be something really simple and stupid) > > > > > > Or complicated an interesting. > > > > > > According to three random calculators I tried, -2 mod 12 is 10, which is > > > clearly the assumption the person writing this code made. > > > > > > According to C++, -2 % 12 is -2. > > Annoying. To my understanding, y modulo X should always be a value between > 0 and X-1. > > > > There's your problem. > > > > Interesting. That's a problem I *have* had to resolve. My way of doing so is > > simply to add the modulo value before the calculation to absolutely > > guarantee a > > consistent result. > > > > So (-2+12) % 12 will always give 10 whether it's python, C++, BASIC or an > > abacus! > > JFTR: This would not work with -14 % 12 (hm, "((x % M) + M) % M" ??? ;-) ) > > > Ciao, Robert It will if you add 24. I thought Michael only had to handle one octave. Make it 120 and it'll handle 10 :) I originally used the idea for a shaft encoder where I knew it couldn't exceed 1 rotation in the time between readings. -- Will J Godfrey http://www.musically.me.uk Say you have a poem and I have a tune. Exchange them and we can both have a poem, a tune, and a song. ------------------------------------------------------------------------------ Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122412 _______________________________________________ Rosegarden-user mailing list Rosegarden-user@lists.sourceforge.net - use the link below to unsubscribe https://lists.sourceforge.net/lists/listinfo/rosegarden-user