Diff code: bcadd

Function:
Description: Returns the sum of two arbitrary precision numbers.
Version A:
Version B:
bcadd version 77bcadd version 522
 1function bcadd (left_operand, right_operand, scale) {
 1function bcadd (left_operand, right_operand, scale) {
 2    // http://jsphp.co/jsphp/fn/view/bcadd
 2  // discuss at: http://phpjs.org/functions/bcadd/
 3    // + original by: lmeyrick (https://sourceforge.net/projects/bcmath-js/)
 3  // original by: lmeyrick (https://sourceforge.net/projects/bcmath-js/)
 4    // - depends on: _phpjs_shared_bc
 4  // depends on: _phpjs_shared_bc
 5    // * example 1: bcadd(1, 2);
 5  // example 1: bcadd(1, 2);
 6    // * returns 1: 3
 6  // returns 1: 3
 7    // @todo: implement these testcases
 7  // todo: implement these testcases
 8    // bcscale(0);
 9    //
10    // bcmath.test.result('bcadd', 1, '3', bcadd("1", "2"));
11    // bcmath.test.result('bcadd', 2, '4.0000', bcadd("-1", "5", 4));
12    // bcmath.test.result('bcadd', 3, '8728932003911564969352217864684.00', bcadd("1928372132132819737213", "8728932001983192837219398127471", 2));
13    // bcmath.test.result('bcadd', 4, '3.357000', bcadd('1.123', '2.234', 6));
14    var libbcmath = this._phpjs_shared_bc();
15
 8
16    var first, second, result;
 9  var libbcmath = this._phpjs_shared_bc()
17
10
18    if (typeof(scale) == 'undefined') {
11  var first, second, result
19        scale = libbcmath.scale;
20    }
21    scale = ((scale < 0) ? 0 : scale);
22
12
23    // create objects
13  if (typeof scale === 'undefined') {
24    first = libbcmath.bc_init_num();
14    scale = libbcmath.scale
25    second = libbcmath.bc_init_num();
15  }
26    result = libbcmath.bc_init_num();
16  scale = ((scale < 0) ? 0 : scale)
27
17
28    first = libbcmath.php_str2num(left_operand.toString());
18  // create objects
29    second = libbcmath.php_str2num(right_operand.toString());
19  first = libbcmath.bc_init_num()
20  second = libbcmath.bc_init_num()
21  result = libbcmath.bc_init_num()
30
22
23  first = libbcmath.php_str2num(left_operand.toString())
24  second = libbcmath.php_str2num(right_operand.toString())
31
25
32    result = libbcmath.bc_add(first, second, scale);
26  result = libbcmath.bc_add(first, second, scale)
33
27
34    if (result.n_scale > scale) {
28  if (result.n_scale > scale) {
35        result.n_scale = scale;
29    result.n_scale = scale