Here you can find the source of floorDivide(long n, long d)
public static final long floorDivide(long n, long d)
//package com.java2s; //License from project: Mozilla Public License public class Main { public static final long floorDivide(long n, long d) { return ((n >= 0) ? (n / d) : (((n + 1L) / d) - 1L)); }//from w w w . j a v a 2s . com public static final int floorDivide(int n, int d) { return ((n >= 0) ? (n / d) : (((n + 1) / d) - 1)); } public static final int floorDivide(int n, int d, int[] r) { if (n >= 0) { r[0] = n % d; return n / d; } int q = ((n + 1) / d) - 1; r[0] = n - (q * d); return q; } public static final int floorDivide(long n, int d, int[] r) { if (n >= 0) { r[0] = (int) (n % d); return (int) (n / d); } int q = (int) (((n + 1) / d) - 1); r[0] = (int) (n - (q * d)); return q; } }