Here you can find the source of mod(float dividend, float quotient)
Parameter | Description |
---|---|
dividend | number to divide |
quotient | number to divide by |
static float mod(float dividend, float quotient)
//package com.java2s; public class Main { /**// ww w. j a va2s . c o m * Computes the modulo relationship. This is not the same as * Java's remainder (%) operation, which always returns a * value with the same sign as the dividend or 0. * * @param dividend number to divide * @param quotient number to divide by * @return the number r with the smallest absolute value such * that sign(r) == sign(quotient) and there exists an * integer k such that k * quotient + r = dividend */ //VisibleForTesting static float mod(float dividend, float quotient) { float result = dividend % quotient; if (result == 0 || Math.signum(dividend) == Math.signum(quotient)) { return result; } else { return result + quotient; } } }