@@ -2,7 +2,7 @@ const chai = require("chai");
2
2
const JBC = require ( "../dist/jsbi-calculator.js" ) ;
3
3
4
4
const { assert, expect } = chai ;
5
- const { calculator, arrayizeExpression, rpnParse, jsbiCal } = JBC ;
5
+ const { calculator, arrayizeExpression, rpnParse, jsbiCal, BigDecimal } = JBC ;
6
6
7
7
let expression ;
8
8
@@ -26240,3 +26240,77 @@ result = jsbiCal(rpn);
26240
26240
26241
26241
expect ( result ) . to . be . a ( "string" ) ;
26242
26242
expect ( result ) . to . equal ( "0" ) ;
26243
+
26244
+ let squareNumber , root ;
26245
+
26246
+ squareNumber = "0" ;
26247
+ root = BigDecimal . sqrt ( squareNumber ) . toString ( ) ;
26248
+ expect ( root ) . to . be . a ( "string" ) ;
26249
+ expect ( root ) . to . equal ( "0" ) ;
26250
+
26251
+ squareNumber = "-105625" ;
26252
+ root = BigDecimal . sqrt ( squareNumber ) . toString ( ) ;
26253
+ expect ( root ) . to . be . a ( "string" ) ;
26254
+ expect ( root ) . to . equal ( "NaN" ) ;
26255
+
26256
+ squareNumber = "105625" ;
26257
+ root = BigDecimal . sqrt ( squareNumber ) . toString ( ) ;
26258
+ expect ( root ) . to . be . a ( "string" ) ;
26259
+ // expect(root).to.equal("325");
26260
+ expect (
26261
+ Math . abs (
26262
+ Number ( new BigDecimal ( root ) . subtract ( new BigDecimal ( "325" ) ) . toString ( ) )
26263
+ )
26264
+ ) . to . be . lte ( 1e-18 ) ;
26265
+
26266
+ squareNumber = "9" ;
26267
+ root = BigDecimal . sqrt ( squareNumber ) . toString ( ) ;
26268
+ expect ( root ) . to . be . a ( "string" ) ;
26269
+ // expect(root).to.equal("3");
26270
+ expect (
26271
+ Math . abs (
26272
+ Number ( new BigDecimal ( root ) . subtract ( new BigDecimal ( "3" ) ) . toString ( ) )
26273
+ )
26274
+ ) . to . be . lte ( 1e-18 ) ;
26275
+
26276
+ squareNumber = "3.14" ;
26277
+ root = BigDecimal . sqrt ( squareNumber ) . toString ( ) ;
26278
+ expect ( root ) . to . be . a ( "string" ) ;
26279
+ // expect(root).to.equal("1.772004514666935040");
26280
+ expect (
26281
+ Math . abs (
26282
+ Number (
26283
+ new BigDecimal ( root )
26284
+ . subtract ( new BigDecimal ( "1.772004514666935040" ) )
26285
+ . toString ( )
26286
+ )
26287
+ )
26288
+ ) . to . be . lte ( 1e-18 ) ;
26289
+
26290
+ squareNumber = "102448.6" ;
26291
+ root = BigDecimal . sqrt ( squareNumber ) . toString ( ) ;
26292
+ expect ( root ) . to . be . a ( "string" ) ;
26293
+ // expect(root).to.equal("320.075928491975166214");
26294
+ expect (
26295
+ Math . abs (
26296
+ Number (
26297
+ new BigDecimal ( root )
26298
+ . subtract ( new BigDecimal ( "320.075928491975166214" ) )
26299
+ . toString ( )
26300
+ )
26301
+ )
26302
+ ) . to . be . lte ( 1e-18 ) ;
26303
+
26304
+ squareNumber = "516699783" ;
26305
+ root = BigDecimal . sqrt ( squareNumber ) . toString ( ) ;
26306
+ expect ( root ) . to . be . a ( "string" ) ;
26307
+ // expect(root).to.equal("320.075928491975166214");
26308
+ expect (
26309
+ Math . abs (
26310
+ Number (
26311
+ new BigDecimal ( root )
26312
+ . subtract ( new BigDecimal ( "22731.031278848744745528" ) )
26313
+ . toString ( )
26314
+ )
26315
+ )
26316
+ ) . to . be . lte ( 1e-18 ) ;
0 commit comments