@@ -232,7 +232,31 @@ class BigDecimalTest {
232
232
// Motivated by the problem of MathContext lost
233
233
@ Test
234
234
def testMathContext () {
235
- assert(BigDecimal (1.1d , MC .UNLIMITED ).pow(1000 ) == BigDecimal (" 1.1" , MC .UNLIMITED ).pow(1000 ))
236
- assert((BigDecimal (1.23d , new MC (3 )) + BigDecimal (" 0.005" )).rounded == BigDecimal (" 1.24" ))
235
+ def testPrecision () {
236
+ val e = 1000
237
+
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)
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
246
+
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)
250
+ }
251
+
252
+ def testRounded () {
253
+ 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
+ assert((BigDecimal .decimal(1.23f , new MC (3 )) + BigDecimal (" 0.005" )).rounded == BigDecimal (" 1.24" ))
257
+ }
258
+
259
+ testPrecision()
260
+ testRounded()
237
261
}
238
262
}
0 commit comments