|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| MathUtils.java | 100% | 76.5% | 55.6% | 73.3% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Joey and its relative products are published under the terms
|
|
| 3 |
* of the Apache Software License.
|
|
| 4 |
*/
|
|
| 5 |
package org.asyrinx.brownie.core.util;
|
|
| 6 |
|
|
| 7 |
/**
|
|
| 8 |
* @author akima
|
|
| 9 |
*/
|
|
| 10 |
public final class MathUtils { |
|
| 11 |
|
|
| 12 |
/**
|
|
| 13 |
*
|
|
| 14 |
*/
|
|
| 15 | 0 |
private MathUtils() {
|
| 16 | 0 |
super();
|
| 17 |
} |
|
| 18 |
|
|
| 19 |
/**
|
|
| 20 |
* 値の整数部が10進数で何桁あるのかを返します。
|
|
| 21 |
*
|
|
| 22 |
* @param value
|
|
| 23 |
* @return
|
|
| 24 |
*/
|
|
| 25 | 19 |
public static int digitPlace(double value) { |
| 26 | 19 |
double work = Math.abs(value) / 10;
|
| 27 | 19 |
int result = 1;
|
| 28 | 19 |
while (work >= 1) {
|
| 29 | 96 |
work /= 10; |
| 30 | 96 |
result++; |
| 31 |
} |
|
| 32 | 19 |
return result;
|
| 33 |
} |
|
| 34 |
|
|
| 35 |
/**
|
|
| 36 |
* 値の整数部が10進数で何桁あるのかを返します。
|
|
| 37 |
*
|
|
| 38 |
* @param value
|
|
| 39 |
* @return
|
|
| 40 |
*/
|
|
| 41 | 0 |
public static int digitPlace(float value) { |
| 42 | 0 |
return digitPlace((double) value); |
| 43 |
} |
|
| 44 |
|
|
| 45 |
/**
|
|
| 46 |
* 値の整数部が10進数で何桁あるのかを返します。
|
|
| 47 |
*
|
|
| 48 |
* @param value
|
|
| 49 |
* @return
|
|
| 50 |
*/
|
|
| 51 | 15 |
public static int digitPlace(int value) { |
| 52 | 15 |
return digitPlace((double) value); |
| 53 |
} |
|
| 54 |
|
|
| 55 |
/**
|
|
| 56 |
* 値の整数部が10進数で何桁あるのかを返します。
|
|
| 57 |
*
|
|
| 58 |
* @param value
|
|
| 59 |
* @return
|
|
| 60 |
*/
|
|
| 61 | 4 |
public static int digitPlace(long value) { |
| 62 | 4 |
return digitPlace((double) value); |
| 63 |
} |
|
| 64 |
|
|
| 65 |
/**
|
|
| 66 |
* 10進数の数値に対して指定された桁の数値を返します。
|
|
| 67 |
*
|
|
| 68 |
* @author akima
|
|
| 69 |
*/
|
|
| 70 | 15 |
public static int getDigitAt(double value, int place) { |
| 71 | 15 |
final double placeNumber = Math
|
| 72 | 15 |
.pow(10, (place > 0) ? place : place + 1); |
| 73 | 15 |
double upper = new Double(value / placeNumber).longValue() |
| 74 |
* placeNumber; |
|
| 75 | 15 |
int result = new Double((value - upper) / placeNumber * 10).intValue(); |
| 76 | 15 |
return result;
|
| 77 |
} |
|
| 78 |
|
|
| 79 |
/**
|
|
| 80 |
* 10進数の数値に対して指定された桁の数値を返します。
|
|
| 81 |
*
|
|
| 82 |
* @author akima
|
|
| 83 |
*/
|
|
| 84 | 0 |
public static int getDigitAt(long value, int place) { |
| 85 | 0 |
return getDigitAt((double) value, place); |
| 86 |
} |
|
| 87 |
|
|
| 88 |
/**
|
|
| 89 |
* 10進数の数値に対して指定された桁の数値を返します。
|
|
| 90 |
*
|
|
| 91 |
* @author akima
|
|
| 92 |
*/
|
|
| 93 | 9 |
public static int getDigitAt(int value, int place) { |
| 94 | 9 |
return getDigitAt((double) value, place); |
| 95 |
} |
|
| 96 |
|
|
| 97 |
/**
|
|
| 98 |
* 10進数の数値に対して指定された桁の数値を返します。
|
|
| 99 |
*
|
|
| 100 |
* @author akima
|
|
| 101 |
*/
|
|
| 102 | 0 |
public static int getDigitAt(float value, int place) { |
| 103 | 0 |
return getDigitAt((double) value, place); |
| 104 |
} |
|
| 105 |
|
|
| 106 |
} |
|
||||||||||