Hello All, To have a little fun concerning: > So (-2+12) % 12 will always give 10 whether it's python, C++, BASIC or > an abacus!
and > 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. While waving my hand I calmly say, "These are not the modulos you are looking for." If my Jedi powers have persuaded you, you will stop reading this post and look elsewhere; otherwise keep reading. Actually, modulo and programming language when it comes to negative numbers has several competing camps. Wikipedia has an excellent article about the details. Of particular interest is the massive list of programming languages and how differently each handles this issue. I suggest the best advice is to decide what you are going to do with the modulo if you anticipate negative divisors, and write your own handler for it based on what you need, as will suggested. Looks like C and C++ has a pretty checked past concerning what values will come out when negative numbers are involved. http://en.wikipedia.org/wiki/Modulo_operation Sincerely, Julie S. --- On Sun, 1/13/13, Abrolag <[email protected]> wrote: From: Abrolag <[email protected]> Subject: Re: [Rosegarden-user] \RemoveEmptyStaves in lilypond output To: [email protected] Date: Sunday, January 13, 2013, 11:12 AM On Sun, 13 Jan 2013 05:32:55 -0500 "D. Michael McIntyre" <[email protected]> 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. > > 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! -- 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. ON SALE this month only -- learn more at: http://p.sf.net/sfu/learnmore_123012 _______________________________________________ Rosegarden-user mailing list [email protected] - use the link below to unsubscribe https://lists.sourceforge.net/lists/listinfo/rosegarden-user ------------------------------------------------------------------------------ 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. ON SALE this month only -- learn more at: http://p.sf.net/sfu/learnmore_123012 _______________________________________________ Rosegarden-user mailing list [email protected] - use the link below to unsubscribe https://lists.sourceforge.net/lists/listinfo/rosegarden-user
