"normalizing" a value

bvdp bob at mellowood.ca
Wed Jul 1 22:41:26 EDT 2015


On Wednesday, July 1, 2015 at 7:23:19 PM UTC-7, rand... at fastmail.us wrote:
> On Wed, Jul 1, 2015, at 21:49, bvdp wrote:
> > Interesting that negative values translate properly. That's an
> > non-intuitive result to me. Guess I should have studied that math stuff
> > harder way back when!
> 
> There are multiple interpretations of the operation, and not all
> languages behave the same way as Python does with negative operands.
> Python is the odd one out when one considers C/C++, C#, and Java which
> all behave a different way.
> 
> In general, almost all languages behave in a way so that given q, r = a
> // b, a % b; q * b + r == a. However, this simply changes the question
> to how division results involving negative operands are rounded.
> 
> Here's an article by GvR about why python behaves the way it does:
> http://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html

Interesting link. Thanks. I always thought that modulo was modulo. Guess this is another example of why converting code between languages is hard :)

Anyway, far as shoving my MIDI notes into a single octave, x % 12 seems to be perfect.



More information about the Python-list mailing list