Here you can find the source of modulo(final long x, final long y)
Parameter | Description |
---|---|
x | dividend |
y | divisor |
public static long modulo(final long x, final long y)
//package com.java2s; /* Util.java// w w w .ja v a 2s . c o m * * Copyright (C) 2015, Tom? Pecina <tomas@pecina.cz> * * This file is part of cz.pecina.retro, retro 8-bit computer emulators. * * This application is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This application is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Modulo, with correction for negative dividends. * The result is always non-negative. * * @param x dividend * @param y divisor * @return x % y, non-negative */ public static int modulo(final int x, final int y) { return ((x % y) + y) % y; } /** * Modulo, with correction for negative dividends. * The result is always non-negative. * * @param x dividend * @param y divisor * @return x % y, non-negative */ public static long modulo(final long x, final long y) { return ((x % y) + y) % y; } /** * Modulo, with correction for negative dividends. * The result is always non-negative. * * @param x dividend * @param y divisor * @return x % y, non-negative */ public static float modulo(final float x, final float y) { return ((x % y) + y) % y; } /** * Modulo, with correction for negative dividends. * The result is always non-negative. * * @param x dividend * @param y divisor * @return x % y, non-negative */ public static double modulo(final double x, final double y) { return ((x % y) + y) % y; } }