Closed megawac closed 9 years ago
Yeah, the first thread the one I was looking for, we discussed this operator in quite some detail in https://github.com/ramda/ramda/issues/186 and I needed it today
Done some tests and research to clear up my understanding :
http://en.wikipedia.org/wiki/Modulo_operation
I'm in a bit of a bind as to decide what to implement to be honest. Euclidean seems to be the most consistent to me but it is also the most expensive. I might as well implement them all, name the functions accordingly and avoid making a "modulo" function as people may have a different opinion of how it should behave based on their background. Any thought on the matter ?
The most common implementation is the one from the blog post but I think itd be better to implement a version closer to the what would be expected mathematically.
Implemented euclideanModulo, flooredModulo and truncatedModulo.
Also ran some jsperf test to figure out if an alternative implementation without using % would be better (or worse). It turned out there are no real difference.
Good work, thanks
It would be nice to have a proper math mod function (see http://javascript.about.com/od/problemsolving/a/modulobug.htm)