- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional offset parameter for mod() #14431
Comments
There is |
Well, that's embarrassing. :) I only checked http://docs.julialang.org/en/release-0.4/manual/mathematical-operations/ and |
An optional second argument seems generally useful. However, more importantly -- do you want to submit a pull request to update the documentation for |
I do rather like the version with a third argument as a generalization of |
The related issue #14496 discusses this further and already has a PR. Should this issue be closed as a duplicate? |
I think a more elegant interface would be julia> mod(88, 10:20)
11-element Array{Int64,1}:
8
0
4
10
4
13
8
3
16
12
8 This is one of those cases where implicit vectorization causes harm. In my own code I regularly define |
Let's deprecate the vectorized form ASAP in master? |
I can think of other usecases.
|
Yeah, the degrees example is actually not too bad. I regularly use the Mathematica version of this function to do |
Effectively implemented by #32628. Note that we also have |
My main grudge with the 1-based array indexing common in scientific programming languages is that it makes cyclic array-indexing a pain:
The only language I know which solves this problem reasonably elegantly is Mathematica whose
Mod
function takes an optional third argument which is an offset that shifts the representatives of the remainder classes. E.g.mod(x,3,1)
would return a number in3, 1, 2
instead of0, 1, 2
. This makes cyclic 1-based indexing a lot neater:I don't know if this would also be a useful feature for
rem
, especially becauserem(x,n)
doesn't come with the semantics "this function will always return one ofn
values".The text was updated successfully, but these errors were encountered: