-
CSR
-
Resolution: Approved
-
P3
-
minimal
-
New method being added.
-
Java API
-
SE
Summary
Add a square root method to BigDecimal
.
Problem
BigDecimal does not have a sqrt method.
Solution
Add a sqrt method to BigDecimal.
Specification
/**
+ * Returns an approximation to the square root of {@code this}
+ * with rounding according to the context settings.
+ *
+ * <p>The preferred scale of the returned result is equal to
+ * {@code floor(this.scale()/2.0)}. The value of the returned
+ * result is always within one ulp of the exact decimal value for
+ * the precision in question. If the rounding mode is {@link
+ * RoundingMode#HALF_UP HALF_UP}, {@link RoundingMode#HALF_DOWN
+ * HALF_DOWN}, or {@link RoundingMode#HALF_EVEN HALF_EVEN}, the
+ * result is within one half an ulp of the exact decimal value.
+ *
+ * <p>Special case:
+ * <ul>
+ * <li> The square root of {@code ZERO} is {@code ZERO}
+ * </ul>
+ *
+ * @param mc the context to use.
+ * @return the square root of {@code this}.
+ * @throws ArithmeticException if {@code this} is less than zero.
+ * @throws ArithmeticException if an exact result is requested
+ * ({@code mc.getPrecision()==0}) and there is no finite decimal
+ * expansion of the exact result
+ * @throws ArithmeticException if
+ * {@code (mc.getRoundingMode()==RoundingMode.UNNECESSARY}) and
+ * the exact result cannot fit in {@code mc.getPrecision()}
+ * digits.
+ * @since 9
+ */
+ BigDecimal sqrt(MathContext mc) {
- csr for
-
JDK-4851777 Add BigDecimal sqrt method
-
- Closed
-