OLD | NEW |
1 // © 2017 and later: Unicode, Inc. and others. | 1 // © 2017 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html#License | 2 // License & terms of use: http://www.unicode.org/copyright.html#License |
3 package com.ibm.icu.impl.number; | 3 package com.ibm.icu.impl.number; |
4 | 4 |
5 import java.math.BigDecimal; | 5 import java.math.BigDecimal; |
6 import java.math.MathContext; | 6 import java.math.MathContext; |
7 import java.math.RoundingMode; | 7 import java.math.RoundingMode; |
8 | 8 |
9 import com.ibm.icu.impl.number.Rounder.IBasicRoundingProperties; | 9 import com.ibm.icu.impl.number.Rounder.IBasicRoundingProperties; |
10 | 10 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 */ | 155 */ |
156 public static MathContext getMathContextOr34Digits(IBasicRoundingProperties pr
operties) { | 156 public static MathContext getMathContextOr34Digits(IBasicRoundingProperties pr
operties) { |
157 MathContext mathContext = properties.getMathContext(); | 157 MathContext mathContext = properties.getMathContext(); |
158 if (mathContext == null) { | 158 if (mathContext == null) { |
159 RoundingMode roundingMode = properties.getRoundingMode(); | 159 RoundingMode roundingMode = properties.getRoundingMode(); |
160 if (roundingMode == null) roundingMode = RoundingMode.HALF_EVEN; | 160 if (roundingMode == null) roundingMode = RoundingMode.HALF_EVEN; |
161 mathContext = MATH_CONTEXT_BY_ROUNDING_MODE_34_DIGITS[roundingMode.ordinal
()]; | 161 mathContext = MATH_CONTEXT_BY_ROUNDING_MODE_34_DIGITS[roundingMode.ordinal
()]; |
162 } | 162 } |
163 return mathContext; | 163 return mathContext; |
164 } | 164 } |
| 165 |
| 166 /** |
| 167 * Gets a MathContext with unlimited precision and the specified RoundingMode.
Equivalent to "new |
| 168 * MathContext(0, roundingMode)", but pulls from a singleton to prevent object
thrashing. |
| 169 * |
| 170 * @param roundingMode The {@link RoundingMode} to use. |
| 171 * @return The corresponding {@link MathContext}. |
| 172 */ |
| 173 public static MathContext mathContextUnlimited(RoundingMode roundingMode) { |
| 174 return MATH_CONTEXT_BY_ROUNDING_MODE_UNLIMITED[roundingMode.ordinal()]; |
| 175 } |
165 } | 176 } |
OLD | NEW |