Java Code Examples for com.google.common.math.IntMath#sqrt()

The following examples show how to use com.google.common.math.IntMath#sqrt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MathUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 开方
 */
public static int sqrt(int x, RoundingMode mode) {
	return IntMath.sqrt(x, mode);
}
 
Example 2
Source File: MathUtil.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 开方
 */
public static int sqrt(int x, RoundingMode mode) {
	return IntMath.sqrt(x, mode);
}
 
Example 3
Source File: MathUtil.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
/**
 * 开方
 */
public static int sqrt(int x, RoundingMode mode) {
	return IntMath.sqrt(x, mode);
}
 
Example 4
Source File: GuavaMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void should_round_sqrt_result() {
    int result = IntMath.sqrt(4, RoundingMode.UNNECESSARY);
    assertThat(result, equalTo(2));
}
 
Example 5
Source File: GuavaMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test(expected = ArithmeticException.class)
public void whenNeedRounding_thenThrowException() {
    IntMath.sqrt(5, RoundingMode.UNNECESSARY);
}
 
Example 6
Source File: GuavaIntMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenSqrtIntegerValues_shouldSqrtThemAndReturnTheResultForCeilingRounding() {
    int result = IntMath.sqrt(30, RoundingMode.CEILING);
    assertEquals(6, result);
}
 
Example 7
Source File: GuavaIntMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenSqrtIntegerValues_shouldSqrtThemAndReturnTheResultForFloorRounding() {
    int result = IntMath.sqrt(30, RoundingMode.FLOOR);
    assertEquals(5, result);
}
 
Example 8
Source File: GuavaIntMathUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test(expected = ArithmeticException.class)
public void whenSqrtIntegerValues_shouldThrowArithmeticExceptionIfRoundingNotDefinedButNecessary() {
    IntMath.sqrt(30, RoundingMode.UNNECESSARY);
}