Here you can find the source of mod(long l, int m)
Parameter | Description |
---|---|
l | long value |
m | modulus |
public static int mod(long l, int m)
//package com.java2s; /*/*w w w .ja v a 2s.com*/ * Copyright Myrrix Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Computes {@code l mod m}, such that the result is always in [0,m-1], for any {@code long} * value including negative values. * * @param l long value * @param m modulus * @return {@code l mod m} if l is nonnegative, {@code (l mod m) + m} otherwise */ public static int mod(long l, int m) { return ((int) (l % m) + m) % m; } }