Here you can find the source of div(double left, double right)
public static long div(double left, double right)
//package com.java2s; /*/*from ww w . j a va 2 s .com*/ * #%~ * VDM Code Generator Runtime * %% * Copyright (C) 2008 - 2014 Overture * %% * This program 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 program 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/gpl-3.0.html>. * #~% */ public class Main { public static long div(double left, double right) { validateInput(left, right); return computeDiv(left, right); } private static void validateInput(double left, double right) { if (!(is_int(left) && is_int(right))) { throw new ArithmeticException("Operands must be integers. Got left " + left + " and right" + right); } if (right == 0L) { throw new ArithmeticException("Division by zero is undefined"); } } private static long computeDiv(double lv, double rv) { if (lv / rv < 0) { return (long) -Math.floor(Math.abs(lv / rv)); } else { return (long) Math.floor(Math.abs(-lv / rv)); } } public static boolean is_int(Object value) { Double doubleValue = getDoubleValue(value); return is_int(doubleValue); } private static boolean is_int(Double doubleValue) { return doubleValue != null && (doubleValue == Math.floor(doubleValue)) && !Double.isInfinite(doubleValue); } private static Double getDoubleValue(Object value) { if (!(value instanceof Number)) { return null; } Double doubleValue = ((Number) value).doubleValue(); return doubleValue; } }