Java Float Number Mod fmodulo(double v1, double v2)

Here you can find the source of fmodulo(double v1, double v2)

Description

Returns the remainder of the division v1/v2 .

License

Open Source License

Parameter

Parameter Description
v1 dividend; can be positive or negative
v2 divisor; must be positive

Return

remainder of the division; positive and smaller than v2

Declaration

static public double fmodulo(double v1, double v2) 

Method Source Code

//package com.java2s;
/*/*from   w w  w . jav  a2  s  .  c  o  m*/
 *  This file is part of Healpix Java.
 *
 *  This code 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 2 of the License, or
 *  (at your option) any later version.
 *
 *  This code 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 code; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *  For more information about HEALPix, see http://healpix.jpl.nasa.gov
 */

public class Main {
    /** Returns the remainder of the division {@code v1/v2}.
        The result is non-negative.
        @param v1 dividend; can be positive or negative
        @param v2 divisor; must be positive
        @return remainder of the division; positive and smaller than {@code v2} */
    static public double fmodulo(double v1, double v2) {
        if (v1 >= 0)
            return (v1 < v2) ? v1 : v1 % v2;
        double tmp = v1 % v2 + v2;
        return (tmp == v2) ? 0. : tmp;
    }
}

Related

  1. fmod(double a, double b)
  2. fmod(double a, double b)
  3. FMod(double x, double y)
  4. fmodf(Float float1, float float2)
  5. mod(final float a, final float b)
  6. mod(final float a, final float mod)
  7. mod(float a, float b)
  8. mod(float a, float b)