Crossfire JXClient, Trunk  R20561
MathUtils.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.util;
23 
28 public class MathUtils {
29 
33  private MathUtils() {
34  }
35 
42  public static int div(final int numerator, final int denominator) {
43  if (numerator >= 0) {
44  return numerator/denominator;
45  }
46  return -((denominator-1-numerator)/denominator);
47  }
48 
55  public static int mod(final int numerator, final int denominator) {
56  final int result = numerator%denominator;
57  return result < 0 ? result+denominator : result;
58  }
59 
66  public static int divRoundUp(final int numerator, final int denominator) {
67  if (numerator >= 0) {
68  return (numerator+denominator-1)/denominator;
69  }
70  return -(-numerator/denominator);
71  }
72 
79  public static int divRound(final int numerator, final int denominator) {
80  if (numerator >= 0) {
81  return (numerator+denominator/2)/denominator;
82  }
83  return -((-numerator-denominator/2+1)/denominator);
84  }
85 
86 }
static int div(final int numerator, final int denominator)
Calculates (.
Definition: MathUtils.java:42
static int mod(final int numerator, final int denominator)
Calculates the remainder of.
Definition: MathUtils.java:55
Utility class for mathematical functions.
Definition: MathUtils.java:28
MathUtils()
Private constructor to prevent instantiation.
Definition: MathUtils.java:33
static int divRound(final int numerator, final int denominator)
Returns the quotient of two values, rounded to the nearest integer.
Definition: MathUtils.java:79
static int divRoundUp(final int numerator, final int denominator)
Returns the quotient of two values, rounded up to the nearest integer.
Definition: MathUtils.java:66