@@ -233,27 +233,28 @@ class BigDecimalTest {
233
233
@ Test
234
234
def testMathContext () {
235
235
def testPrecision () {
236
- val e = 1000
236
+ val p = 1000
237
+ val n = BigDecimal (" 1.1" , MC .UNLIMITED ).pow(p)
237
238
238
- val n = BigDecimal (" 1.1" , MC .UNLIMITED ).pow(e)
239
- assert(BigDecimal (1.1d , MC .UNLIMITED ).pow(e) == n)
240
- assert(BigDecimal .decimal(1.1d , MC .UNLIMITED ).pow(e) == n)
241
- assert(BigDecimal .decimal(1.1f , MC .UNLIMITED ).pow(e) == n)
242
- assert(BigDecimal .decimal(new BD (" 1.1" ), MC .UNLIMITED ).pow(e) == n)
239
+ // BigDecimal(x: Float, mc: MC), which may not do what you want, is deprecated
240
+ assert(BigDecimal (1.1f , MC .UNLIMITED ).pow(p) == BigDecimal (java.lang.Double .toString(1.1f .toDouble), MC .UNLIMITED ).pow(p))
241
+ assert(BigDecimal (1.1d , MC .UNLIMITED ).pow(p) == n)
242
+ assert(BigDecimal (new BD (" 1.1" ), MC .UNLIMITED ).pow(p) == n)
243
243
244
- val m = BigDecimal (java.lang.Double .toString(1.1f .toDouble), MC .UNLIMITED ).pow(e)
245
- assert(BigDecimal (1.1f , MC .UNLIMITED ).pow(e) == m) // deprecated
244
+ assert(BigDecimal .decimal(1.1f , MC .UNLIMITED ).pow(p) == n)
245
+ assert(BigDecimal .decimal(1.1d , MC .UNLIMITED ).pow(p) == n)
246
+ assert(BigDecimal .decimal(new BD (" 1.1" ), MC .UNLIMITED ).pow(p) == n)
246
247
247
- val l = BigDecimal (" 11" , MC .UNLIMITED ).pow(e)
248
- assert(BigDecimal (11 , MC .UNLIMITED ).pow(e) == l)
249
- assert(BigDecimal .decimal(11 , MC .UNLIMITED ).pow(e) == l)
248
+ assert((BigDecimal (11 , MC .UNLIMITED ) / 10 ).pow(p) == n)
249
+ assert((BigDecimal .decimal(11 , MC .UNLIMITED ) / 10 ).pow(p) == n)
250
250
}
251
251
252
252
def testRounded () {
253
+ // the default rounding mode is HALF_UP
254
+ assert((BigDecimal (1.23f , new MC (3 )) + BigDecimal (" 0.005" )).rounded == BigDecimal (" 1.24" )) // deprecated api
253
255
assert((BigDecimal (1.23d , new MC (3 )) + BigDecimal (" 0.005" )).rounded == BigDecimal (" 1.24" ))
254
- assert((BigDecimal (1.23f , new MC (3 )) + BigDecimal (" 0.005" )).rounded == BigDecimal (" 1.24" )) // deprecated
255
- assert((BigDecimal .decimal(1.23d , new MC (3 )) + BigDecimal (" 0.005" )).rounded == BigDecimal (" 1.24" ))
256
256
assert((BigDecimal .decimal(1.23f , new MC (3 )) + BigDecimal (" 0.005" )).rounded == BigDecimal (" 1.24" ))
257
+ assert((BigDecimal .decimal(1.23d , new MC (3 )) + BigDecimal (" 0.005" )).rounded == BigDecimal (" 1.24" ))
257
258
}
258
259
259
260
testPrecision()
0 commit comments