| @@ 535-563 (lines=29) @@ | ||
| 532 | } |
|
| 533 | ||
| 534 | //sd subtracts the decimal part of string |
|
| 535 | function sd(x, y) {
|
|
| 536 | var xl, yl, i; |
|
| 537 | xl = x.length; |
|
| 538 | yl = y.length; |
|
| 539 | if (xl < yl) {
|
|
| 540 | x += zero(yl - xl); |
|
| 541 | } else if (xl > yl) {
|
|
| 542 | y += zero(xl - yl); |
|
| 543 | } |
|
| 544 | ||
| 545 | x = x.split("").reverse();
|
|
| 546 | y = y.split("").reverse();
|
|
| 547 | ||
| 548 | var borrow = 0, |
|
| 549 | diff = [], |
|
| 550 | temp = 0; |
|
| 551 | xl = x.length; |
|
| 552 | for (i = 0; i < xl; i++) {
|
|
| 553 | temp = (x[i] * 1) - (y[i] * 1) - borrow; |
|
| 554 | if (temp < 0) {
|
|
| 555 | temp = (10 + x[i] * 1 - y[i] * 1 - borrow); |
|
| 556 | borrow = 1; |
|
| 557 | } else {
|
|
| 558 | borrow = 0; |
|
| 559 | } |
|
| 560 | diff.push(temp); |
|
| 561 | } |
|
| 562 | return [diff.reverse().join(""), borrow + ""];
|
|
| 563 | } |
|
| 564 | ||
| 565 | //subtract is a operator |
|
| 566 | function subtract(_a, _b) {
|
|
| @@ 505-532 (lines=28) @@ | ||
| 502 | } |
|
| 503 | ||
| 504 | //s subtracts the integer part of a string |
|
| 505 | function s(x, y) {
|
|
| 506 | var xl, yl, i; |
|
| 507 | xl = x.length; |
|
| 508 | yl = y.length; |
|
| 509 | if (xl < yl) {
|
|
| 510 | x = zero(yl - xl) + x; |
|
| 511 | } else if (xl > yl) {
|
|
| 512 | y = zero(xl - yl) + y; |
|
| 513 | } |
|
| 514 | x = x.split("").reverse();
|
|
| 515 | y = y.split("").reverse();
|
|
| 516 | ||
| 517 | var borrow = 0, |
|
| 518 | diff = [], |
|
| 519 | temp = 0; |
|
| 520 | xl = x.length; |
|
| 521 | for (i = 0; i < xl; i++) {
|
|
| 522 | temp = (x[i] * 1) - (y[i] * 1) - borrow; |
|
| 523 | if (temp < 0) {
|
|
| 524 | temp = (10 + x[i] * 1 - y[i] * 1 - borrow); |
|
| 525 | borrow = 1; |
|
| 526 | } else {
|
|
| 527 | borrow = 0; |
|
| 528 | } |
|
| 529 | diff.push(temp); |
|
| 530 | } |
|
| 531 | return diff.reverse().join("");
|
|
| 532 | } |
|
| 533 | ||
| 534 | //sd subtracts the decimal part of string |
|
| 535 | function sd(x, y) {
|
|