| r155 vs r156 | ||
|---|---|---|
| ... | ... | |
| 18 | 18 | '''rs''' : "result" suprerior value (integer→string); '''ri''' : "result" inferior value (integer→string); |
| 19 | 19 | '''i''' : index; '''tv''' temporary value 1 (integer); '''tw''' temporary value 2 (integer); '''ps''' : pass (logical); |
| 20 | 20 | '''ea''' : error about "a"; '''eb''' : error about "b"; '''wa''' : warning about "a" ; '''wb''' : warning about "b" ; |
| 21 | {{{#!if this.as=a.toString(), this.bs=b.toString(), this.rs=0+0, this.ru=0+0, this.rb=0+0, this.ri=0+0, this.rp=0+0, this.i=0+0, this.tv=1, this.tw=0, this.ea=0+0, this.eb=0+0, this.wa=0+0, this.wb=0+0 | |
| 21 | {{{#!if this.as=a.toString(), this.bs=b.toString(), this.rs=0+0, this.ru=0+0, this.rb=0+0, this.ri=0+0, this.rp=0+0, this.i=0+0, this.tv=1, this.tw=0, this.ea=0+0, this.eb=0+0, this.wa=0+0, this.wb=0+0, this.ps=false | |
| 22 | 22 | }}}{{{#!if this.al=as.length, this.bl=bs.length, this.ad=as.indexOf("."), this.bd=bs.indexOf(".") |
| 23 | 23 | }}}{{{#!if ad!=-1 |
| 24 | 24 | 소수점이 발견되는 자리 번호가 ad이므로 ad+1번에 해당되는 자리부터 끝까지 표기합니다. |
| ... | ... | |
| 136 | 136 | }}}}}} |
| 137 | 137 | |
| 138 | 138 | ru값이 어떤지 보고 각 경우 rb값이 어떠한가에 따라 rb만 정리하거나 rb와 ru 모두 정리합니다. |
| 139 | 중복 처리를 막기 위해 변수 하나를 | |
| 140 | ||
| 141 | ||
| 139 | 중복 처리를 막기 위해 초기화된 ps 변수 하나를 가져옵니다. | |
| 142 | 140 | |
| 143 | 141 | 소수점 아래 값의 부호와 소수점 위의 값의 부호가 서로 다른 경우 계산을 하기 위해 값을 하나 정의합니다. |
| 144 | 142 | {{{#!if i<ap |
| ... | ... | |
| 479 | 477 | +18자}}}{{{#!if bb=bb.substr(0,18) |
| 480 | 478 | }}} |
| 481 | 479 | |
| 482 | ||
| 483 | ||
| 480 | 곱셈은 18자리를 끊어서 계산합니다. 소수점 아래 18자리의 아래인 제19~36번 자리를 ri로 둡니다. 소수점 위 19~36번째 자리는 rs로 두어 ri, rb, ru, rs 순으로 계산합니다. | |
| 484 | 481 | |
| 485 | 482 | 앞으로 있을 계산은 다음과 같습니다. |
| 486 | 483 | * ri를 더했더니 ri가 19자리 숫자로 넘치면 넘친 앞의 1자리를 rb로 넘깁니다. |
| ... | ... | |
| 488 | 485 | * ru가 19자리로 넘친다면 넘친 앞의 1자리를 rs로 넘깁니다. |
| 489 | 486 | (rs는 상용로그로 보았을 때 log a<18, log b<18 에서 log (a*b) = log a + log b < 36이므로 19자리로 넘치지 않습니다.) |
| 490 | 487 | 문자열로 바꾸고 문자열을 쪼갠 다음 숫자로 바꾸는 과정입니다. 이를 if로 바꾸면 다음과 같습니다. |
| 488 | {{{#!if false | |
| 491 | 489 | {{{#!if ri=ri.toString(), ri.length==19 |
| 492 | 490 | {{{#if rb=(+rb)+(+ri.substr(0,1)), ri=(+ri.substr(1,18)) |
| 493 | 491 | }}}}}} |
| ... | ... | |
| 497 | 495 | {{{#!if ru=ru.toString(), ru.length==19 |
| 498 | 496 | {{{#if rs=(+rs)+(+ru.substr(0,1)), ru=(+ru.substr(1,18)) |
| 499 | 497 | }}}}}} |
| 498 | }}} | |
| 499 | 변수 tv, tw, i, ps를 가져옵니다. tw는 0, tv는 1, i는 0, ps는 false으로 초기화 된 채로 있습니다. 연산 과정 중간중간에 마지막 자릿수를 보정하고자 10씩 곱하게 됩니다. ri에서 최대 18자리에서 1자리 수를 곱하면 19자리가 될 수 있으므로 곱셈할 때마다 19자리로 넘치는 숫자는 rb로 넘깁니다. | |
| 500 | ## for i=0 to 17 | |
| 501 | {{{#!if tw=(+ab.substr(0,18-i))*(+bb.substr(17-i,1))*tv | |
| 502 | }}}{{{#!if tw=tw.toString(), tw.legnth==19 | |
| 503 | {{{#!if rb=(+rb)+(+tw.substr(0,1)), ri=(+ri)+(+tw.substr(1,18)) | |
| 504 | }}} | |
| 505 | }}} | |
| 506 | {{{#!if i+=1 | |
| 507 | }}} | |
| 500 | 508 | |
| 501 | 509 | |
| 510 | ||
| 511 | ||
| 502 | 512 | 여기까지가 a*b 계산과정입니다. |
| 503 | 513 | }}} |
| 504 | 514 | |
| ... | ... | |
| 539 | 549 | (@b@)}}} {{{#!if (bs.length>=20)||(as.length+bs.length>=30) |
| 540 | 550 | [br]}}}= {{{#!if rs!="" |
| 541 | 551 | }}}{{{#!if (f=='+')||(f=='-') |
| 542 | {{{#!if this. | |
| 552 | {{{#!if this.rl=ru.length | |
| 543 | 553 | ##ru string |
| 544 | 554 | }}}@ru@{{{#!if +rp!=0 |
| 545 | 555 | ##rb string, decimal point marking |
| ... | ... |