r2 vs r3
11
[[분류:냥]][[분류:계산용 틀]]{{{#!wiki style="display: none;"
2
##디버그용 if 문법 ("문자열" 값으로 정의해야 합니다.)
3
{{{#!if a= ,b= ,f=, md=
4
}}}
52
##== 변수 설명 ==
63
'''as''' : "a" value to string; '''bs''' : "b" value to string;
74
'''al''' : "a" string length (integer); '''bl''' : "b" string length (integer)
......
2724
'''ma''' : message about "a" (string); '''mb''' : message about "b" (string);
2825
'''tm''' : temporary string, or transaction message (string); '''tn''' : temporary string 2 (string);
2926
'''ns''' : negative sign for multiplication and division (string);
30
3127
##== 초기화 ==
32
값을 미리 정의하여 초기화합니다. 중간에 --장난으로-- 계산에 사용되는 변수에 값을 부여한 채로 include 하더라도 이를 무시합니다.
3328
{{{#!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.tu=0, this.tv=1+0, this.tw=0, this.tx=0, this.ty=0, this.ea=0+0, this.eb=0+0, this.wa=0+0, this.wb=0+0, this.ps=false, this.ts=false, this.br=false, this.ns="", this.ma="", this.mb="", this.tm="", this.tn="", this.ms="", this.pd="000000000000000000"
3429
}}}{{{#!if this.al=as.length, this.bl=bs.length, this.ad=as.indexOf("."), this.bd=bs.indexOf(".")
3530
}}}{{{#!if ad!=-1
36
소수점이 발견되는 자리 번호가 ad이므로 ad+1번에 해당되는 자리부터 끝까지 표기합니다.
3731
{{{#!if this.au=as.substr(0,ad), this.ab=as.substr(ad+1, al-ad-1), this.ap=ab.length
3832
}}}{{{#!if (au=="")||(au=="-")||(au=="+")
39
.12345 식으로 또는 -.12345 식으로 기입할 경우 upper 값을 0으로 부여합니다.
4033
{{{#!if au="0"
4134
}}}}}}}}}{{{#!if ad==-1
42
소수점이 존재하지 않을 경우 au 문자열 길이값을 ad로 정의합니다. au의 마지막 문자열 index는 ad-1이 됩니다.
4335
{{{#!if this.au=as, ab="", ap=0+0, ad=au.length
4436
}}}}}}{{{#!if bd!=-1
4537
{{{#!if this.bu=bs.substr(0,bd), this.bb=bs.substr(bd+1, bl-bd-1), this.bp=bb.length
......
4840
}}}}}}}}}{{{#!if bd==-1
4941
{{{#!if this.bu=bs, bb="", bp=0+0, bd=bu.length
5042
}}}}}}
51
5243
##== 유효성 검사 ==
53
the seed에서 지원되는 long(integer)가 unsigned였으면 1844경까지 가서 충분히 19자리로 놀 수 있었는데, signed long이므로 922경까지 가능한 공간에서 18자리로 잘라내기를 합니다. (소수점 위 최대 18자리, 소수점 아래 최대 18자리)
54
55
(반점(,)을 자동적으로 생략하고 들어가는 것은 나중에 생각하겠습니다.)
56
5744
{{{#!if (as!=null)&&(bs!=null)
58
a와 b 모두 입력되었을 때, br와 ts 변수를 이용하여 순차적으로 검사를 진행합니다. 도중 문제가 있으면 (br를 true로 반환하고) 오류 코드를 내도록 만듭니다. a를 먼저 보며, 소수점 윗부분을 먼저 본 다음 소수점 아랫부분을 봅니다.
59
변수 tm와 tn을 가져와 유효성 검사를 실행합니다.
60
먼저 소수점을 2개 이상 입력했음이 탐지된다면 오류코드 5번(이중 소수점 표기)을 반환합니다.
61
소수점을 입력하면 indexOf와 lastIndexOf는 서로 다른 값을 가리키게 됩니다. 소수점을 입력하지 않았을 경우 indexOf와 lastIndexOf는 -1로 서로 같은 값을 가리키게 됩니다.
6245
{{{#!if ts=(as.indexOf(".")==as.lastIndexOf(".")), br=ts?br:true, ea=ts?0:5
63
}}}
64
65
문제가 없으면 au를 tm으로 복제하고 검사를 계속 합니다.
66
앞자리가 마이너스(-)일 경우 이를 잘라냅니다. 이 때 소수점 윗자릿수가 넘치면 오류코드 1번(오버플로)를 반환합니다.
67
{{{#!if ts&&!br
46
}}}{{{#!if ts&&!br
6847
{{{#!if tm=(au[0]==45)?au.substr(1):au, ts=(tm.length<=18), br=ts?br:true, ea=ts?0:1
69
}}}}}}
70
71
의도적으로 00을 적어놓았을 수 있으므로 tm 앞에 숫자 1을 더 붙인 다음, 이를 값으로 바꾼 다음 다시 텍스트 값으로 바꾼 문자열을 tn으로 정의합니다. 중간에 숫자가 아닌 문구가 들어갔다면 숫자가 아닌 문구가 들어간 부분부터 값이 잘려 나오게 됩니다.
72
숫자가 아닌 문구를 섞어넣었음이 탐지될 경우 오류코드 6번(소수점 윗자리 오류)을 반환합니다. (반점(,)도 걸릴 수 있습니다.)
73
{{{#!if ts&&!br
48
}}}}}}{{{#!if ts&&!br
7449
{{{#!if tm="1"+tm, tn=+tm, tn=tn.toString(), ts=(tm==tn), br=ts?br:true, ea=ts?0:6
75
}}}}}}
76
77
소수점 아래 부분을 검사합니다. 앞에서 소수점 개수를 검사했으므로 소수점 아래 부분에 점(.)이 더 이상 나올 수 없습니다.
78
소수점 아래 입력한 자릿수가 19자리를 넘어가면 오류 대신 경고코드 1번(소수점 아래 자릿수 너무 많음)을 반환하고 소수점 아래 자릿수를 최대 18자리로 잘라냅니다. (이하 이상한 문구를 섞어도 이를 계산에 넣지 않게 됩니다.)
79
{{{#!if ts&&!br
50
}}}}}}{{{#!if ts&&!br
8051
{{{#!if ab.length>=19
8152
{{{#!if wa=1, ab=ab.substr(0,18), ap=18
82
}}}}}}
83
84
앞에서 소수점 아래 자릿수를 18자 이하로 줄였습니다. 문자열에서 자릿수에 해당하는 index가 비어있다면 해당 문자열의 주소값은 null이 나옵니다. (예:"테스트"[3]==null) 숫자는 문자열 각 자릿수 문자열의 유니코드 값이 null이 아닌 이상 48 이상 57 이하이며, 이를 이용하여 소수점 아래 18자리에 대해 유효성 검사를 합니다.
85
{{{#!if ts=(((ab[0]==null)||((ab[0]>=48)&&(ab[0]<=57)))&&((ab[1]==null)||((ab[1]>=48)&&(ab[1]<=57)))&&((ab[2]==null)||((ab[2]>=48)&&(ab[2]<=57)))&&((ab[3]==null)||((ab[3]>=48)&&(ab[3]<=57)))&&((ab[4]==null)||((ab[4]>=48)&&(ab[4]<=57)))&&((ab[5]==null)||((ab[5]>=48)&&(ab[5]<=57)))&&((ab[6]==null)||((ab[6]>=48)&&(ab[6]<=57)))&&((ab[7]==null)||((ab[7]>=48)&&(ab[7]<=57)))&&((ab[8]==null)||((ab[8]>=48)&&(ab[8]<=57)))&&((ab[9]==null)||((ab[9]>=48)&&(ab[9]<=57)))&&((ab[10]==null)||((ab[10]>=48)&&(ab[10]<=57)))&&((ab[11]==null)||((ab[11]>=48)&&(ab[11]<=57)))&&((ab[12]==null)||((ab[12]>=48)&&(ab[12]<=57)))&&((ab[13]==null)||((ab[13]>=48)&&(ab[13]<=57)))&&((ab[14]==null)||((ab[14]>=48)&&(ab[14]<=57)))&&((ab[15]==null)||((ab[15]>=48)&&(ab[15]<=57)))&&((ab[16]==null)||((ab[16]>=48)&&(ab[16]<=57)))&&((ab[17]==null)||((ab[17]>=48)&&(ab[17]<=57))))
86
}}}
87
소수점 아래 자리에 입력한 부분이 문제가 있으면 오류코드 7번(소수점 아랫자리 오류)를 반환합니다.
88
{{{#!if br=ts?br:true, ea=ts?0:7
89
}}}}}}
90
91
이와 같은 방법으로 b도 bu를 tm으로 복제하는 과정을 포함하여 유효성 검사를 실행합니다. 오류코드는 동일합니다.
92
a와 b를 각각 진단해야 하므로 br를 false로 초기화합니다.
93
{{{#!if br=false, ts=(bs.indexOf(".")==bs.lastIndexOf(".")), br=ts?br:true, eb=ts?0:5
94
}}}
95
{{{#!if ts&&!br
53
}}}}}}{{{#!if ts=(((ab[0]==null)||((ab[0]>=48)&&(ab[0]<=57)))&&((ab[1]==null)||((ab[1]>=48)&&(ab[1]<=57)))&&((ab[2]==null)||((ab[2]>=48)&&(ab[2]<=57)))&&((ab[3]==null)||((ab[3]>=48)&&(ab[3]<=57)))&&((ab[4]==null)||((ab[4]>=48)&&(ab[4]<=57)))&&((ab[5]==null)||((ab[5]>=48)&&(ab[5]<=57)))&&((ab[6]==null)||((ab[6]>=48)&&(ab[6]<=57)))&&((ab[7]==null)||((ab[7]>=48)&&(ab[7]<=57)))&&((ab[8]==null)||((ab[8]>=48)&&(ab[8]<=57)))&&((ab[9]==null)||((ab[9]>=48)&&(ab[9]<=57)))&&((ab[10]==null)||((ab[10]>=48)&&(ab[10]<=57)))&&((ab[11]==null)||((ab[11]>=48)&&(ab[11]<=57)))&&((ab[12]==null)||((ab[12]>=48)&&(ab[12]<=57)))&&((ab[13]==null)||((ab[13]>=48)&&(ab[13]<=57)))&&((ab[14]==null)||((ab[14]>=48)&&(ab[14]<=57)))&&((ab[15]==null)||((ab[15]>=48)&&(ab[15]<=57)))&&((ab[16]==null)||((ab[16]>=48)&&(ab[16]<=57)))&&((ab[17]==null)||((ab[17]>=48)&&(ab[17]<=57)))), br=ts?br:true, ea=ts?0:7
54
}}}}}}{{{#!if br=false, ts=(bs.indexOf(".")==bs.lastIndexOf(".")), br=ts?br:true, eb=ts?0:5
55
}}}{{{#!if ts&&!br
9656
{{{#!if tm=(bu[0]==45)?bu.substr(1):bu, ts=(tm.length<=18), br=ts?br:true, eb=ts?0:1
97
}}}}}}
98
{{{#!if ts&&!br
57
}}}}}}{{{#!if ts&&!br
9958
{{{#!if tm="1"+tm, tn=+tm, tn=tn.toString(), ts=(tm==tn), br=ts?br:true, eb=ts?0:6
100
}}}}}}
101
{{{#!if ts&&!br
59
}}}}}}{{{#!if ts&&!br
10260
{{{#!if bb.length>=19
10361
{{{#!if wb=1, bb=bb.substr(0,18), bp=18
10462
}}}}}}{{{#!if ts=(((bb[0]==null)||((bb[0]>=48)&&(bb[0]<=57)))&&((bb[1]==null)||((bb[1]>=48)&&(bb[1]<=57)))&&((bb[2]==null)||((bb[2]>=48)&&(bb[2]<=57)))&&((bb[3]==null)||((bb[3]>=48)&&(bb[3]<=57)))&&((bb[4]==null)||((bb[4]>=48)&&(bb[4]<=57)))&&((bb[5]==null)||((bb[5]>=48)&&(bb[5]<=57)))&&((bb[6]==null)||((bb[6]>=48)&&(bb[6]<=57)))&&((bb[7]==null)||((bb[7]>=48)&&(bb[7]<=57)))&&((bb[8]==null)||((bb[8]>=48)&&(bb[8]<=57)))&&((bb[9]==null)||((bb[9]>=48)&&(bb[9]<=57)))&&((bb[10]==null)||((bb[10]>=48)&&(bb[10]<=57)))&&((bb[11]==null)||((bb[11]>=48)&&(bb[11]<=57)))&&((bb[12]==null)||((bb[12]>=48)&&(bb[12]<=57)))&&((bb[13]==null)||((bb[13]>=48)&&(bb[13]<=57)))&&((bb[14]==null)||((bb[14]>=48)&&(bb[14]<=57)))&&((bb[15]==null)||((bb[15]>=48)&&(bb[15]<=57)))&&((bb[16]==null)||((bb[16]>=48)&&(bb[16]<=57)))&&((bb[17]==null)||((bb[17]>=48)&&(bb[17]<=57)))), br=ts?br:true, eb=ts?0:7
......