다양화 Wave2: dbio 289 + common 120 고유화 + 프로그램 206개 EXEC SQL 심화
- dbio io(289): fetch/touch/total 시그니처 유지, SQL 바디를 JOIN/집계/커서/ upsert/DELETE 등 구조로 고유화 → 289/289 고유 - common cu(120): 유틸 시그니처 유지, Luhn/CRC/Zeller/BIN레인지/amortization/ netting 등 실 알고리즘으로 고유화 → 120/120 고유 - 심화: 실제 EXEC SQL 없던 프로그램에 SELECT/INSERT/UPDATE/커서+tx 추가 → online+batch 530/530 전부 실제 SQL 보유 - 전 코퍼스 프로그램 939/939 고유, 전체 docker make -j4 = EXIT 0, 958 오브젝트 - 임시 생성기 제거, inventory.json loc 실측 갱신 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c3a0259e95
commit
93c3cb74af
1111 changed files with 31539 additions and 17258 deletions
|
|
@ -100,9 +100,32 @@ struct sqlca_t *ECPGget_sqlca(void);
|
||||||
|
|
||||||
static int run_cm_bt_0015(const char *biz_date)
|
static int run_cm_bt_0015(const char *biz_date)
|
||||||
{
|
{
|
||||||
|
/* exec sql begin declare section */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#line 26 "app/batch/cm_bt_0015.pgc"
|
||||||
|
char h_biz_date [ 9 ] ;
|
||||||
|
|
||||||
|
#line 27 "app/batch/cm_bt_0015.pgc"
|
||||||
|
char h_merch_id [ 16 ] ;
|
||||||
|
|
||||||
|
#line 28 "app/batch/cm_bt_0015.pgc"
|
||||||
|
long h_merch_cnt ;
|
||||||
|
|
||||||
|
#line 29 "app/batch/cm_bt_0015.pgc"
|
||||||
|
long h_merch_sum ;
|
||||||
|
/* exec sql end declare section */
|
||||||
|
#line 30 "app/batch/cm_bt_0015.pgc"
|
||||||
|
|
||||||
|
|
||||||
long n_recv, n_done, n_fail, n_settled, total;
|
long n_recv, n_done, n_fail, n_settled, total;
|
||||||
long sum_amt = 0;
|
long sum_amt = 0;
|
||||||
|
long merch_lines = 0;
|
||||||
char won[32];
|
char won[32];
|
||||||
|
char merch_won[32];
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
n_recv = cm_rec_count(biz_date, CM_ST_RECV);
|
n_recv = cm_rec_count(biz_date, CM_ST_RECV);
|
||||||
|
|
@ -139,6 +162,57 @@ static int run_cm_bt_0015(const char *biz_date)
|
||||||
printf(" 거래총액 : %s\n", won);
|
printf(" 거래총액 : %s\n", won);
|
||||||
if (total > 0)
|
if (total > 0)
|
||||||
printf(" 완료율 : %ld%%\n", (n_done * 100) / total);
|
printf(" 완료율 : %ld%%\n", (n_done * 100) / total);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 가맹점별 상세 브레이크다운: cm_ledger 를 가맹점번호로 그룹집계하는
|
||||||
|
* 커서를 순회하며 건수 내림차순으로 상위 가맹점을 리포트한다.
|
||||||
|
*/
|
||||||
|
strncpy(h_biz_date, biz_date, sizeof(h_biz_date) - 1);
|
||||||
|
h_biz_date[sizeof(h_biz_date) - 1] = '\0';
|
||||||
|
|
||||||
|
ECPGset_var( 0, ( h_biz_date ), __LINE__);\
|
||||||
|
/* declare cur_cm_bt_0015 cursor for select merch_id , count ( * ) , coalesce ( sum ( amount ) , 0 ) from cm_ledger where biz_date = $1 group by merch_id order by count ( * ) desc , merch_id */
|
||||||
|
#line 86 "app/batch/cm_bt_0015.pgc"
|
||||||
|
|
||||||
|
#line 86 "app/batch/cm_bt_0015.pgc"
|
||||||
|
|
||||||
|
|
||||||
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur_cm_bt_0015 cursor for select merch_id , count ( * ) , coalesce ( sum ( amount ) , 0 ) from cm_ledger where biz_date = $1 group by merch_id order by count ( * ) desc , merch_id",
|
||||||
|
ECPGt_char,(h_biz_date),(long)9,(long)1,(9)*sizeof(char),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
|
||||||
|
#line 88 "app/batch/cm_bt_0015.pgc"
|
||||||
|
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
||||||
|
TX_DBIO_LOG_ERR("cm_bt_0015 OPEN cur");
|
||||||
|
} else {
|
||||||
|
printf(" ----- 가맹점별 상세 -----\n");
|
||||||
|
for (;;) {
|
||||||
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur_cm_bt_0015", ECPGt_EOIT,
|
||||||
|
ECPGt_char,(h_merch_id),(long)16,(long)1,(16)*sizeof(char),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||||
|
ECPGt_long,&(h_merch_cnt),(long)1,(long)1,sizeof(long),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||||
|
ECPGt_long,&(h_merch_sum),(long)1,(long)1,sizeof(long),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
|
||||||
|
#line 95 "app/batch/cm_bt_0015.pgc"
|
||||||
|
|
||||||
|
|
||||||
|
if (sqlca.sqlcode == TX_SQL_NOTFOUND)
|
||||||
|
break;
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
||||||
|
TX_DBIO_LOG_ERR("cm_bt_0015 FETCH cur");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
merch_lines++;
|
||||||
|
amount_format_won(h_merch_sum, merch_won, sizeof(merch_won));
|
||||||
|
printf(" %-12s 건수=%-6ld 금액=%s\n",
|
||||||
|
h_merch_id, h_merch_cnt, merch_won);
|
||||||
|
}
|
||||||
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur_cm_bt_0015", ECPGt_EOIT, ECPGt_EORT);}
|
||||||
|
#line 108 "app/batch/cm_bt_0015.pgc"
|
||||||
|
|
||||||
|
}
|
||||||
|
printf(" 가맹점 수 : %ld\n", merch_lines);
|
||||||
printf("=============================================\n");
|
printf("=============================================\n");
|
||||||
|
|
||||||
return TX_OK;
|
return TX_OK;
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,18 @@ EXEC SQL INCLUDE sqlca;
|
||||||
|
|
||||||
static int run_cm_bt_0015(const char *biz_date)
|
static int run_cm_bt_0015(const char *biz_date)
|
||||||
{
|
{
|
||||||
|
EXEC SQL BEGIN DECLARE SECTION;
|
||||||
|
char h_biz_date[9];
|
||||||
|
char h_merch_id[16];
|
||||||
|
long h_merch_cnt;
|
||||||
|
long h_merch_sum;
|
||||||
|
EXEC SQL END DECLARE SECTION;
|
||||||
|
|
||||||
long n_recv, n_done, n_fail, n_settled, total;
|
long n_recv, n_done, n_fail, n_settled, total;
|
||||||
long sum_amt = 0;
|
long sum_amt = 0;
|
||||||
|
long merch_lines = 0;
|
||||||
char won[32];
|
char won[32];
|
||||||
|
char merch_won[32];
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
n_recv = cm_rec_count(biz_date, CM_ST_RECV);
|
n_recv = cm_rec_count(biz_date, CM_ST_RECV);
|
||||||
|
|
@ -61,6 +70,44 @@ static int run_cm_bt_0015(const char *biz_date)
|
||||||
printf(" 거래총액 : %s\n", won);
|
printf(" 거래총액 : %s\n", won);
|
||||||
if (total > 0)
|
if (total > 0)
|
||||||
printf(" 완료율 : %ld%%\n", (n_done * 100) / total);
|
printf(" 완료율 : %ld%%\n", (n_done * 100) / total);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 가맹점별 상세 브레이크다운: cm_ledger 를 가맹점번호로 그룹집계하는
|
||||||
|
* 커서를 순회하며 건수 내림차순으로 상위 가맹점을 리포트한다.
|
||||||
|
*/
|
||||||
|
strncpy(h_biz_date, biz_date, sizeof(h_biz_date) - 1);
|
||||||
|
h_biz_date[sizeof(h_biz_date) - 1] = '\0';
|
||||||
|
|
||||||
|
EXEC SQL DECLARE cur_cm_bt_0015 CURSOR FOR
|
||||||
|
SELECT merch_id, count(*), coalesce(sum(amount), 0)
|
||||||
|
FROM cm_ledger
|
||||||
|
WHERE biz_date = :h_biz_date
|
||||||
|
GROUP BY merch_id
|
||||||
|
ORDER BY count(*) DESC, merch_id;
|
||||||
|
|
||||||
|
EXEC SQL OPEN cur_cm_bt_0015;
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
||||||
|
TX_DBIO_LOG_ERR("cm_bt_0015 OPEN cur");
|
||||||
|
} else {
|
||||||
|
printf(" ----- 가맹점별 상세 -----\n");
|
||||||
|
for (;;) {
|
||||||
|
EXEC SQL FETCH cur_cm_bt_0015
|
||||||
|
INTO :h_merch_id, :h_merch_cnt, :h_merch_sum;
|
||||||
|
|
||||||
|
if (sqlca.sqlcode == TX_SQL_NOTFOUND)
|
||||||
|
break;
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
||||||
|
TX_DBIO_LOG_ERR("cm_bt_0015 FETCH cur");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
merch_lines++;
|
||||||
|
amount_format_won(h_merch_sum, merch_won, sizeof(merch_won));
|
||||||
|
printf(" %-12s 건수=%-6ld 금액=%s\n",
|
||||||
|
h_merch_id, h_merch_cnt, merch_won);
|
||||||
|
}
|
||||||
|
EXEC SQL CLOSE cur_cm_bt_0015;
|
||||||
|
}
|
||||||
|
printf(" 가맹점 수 : %ld\n", merch_lines);
|
||||||
printf("=============================================\n");
|
printf("=============================================\n");
|
||||||
|
|
||||||
return TX_OK;
|
return TX_OK;
|
||||||
|
|
|
||||||
|
|
@ -107,12 +107,37 @@ static long mg_pct_x10(long part, long whole)
|
||||||
|
|
||||||
static int run_mg_bt_0005(const char *biz_date)
|
static int run_mg_bt_0005(const char *biz_date)
|
||||||
{
|
{
|
||||||
|
/* exec sql begin declare section */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#line 33 "app/batch/mg_bt_0005.pgc"
|
||||||
|
char h_bd [ 9 ] ;
|
||||||
|
|
||||||
|
#line 34 "app/batch/mg_bt_0005.pgc"
|
||||||
|
char h_merch [ 16 ] ;
|
||||||
|
|
||||||
|
#line 35 "app/batch/mg_bt_0005.pgc"
|
||||||
|
long h_mcnt ;
|
||||||
|
|
||||||
|
#line 36 "app/batch/mg_bt_0005.pgc"
|
||||||
|
long h_msum ;
|
||||||
|
/* exec sql end declare section */
|
||||||
|
#line 37 "app/batch/mg_bt_0005.pgc"
|
||||||
|
|
||||||
|
|
||||||
long c_recv, c_done, c_fail, c_settled, total;
|
long c_recv, c_done, c_fail, c_settled, total;
|
||||||
long sum_amt = 0;
|
long sum_amt = 0;
|
||||||
long rate;
|
long rate;
|
||||||
int rc;
|
int rc;
|
||||||
|
int shown;
|
||||||
char amtbuf[32];
|
char amtbuf[32];
|
||||||
|
|
||||||
|
strncpy(h_bd, biz_date, sizeof(h_bd) - 1);
|
||||||
|
h_bd[sizeof(h_bd) - 1] = '\0';
|
||||||
|
|
||||||
c_recv = mg_rec_count(biz_date, MG_ST_RECV);
|
c_recv = mg_rec_count(biz_date, MG_ST_RECV);
|
||||||
c_done = mg_rec_count(biz_date, MG_ST_DONE);
|
c_done = mg_rec_count(biz_date, MG_ST_DONE);
|
||||||
c_fail = mg_rec_count(biz_date, MG_ST_FAIL);
|
c_fail = mg_rec_count(biz_date, MG_ST_FAIL);
|
||||||
|
|
@ -149,6 +174,55 @@ static int run_mg_bt_0005(const char *biz_date)
|
||||||
printf(" 처리율 : %ld.%ld%%\n", rate / 10, rate % 10);
|
printf(" 처리율 : %ld.%ld%%\n", rate / 10, rate % 10);
|
||||||
printf("=============================================\n");
|
printf("=============================================\n");
|
||||||
|
|
||||||
|
/* 가맹점별 거래 상위 내역을 커서로 순회하여 부가 리포트 출력 */
|
||||||
|
ECPGset_var( 0, ( h_bd ), __LINE__);\
|
||||||
|
/* declare cur_mg_bt_0005 cursor for select merch_id , count ( * ) , coalesce ( SUM ( amount ) , 0 ) from mg_ledger where biz_date = $1 group by merch_id order by 3 desc */
|
||||||
|
#line 91 "app/batch/mg_bt_0005.pgc"
|
||||||
|
|
||||||
|
#line 91 "app/batch/mg_bt_0005.pgc"
|
||||||
|
|
||||||
|
|
||||||
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "declare cur_mg_bt_0005 cursor for select merch_id , count ( * ) , coalesce ( SUM ( amount ) , 0 ) from mg_ledger where biz_date = $1 group by merch_id order by 3 desc",
|
||||||
|
ECPGt_char,(h_bd),(long)9,(long)1,(9)*sizeof(char),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);}
|
||||||
|
#line 93 "app/batch/mg_bt_0005.pgc"
|
||||||
|
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
||||||
|
TX_DBIO_LOG_ERR("OPEN cur_mg_bt_0005");
|
||||||
|
return TX_OK; /* 부가 리포트 실패는 배치 성공에 영향 없음 */
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("---------- 가맹점별 거래 상위 (mg_bt_0005) ----------\n");
|
||||||
|
shown = 0;
|
||||||
|
for (;;) {
|
||||||
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur_mg_bt_0005", ECPGt_EOIT,
|
||||||
|
ECPGt_char,(h_merch),(long)16,(long)1,(16)*sizeof(char),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||||
|
ECPGt_long,&(h_mcnt),(long)1,(long)1,sizeof(long),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||||
|
ECPGt_long,&(h_msum),(long)1,(long)1,sizeof(long),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
|
||||||
|
#line 102 "app/batch/mg_bt_0005.pgc"
|
||||||
|
|
||||||
|
if (sqlca.sqlcode == TX_SQL_NOTFOUND)
|
||||||
|
break;
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
||||||
|
TX_DBIO_LOG_ERR("FETCH cur_mg_bt_0005");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (shown < 10) {
|
||||||
|
amount_format_won(h_msum, amtbuf, sizeof(amtbuf));
|
||||||
|
printf(" %-14s 건수=%-6ld 금액=%s\n", h_merch, h_mcnt, amtbuf);
|
||||||
|
}
|
||||||
|
shown++;
|
||||||
|
}
|
||||||
|
printf(" (가맹점 수: %d)\n", shown);
|
||||||
|
printf("=============================================\n");
|
||||||
|
|
||||||
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "close cur_mg_bt_0005", ECPGt_EOIT, ECPGt_EORT);}
|
||||||
|
#line 118 "app/batch/mg_bt_0005.pgc"
|
||||||
|
|
||||||
|
|
||||||
return TX_OK;
|
return TX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,23 @@ static long mg_pct_x10(long part, long whole)
|
||||||
|
|
||||||
static int run_mg_bt_0005(const char *biz_date)
|
static int run_mg_bt_0005(const char *biz_date)
|
||||||
{
|
{
|
||||||
|
EXEC SQL BEGIN DECLARE SECTION;
|
||||||
|
char h_bd[9];
|
||||||
|
char h_merch[16];
|
||||||
|
long h_mcnt;
|
||||||
|
long h_msum;
|
||||||
|
EXEC SQL END DECLARE SECTION;
|
||||||
|
|
||||||
long c_recv, c_done, c_fail, c_settled, total;
|
long c_recv, c_done, c_fail, c_settled, total;
|
||||||
long sum_amt = 0;
|
long sum_amt = 0;
|
||||||
long rate;
|
long rate;
|
||||||
int rc;
|
int rc;
|
||||||
|
int shown;
|
||||||
char amtbuf[32];
|
char amtbuf[32];
|
||||||
|
|
||||||
|
strncpy(h_bd, biz_date, sizeof(h_bd) - 1);
|
||||||
|
h_bd[sizeof(h_bd) - 1] = '\0';
|
||||||
|
|
||||||
c_recv = mg_rec_count(biz_date, MG_ST_RECV);
|
c_recv = mg_rec_count(biz_date, MG_ST_RECV);
|
||||||
c_done = mg_rec_count(biz_date, MG_ST_DONE);
|
c_done = mg_rec_count(biz_date, MG_ST_DONE);
|
||||||
c_fail = mg_rec_count(biz_date, MG_ST_FAIL);
|
c_fail = mg_rec_count(biz_date, MG_ST_FAIL);
|
||||||
|
|
@ -71,6 +82,41 @@ static int run_mg_bt_0005(const char *biz_date)
|
||||||
printf(" 처리율 : %ld.%ld%%\n", rate / 10, rate % 10);
|
printf(" 처리율 : %ld.%ld%%\n", rate / 10, rate % 10);
|
||||||
printf("=============================================\n");
|
printf("=============================================\n");
|
||||||
|
|
||||||
|
/* 가맹점별 거래 상위 내역을 커서로 순회하여 부가 리포트 출력 */
|
||||||
|
EXEC SQL DECLARE cur_mg_bt_0005 CURSOR FOR
|
||||||
|
SELECT merch_id, COUNT(*), COALESCE(SUM(amount), 0)
|
||||||
|
FROM mg_ledger
|
||||||
|
WHERE biz_date = :h_bd
|
||||||
|
GROUP BY merch_id
|
||||||
|
ORDER BY 3 DESC;
|
||||||
|
|
||||||
|
EXEC SQL OPEN cur_mg_bt_0005;
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
||||||
|
TX_DBIO_LOG_ERR("OPEN cur_mg_bt_0005");
|
||||||
|
return TX_OK; /* 부가 리포트 실패는 배치 성공에 영향 없음 */
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("---------- 가맹점별 거래 상위 (mg_bt_0005) ----------\n");
|
||||||
|
shown = 0;
|
||||||
|
for (;;) {
|
||||||
|
EXEC SQL FETCH cur_mg_bt_0005 INTO :h_merch, :h_mcnt, :h_msum;
|
||||||
|
if (sqlca.sqlcode == TX_SQL_NOTFOUND)
|
||||||
|
break;
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK) {
|
||||||
|
TX_DBIO_LOG_ERR("FETCH cur_mg_bt_0005");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (shown < 10) {
|
||||||
|
amount_format_won(h_msum, amtbuf, sizeof(amtbuf));
|
||||||
|
printf(" %-14s 건수=%-6ld 금액=%s\n", h_merch, h_mcnt, amtbuf);
|
||||||
|
}
|
||||||
|
shown++;
|
||||||
|
}
|
||||||
|
printf(" (가맹점 수: %d)\n", shown);
|
||||||
|
printf("=============================================\n");
|
||||||
|
|
||||||
|
EXEC SQL CLOSE cur_mg_bt_0005;
|
||||||
|
|
||||||
return TX_OK;
|
return TX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,11 +101,35 @@ struct sqlca_t *ECPGget_sqlca(void);
|
||||||
|
|
||||||
static int run_rc_bt_0006(const char *biz_date)
|
static int run_rc_bt_0006(const char *biz_date)
|
||||||
{
|
{
|
||||||
|
/* exec sql begin declare section */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#line 27 "app/batch/rc_bt_0006.pgc"
|
||||||
|
char h_bd [ 9 ] ;
|
||||||
|
|
||||||
|
#line 28 "app/batch/rc_bt_0006.pgc"
|
||||||
|
long h_db_total ;
|
||||||
|
|
||||||
|
#line 29 "app/batch/rc_bt_0006.pgc"
|
||||||
|
long h_db_unmatch ;
|
||||||
|
|
||||||
|
#line 30 "app/batch/rc_bt_0006.pgc"
|
||||||
|
long h_db_sum ;
|
||||||
|
/* exec sql end declare section */
|
||||||
|
#line 31 "app/batch/rc_bt_0006.pgc"
|
||||||
|
|
||||||
|
|
||||||
long cntR, cntM, cntU, cntS;
|
long cntR, cntM, cntU, cntS;
|
||||||
long total, processed;
|
long total, processed;
|
||||||
long proc_rate, settle_rate, fail_rate;
|
long proc_rate, settle_rate, fail_rate;
|
||||||
int mismatch;
|
int mismatch;
|
||||||
|
|
||||||
|
strncpy(h_bd, biz_date, sizeof(h_bd) - 1);
|
||||||
|
h_bd[sizeof(h_bd) - 1] = '\0';
|
||||||
|
|
||||||
/* 상태별 건수 조회 (읽기전용) */
|
/* 상태별 건수 조회 (읽기전용) */
|
||||||
cntR = rc_rec_count(biz_date, RC_ST_RECV);
|
cntR = rc_rec_count(biz_date, RC_ST_RECV);
|
||||||
cntM = rc_rec_count(biz_date, RC_ST_DONE);
|
cntM = rc_rec_count(biz_date, RC_ST_DONE);
|
||||||
|
|
@ -166,6 +190,47 @@ static int run_rc_bt_0006(const char *biz_date)
|
||||||
printf(" 미처리 여부 : %s\n", mismatch ? "미처리(접수 잔량)" : "완료");
|
printf(" 미처리 여부 : %s\n", mismatch ? "미처리(접수 잔량)" : "완료");
|
||||||
printf("===============================================\n");
|
printf("===============================================\n");
|
||||||
|
|
||||||
|
/* 원장에서 직접 총건수/불일치건수/총금액을 임베디드 SQL 로 교차집계 */
|
||||||
|
h_db_total = 0;
|
||||||
|
h_db_unmatch = 0;
|
||||||
|
h_db_sum = 0;
|
||||||
|
|
||||||
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select count ( * ) , coalesce ( SUM ( amount ) , 0 ) from rc_ledger where biz_date = $1 ",
|
||||||
|
ECPGt_char,(h_bd),(long)9,(long)1,(9)*sizeof(char),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
|
||||||
|
ECPGt_long,&(h_db_total),(long)1,(long)1,sizeof(long),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||||
|
ECPGt_long,&(h_db_sum),(long)1,(long)1,sizeof(long),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
|
||||||
|
#line 109 "app/batch/rc_bt_0006.pgc"
|
||||||
|
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
|
||||||
|
TX_DBIO_LOG_ERR("SELECT rc_ledger dbtotal (rc_bt_0006)");
|
||||||
|
return TX_EDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select count ( * ) from rc_ledger where biz_date = $1 and status = 'U'",
|
||||||
|
ECPGt_char,(h_bd),(long)9,(long)1,(9)*sizeof(char),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
|
||||||
|
ECPGt_long,&(h_db_unmatch),(long)1,(long)1,sizeof(long),
|
||||||
|
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}
|
||||||
|
#line 119 "app/batch/rc_bt_0006.pgc"
|
||||||
|
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
|
||||||
|
TX_DBIO_LOG_ERR("SELECT rc_ledger unmatch (rc_bt_0006)");
|
||||||
|
return TX_EDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("------- 원장 직접 교차집계 (rc_bt_0006) -------\n");
|
||||||
|
printf(" DB 총건수 : %ld\n", h_db_total);
|
||||||
|
printf(" DB 불일치건수 : %ld\n", h_db_unmatch);
|
||||||
|
printf(" DB 총금액 : %ld\n", h_db_sum);
|
||||||
|
if (h_db_total != total)
|
||||||
|
tx_log(TX_LOG_WARN,
|
||||||
|
"[rc_bt_0006] 집계 교차검증 상이 count=%ld db=%ld",
|
||||||
|
total, h_db_total);
|
||||||
|
printf("===============================================\n");
|
||||||
|
|
||||||
return TX_OK;
|
return TX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,21 @@ EXEC SQL INCLUDE sqlca;
|
||||||
|
|
||||||
static int run_rc_bt_0006(const char *biz_date)
|
static int run_rc_bt_0006(const char *biz_date)
|
||||||
{
|
{
|
||||||
|
EXEC SQL BEGIN DECLARE SECTION;
|
||||||
|
char h_bd[9];
|
||||||
|
long h_db_total;
|
||||||
|
long h_db_unmatch;
|
||||||
|
long h_db_sum;
|
||||||
|
EXEC SQL END DECLARE SECTION;
|
||||||
|
|
||||||
long cntR, cntM, cntU, cntS;
|
long cntR, cntM, cntU, cntS;
|
||||||
long total, processed;
|
long total, processed;
|
||||||
long proc_rate, settle_rate, fail_rate;
|
long proc_rate, settle_rate, fail_rate;
|
||||||
int mismatch;
|
int mismatch;
|
||||||
|
|
||||||
|
strncpy(h_bd, biz_date, sizeof(h_bd) - 1);
|
||||||
|
h_bd[sizeof(h_bd) - 1] = '\0';
|
||||||
|
|
||||||
/* 상태별 건수 조회 (읽기전용) */
|
/* 상태별 건수 조회 (읽기전용) */
|
||||||
cntR = rc_rec_count(biz_date, RC_ST_RECV);
|
cntR = rc_rec_count(biz_date, RC_ST_RECV);
|
||||||
cntM = rc_rec_count(biz_date, RC_ST_DONE);
|
cntM = rc_rec_count(biz_date, RC_ST_DONE);
|
||||||
|
|
@ -88,6 +98,40 @@ static int run_rc_bt_0006(const char *biz_date)
|
||||||
printf(" 미처리 여부 : %s\n", mismatch ? "미처리(접수 잔량)" : "완료");
|
printf(" 미처리 여부 : %s\n", mismatch ? "미처리(접수 잔량)" : "완료");
|
||||||
printf("===============================================\n");
|
printf("===============================================\n");
|
||||||
|
|
||||||
|
/* 원장에서 직접 총건수/불일치건수/총금액을 임베디드 SQL 로 교차집계 */
|
||||||
|
h_db_total = 0;
|
||||||
|
h_db_unmatch = 0;
|
||||||
|
h_db_sum = 0;
|
||||||
|
|
||||||
|
EXEC SQL SELECT COUNT(*), COALESCE(SUM(amount), 0)
|
||||||
|
INTO :h_db_total, :h_db_sum
|
||||||
|
FROM rc_ledger
|
||||||
|
WHERE biz_date = :h_bd;
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
|
||||||
|
TX_DBIO_LOG_ERR("SELECT rc_ledger dbtotal (rc_bt_0006)");
|
||||||
|
return TX_EDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXEC SQL SELECT COUNT(*)
|
||||||
|
INTO :h_db_unmatch
|
||||||
|
FROM rc_ledger
|
||||||
|
WHERE biz_date = :h_bd
|
||||||
|
AND status = 'U';
|
||||||
|
if (sqlca.sqlcode != TX_SQL_OK && sqlca.sqlcode != TX_SQL_NOTFOUND) {
|
||||||
|
TX_DBIO_LOG_ERR("SELECT rc_ledger unmatch (rc_bt_0006)");
|
||||||
|
return TX_EDB;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("------- 원장 직접 교차집계 (rc_bt_0006) -------\n");
|
||||||
|
printf(" DB 총건수 : %ld\n", h_db_total);
|
||||||
|
printf(" DB 불일치건수 : %ld\n", h_db_unmatch);
|
||||||
|
printf(" DB 총금액 : %ld\n", h_db_sum);
|
||||||
|
if (h_db_total != total)
|
||||||
|
tx_log(TX_LOG_WARN,
|
||||||
|
"[rc_bt_0006] 집계 교차검증 상이 count=%ld db=%ld",
|
||||||
|
total, h_db_total);
|
||||||
|
printf("===============================================\n");
|
||||||
|
|
||||||
return TX_OK;
|
return TX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,49 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* CRC-8(다항식 0x07) 계산: 고정길이 필드 무결성 */
|
||||||
|
static unsigned ac_cu_0001_crc8(const char *s, int n)
|
||||||
|
{
|
||||||
|
unsigned crc = 0;
|
||||||
|
int i, b;
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
crc ^= (unsigned char)s[i];
|
||||||
|
for (b = 0; b < 8; b++)
|
||||||
|
crc = (crc & 0x80) ? ((crc << 1) ^ 0x07) & 0xFF : (crc << 1) & 0xFF;
|
||||||
|
}
|
||||||
|
return crc & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 금액을 12자리 고정필드로 pack 후 CRC 가산 */
|
||||||
long ac_cu_0001_fee(long amount, int rate_bp)
|
long ac_cu_0001_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
char buf[16];
|
||||||
|
long v = amount < 0 ? 0 : amount;
|
||||||
|
int i;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 11; i >= 0; i--) { buf[i] = (char)('0' + (int)(v % 10)); v /= 10; }
|
||||||
if (fee < 0)
|
buf[12] = '\0';
|
||||||
fee = 0;
|
return (amount * (long)rate_bp) / 10000L + (long)ac_cu_0001_crc8(buf, 12);
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최근접 배수 반올림(round-half-away-from-zero) */
|
||||||
long ac_cu_0001_round_unit(long amount, long unit)
|
long ac_cu_0001_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r, h;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
h = (unit + 1) / 2;
|
||||||
|
if (r < 0)
|
||||||
|
return (-r >= h) ? amount - (unit + r) : amount - r;
|
||||||
|
return (r >= h) ? amount + (unit - r) : amount - r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 부호·홀짝 조합 4가지 */
|
||||||
int ac_cu_0001_classify(long amount)
|
int ac_cu_0001_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int s = amount < 0 ? 2 : 0;
|
||||||
return 0;
|
int p = (amount % 2 != 0) ? 1 : 0;
|
||||||
if (amount < 1000000L)
|
return s + p;
|
||||||
return 1;
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,39 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 수수료: 12개월 균등분할 잔액에 대한 단리 이자 합 */
|
||||||
long ac_cu_0002_fee(long amount, int rate_bp)
|
long ac_cu_0002_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long total = 0, principal;
|
||||||
|
int m;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
principal = amount / 12;
|
||||||
if (fee < 0)
|
for (m = 1; m <= 12; m++) {
|
||||||
fee = 0;
|
long bal = amount - principal * (m - 1);
|
||||||
return fee;
|
total += bal * (long)rate_bp / 120000L;
|
||||||
|
}
|
||||||
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 잔돈 재분배 반올림: 잔여의 2배가 unit 이상이면 올림 */
|
||||||
long ac_cu_0002_round_unit(long amount, long unit)
|
long ac_cu_0002_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long base, rem;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
base = (amount / unit) * unit;
|
||||||
|
rem = amount - base;
|
||||||
|
return (rem * 2 >= unit) ? base + unit : base;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 최상위(선두) 숫자 1~9 */
|
||||||
int ac_cu_0002_classify(long amount)
|
int ac_cu_0002_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
while (v >= 10)
|
||||||
return 1;
|
v /= 10;
|
||||||
return 2;
|
return (int)v;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,33 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 수수료: 소수 2자리 스케일로 확대 후 요율 적용, 원 단위 복귀 */
|
||||||
long ac_cu_0003_fee(long amount, int rate_bp)
|
long ac_cu_0003_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long scaled, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
scaled = amount * 100L;
|
||||||
if (fee < 0)
|
fee = scaled * (long)rate_bp / 10000L;
|
||||||
fee = 0;
|
return fee / 100L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 단위가 2의 거듭제곱이면 비트마스크 정렬, 아니면 일반 절사 */
|
||||||
long ac_cu_0003_round_unit(long amount, long unit)
|
long ac_cu_0003_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
|
if ((unit & (unit - 1)) == 0)
|
||||||
|
return amount & ~(unit - 1);
|
||||||
return (amount / unit) * unit;
|
return (amount / unit) * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 금액 구간 비트맵 플래그(bit0=만,bit1=십만,bit2=백만) */
|
||||||
int ac_cu_0003_classify(long amount)
|
int ac_cu_0003_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int f = 0;
|
||||||
return 0;
|
if (amount >= 10000L) f |= 1;
|
||||||
if (amount < 1000000L)
|
if (amount >= 100000L) f |= 2;
|
||||||
return 1;
|
if (amount >= 1000000L) f |= 4;
|
||||||
return 2;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 수수료: 금액 구간별 요율을 선형보간하여 적용 */
|
||||||
long ac_cu_0004_fee(long amount, int rate_bp)
|
long ac_cu_0004_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
static const long x[4] = {0L, 100000L, 1000000L, 10000000L};
|
||||||
if (amount <= 0 || rate_bp < 0)
|
static const long y[4] = {30L, 20L, 10L, 5L};
|
||||||
|
long r = rate_bp;
|
||||||
|
int i;
|
||||||
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 0; i < 3; i++) {
|
||||||
if (fee < 0)
|
if (amount <= x[i + 1]) {
|
||||||
fee = 0;
|
long span = x[i + 1] - x[i];
|
||||||
return fee;
|
r = y[i] + (y[i + 1] - y[i]) * (amount - x[i]) / span;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return amount * r / 10000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 5사6입: 잔여가 unit 의 60% 이상일 때만 올림 */
|
||||||
long ac_cu_0004_round_unit(long amount, long unit)
|
long ac_cu_0004_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
return (r * 10 >= unit * 6) ? amount + (unit - r) : amount - r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 이진탐색으로 경계 버킷 결정 */
|
||||||
int ac_cu_0004_classify(long amount)
|
int ac_cu_0004_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long b[7] = {5000L, 20000L, 50000L, 200000L,
|
||||||
return 0;
|
500000L, 2000000L, 5000000L};
|
||||||
if (amount < 1000000L)
|
int lo = 0, hi = 7, mid;
|
||||||
return 1;
|
while (lo < hi) {
|
||||||
return 2;
|
mid = (lo + hi) / 2;
|
||||||
|
if (amount < b[mid]) hi = mid; else lo = mid + 1;
|
||||||
|
}
|
||||||
|
return lo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,35 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 그레고리력 → 율리우스일수 근사 변환 */
|
||||||
long ac_cu_0005_fee(long amount, int rate_bp)
|
static long ac_cu_0005_jdn(int y, int m, int d)
|
||||||
{
|
{
|
||||||
long fee;
|
long a = (14 - m) / 12;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
long yy = y + 4800 - a;
|
||||||
return 0;
|
long mm = m + 12 * a - 3;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
return d + (153 * mm + 2) / 5 + 365 * yy + yy / 4 - yy / 100 + yy / 400 - 32045;
|
||||||
if (fee < 0)
|
|
||||||
fee = 0;
|
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 수수료: amount=YYYYMMDD 에 rate_bp 영업일 더한 율리우스일 반환 */
|
||||||
|
long ac_cu_0005_fee(long amount, int rate_bp)
|
||||||
|
{
|
||||||
|
int y, m, d, added = 0;
|
||||||
|
long jd;
|
||||||
|
if (amount <= 0)
|
||||||
|
return 0;
|
||||||
|
y = (int)(amount / 10000L);
|
||||||
|
m = (int)((amount / 100L) % 100L);
|
||||||
|
d = (int)(amount % 100L);
|
||||||
|
jd = ac_cu_0005_jdn(y, m, d);
|
||||||
|
while (added < rate_bp) {
|
||||||
|
jd++;
|
||||||
|
if (jd % 7 != 5 && jd % 7 != 6)
|
||||||
|
added++;
|
||||||
|
}
|
||||||
|
return jd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 0 방향 대칭 절사(truncate toward zero) */
|
||||||
long ac_cu_0005_round_unit(long amount, long unit)
|
long ac_cu_0005_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
|
|
@ -26,12 +42,15 @@ long ac_cu_0005_round_unit(long amount, long unit)
|
||||||
return (amount / unit) * unit;
|
return (amount / unit) * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: FNV-1a 해시의 하위 3비트 */
|
||||||
int ac_cu_0005_classify(long amount)
|
int ac_cu_0005_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
unsigned long h = 2166136261UL;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
do {
|
||||||
return 1;
|
h ^= (unsigned long)(v % 10);
|
||||||
return 2;
|
h *= 16777619UL;
|
||||||
|
v /= 10;
|
||||||
|
} while (v > 0);
|
||||||
|
return (int)(h & 0x7UL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 디지털 루트(각 자리 합 반복) 계산 */
|
||||||
|
static int ac_cu_0006_droot(long v)
|
||||||
|
{
|
||||||
|
if (v < 0) v = -v;
|
||||||
|
while (v >= 10) {
|
||||||
|
long s = 0;
|
||||||
|
while (v > 0) { s += v % 10; v /= 10; }
|
||||||
|
v = s;
|
||||||
|
}
|
||||||
|
return (int)v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 정률 계산 후 상한(cap) 적용 */
|
||||||
long ac_cu_0006_fee(long amount, int rate_bp)
|
long ac_cu_0006_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee, cap = 50000L;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
fee = amount * (long)rate_bp / 10000L;
|
||||||
if (fee < 0)
|
if (fee > cap)
|
||||||
fee = 0;
|
fee = cap;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 이중 절사: 1차 절사 후 잔여 2/3 이상이면 한 단위 보정 */
|
||||||
long ac_cu_0006_round_unit(long amount, long unit)
|
long ac_cu_0006_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long f1;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
f1 = (amount / unit) * unit;
|
||||||
|
if ((amount - f1) * 3 >= unit * 2)
|
||||||
|
f1 += unit;
|
||||||
|
return f1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 디지털 루트(1~9, 0) */
|
||||||
int ac_cu_0006_classify(long amount)
|
int ac_cu_0006_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
return ac_cu_0006_droot(amount);
|
||||||
return 0;
|
|
||||||
if (amount < 1000000L)
|
|
||||||
return 1;
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,49 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 슬랩(구간별 고정액) 수수료 테이블 조회 */
|
||||||
|
static long ac_cu_0007_slab(long a)
|
||||||
|
{
|
||||||
|
static const long lim[4] = {10000L, 100000L, 1000000L, 10000000L};
|
||||||
|
static const long fixed[5] = {100L, 500L, 2000L, 8000L, 30000L};
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
if (a < lim[i])
|
||||||
|
return fixed[i];
|
||||||
|
return fixed[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 슬랩 고정액 + 미세 요율 가산 */
|
||||||
long ac_cu_0007_fee(long amount, int rate_bp)
|
long ac_cu_0007_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long f;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
f = ac_cu_0007_slab(amount);
|
||||||
if (fee < 0)
|
f += amount * (long)rate_bp / 100000L;
|
||||||
fee = 0;
|
return f;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 가장 가까운 배수(반올림, 동점은 올림) */
|
||||||
long ac_cu_0007_round_unit(long amount, long unit)
|
long ac_cu_0007_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount % unit;
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q++;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 통과한 임계 개수(0~5) */
|
||||||
int ac_cu_0007_classify(long amount)
|
int ac_cu_0007_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long g[5] = {1000L, 10000L, 100000L, 1000000L, 10000000L};
|
||||||
return 0;
|
int i, c = 0;
|
||||||
if (amount < 1000000L)
|
for (i = 0; i < 5; i++)
|
||||||
return 1;
|
if (amount >= g[i])
|
||||||
return 2;
|
c++;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,52 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* Luhn(mod-10) 체크섬 계산: 우대카드 판별용 */
|
||||||
|
static int ac_cu_0008_luhn(long v)
|
||||||
|
{
|
||||||
|
int sum = 0, alt = 0;
|
||||||
|
if (v < 0) v = -v;
|
||||||
|
while (v > 0) {
|
||||||
|
int d = (int)(v % 10);
|
||||||
|
if (alt) { d *= 2; if (d > 9) d -= 9; }
|
||||||
|
sum += d;
|
||||||
|
alt = !alt;
|
||||||
|
v /= 10;
|
||||||
|
}
|
||||||
|
return sum % 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: Luhn 체크섬이 0(정상 카드)이면 면제, 그 외 정률 */
|
||||||
long ac_cu_0008_fee(long amount, int rate_bp)
|
long ac_cu_0008_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
if (ac_cu_0008_luhn(amount) == 0)
|
||||||
if (fee < 0)
|
return 0;
|
||||||
fee = 0;
|
return (amount * (long)rate_bp) / 10000L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(round-half-up) 단위 정규화 */
|
||||||
long ac_cu_0008_round_unit(long amount, long unit)
|
long ac_cu_0008_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r, half;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
half = unit / 2;
|
||||||
|
amount -= r;
|
||||||
|
if (r >= half)
|
||||||
|
amount += unit;
|
||||||
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 10진 자릿수 개수 반환 */
|
||||||
int ac_cu_0008_classify(long amount)
|
int ac_cu_0008_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int digits = 0;
|
||||||
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
while (v > 0) { digits++; v /= 10; }
|
||||||
return 1;
|
return digits;
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,54 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* BIN 범위 조회: 카드 앞 6자리 → 등급 */
|
||||||
|
static int ac_cu_0009_bin_grade(long n)
|
||||||
|
{
|
||||||
|
static const long lo[3] = {400000L, 510000L, 600000L};
|
||||||
|
static const long hi[3] = {499999L, 559999L, 699999L};
|
||||||
|
long bin = n < 0 ? -n : n;
|
||||||
|
int i;
|
||||||
|
while (bin >= 1000000L)
|
||||||
|
bin /= 10;
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
if (bin >= lo[i] && bin <= hi[i])
|
||||||
|
return i + 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 카드 등급별 가산 bp 적용 */
|
||||||
long ac_cu_0009_fee(long amount, int rate_bp)
|
long ac_cu_0009_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
int g;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
g = ac_cu_0009_bin_grade(amount);
|
||||||
if (fee < 0)
|
rate_bp += g * 5;
|
||||||
fee = 0;
|
return (amount * (long)rate_bp) / 10000L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 올림(ceil) 단위 정규화 */
|
||||||
long ac_cu_0009_round_unit(long amount, long unit)
|
long ac_cu_0009_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
if (r == 0)
|
||||||
|
return amount;
|
||||||
|
if (r < 0)
|
||||||
|
return amount - r;
|
||||||
|
return amount + (unit - r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 퍼센타일 경계 버킷(0~9) */
|
||||||
int ac_cu_0009_classify(long amount)
|
int ac_cu_0009_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long b[9] = {1000L, 5000L, 10000L, 50000L, 100000L,
|
||||||
return 0;
|
500000L, 1000000L, 5000000L, 10000000L};
|
||||||
if (amount < 1000000L)
|
int i;
|
||||||
return 1;
|
for (i = 0; i < 9; i++)
|
||||||
return 2;
|
if (amount < b[i])
|
||||||
|
return i;
|
||||||
|
return 9;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,53 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* Zeller 합동식으로 요일 계산: 0=토,1=일,...,6=금 */
|
||||||
|
static int ac_cu_0010_dow(int y, int m, int d)
|
||||||
|
{
|
||||||
|
int k, j;
|
||||||
|
if (m < 3) { m += 12; y--; }
|
||||||
|
k = y % 100;
|
||||||
|
j = y / 100;
|
||||||
|
return (d + 13 * (m + 1) / 5 + k + k / 4 + j / 4 + 5 * j) % 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: amount=YYYYMMDD, 주말이면 할증 rate 반환 */
|
||||||
long ac_cu_0010_fee(long amount, int rate_bp)
|
long ac_cu_0010_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
int y, m, d, w;
|
||||||
|
long base;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
y = (int)(amount / 10000L);
|
||||||
if (fee < 0)
|
m = (int)((amount / 100L) % 100L);
|
||||||
fee = 0;
|
d = (int)(amount % 100L);
|
||||||
return fee;
|
w = ac_cu_0010_dow(y, m, d);
|
||||||
|
base = rate_bp;
|
||||||
|
if (w == 0 || w == 1)
|
||||||
|
base += (long)rate_bp / 10;
|
||||||
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 내림(floor) 단위 정규화: 음수 방향 보정 */
|
||||||
long ac_cu_0010_round_unit(long amount, long unit)
|
long ac_cu_0010_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
if (amount % unit != 0 && amount < 0)
|
||||||
|
q--;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: YYYYMMDD 의 요일(0~6), 오류 -1 */
|
||||||
int ac_cu_0010_classify(long amount)
|
int ac_cu_0010_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y, m, d;
|
||||||
return 0;
|
if (amount <= 0)
|
||||||
if (amount < 1000000L)
|
return -1;
|
||||||
return 1;
|
y = (int)(amount / 10000L);
|
||||||
return 2;
|
m = (int)((amount / 100L) % 100L);
|
||||||
|
d = (int)(amount % 100L);
|
||||||
|
return ac_cu_0010_dow(y, m, d);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,45 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 뱅커스 반올림(사사오입): num/den 을 최근접 정수로, 동점은 짝수 */
|
||||||
|
static long ac_cu_0011_bankers(long num, long den)
|
||||||
|
{
|
||||||
|
long q = num / den;
|
||||||
|
long r = num % den;
|
||||||
|
long twice = 2 * (r < 0 ? -r : r);
|
||||||
|
long ad = den < 0 ? -den : den;
|
||||||
|
if (twice > ad)
|
||||||
|
q += (num < 0 ? -1 : 1);
|
||||||
|
else if (twice == ad && (q % 2 != 0))
|
||||||
|
q += (num < 0 ? -1 : 1);
|
||||||
|
return q;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 초과분에만 요율 적용하는 누진 구간 */
|
||||||
long ac_cu_0011_fee(long amount, int rate_bp)
|
long ac_cu_0011_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee = 0, a = amount;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
if (a > 1000000L) { fee += (a - 1000000L) * (long)rate_bp / 10000L; a = 1000000L; }
|
||||||
if (fee < 0)
|
if (a > 100000L) { fee += (a - 100000L) * (long)(rate_bp + 10) / 10000L; a = 100000L; }
|
||||||
fee = 0;
|
fee += a * (long)(rate_bp + 20) / 10000L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 뱅커스 반올림 단위 정규화 */
|
||||||
long ac_cu_0011_round_unit(long amount, long unit)
|
long ac_cu_0011_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
return ac_cu_0011_bankers(amount, unit) * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 10의 거듭제곱 지수(로그10 정수부) */
|
||||||
int ac_cu_0011_classify(long amount)
|
int ac_cu_0011_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int e = 0;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
while (v >= 10) { v /= 10; e++; }
|
||||||
return 1;
|
return e;
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,53 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* Zeller 합동식으로 요일 계산: 0=토,1=일,...,6=금 */
|
||||||
|
static int au_cu_0001_dow(int y, int m, int d)
|
||||||
|
{
|
||||||
|
int k, j;
|
||||||
|
if (m < 3) { m += 12; y--; }
|
||||||
|
k = y % 100;
|
||||||
|
j = y / 100;
|
||||||
|
return (d + 13 * (m + 1) / 5 + k + k / 4 + j / 4 + 5 * j) % 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: amount=YYYYMMDD, 주말이면 할증 rate 반환 */
|
||||||
long au_cu_0001_fee(long amount, int rate_bp)
|
long au_cu_0001_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
int y, m, d, w;
|
||||||
|
long base;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
y = (int)(amount / 10000L);
|
||||||
if (fee < 0)
|
m = (int)((amount / 100L) % 100L);
|
||||||
fee = 0;
|
d = (int)(amount % 100L);
|
||||||
return fee;
|
w = au_cu_0001_dow(y, m, d);
|
||||||
|
base = rate_bp;
|
||||||
|
if (w == 0 || w == 1)
|
||||||
|
base += (long)rate_bp / 10;
|
||||||
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 내림(floor) 단위 정규화: 음수 방향 보정 */
|
||||||
long au_cu_0001_round_unit(long amount, long unit)
|
long au_cu_0001_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
if (amount % unit != 0 && amount < 0)
|
||||||
|
q--;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: YYYYMMDD 의 요일(0~6), 오류 -1 */
|
||||||
int au_cu_0001_classify(long amount)
|
int au_cu_0001_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y, m, d;
|
||||||
return 0;
|
if (amount <= 0)
|
||||||
if (amount < 1000000L)
|
return -1;
|
||||||
return 1;
|
y = (int)(amount / 10000L);
|
||||||
return 2;
|
m = (int)((amount / 100L) % 100L);
|
||||||
|
d = (int)(amount % 100L);
|
||||||
|
return au_cu_0001_dow(y, m, d);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,45 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 뱅커스 반올림(사사오입): num/den 을 최근접 정수로, 동점은 짝수 */
|
||||||
|
static long au_cu_0002_bankers(long num, long den)
|
||||||
|
{
|
||||||
|
long q = num / den;
|
||||||
|
long r = num % den;
|
||||||
|
long twice = 2 * (r < 0 ? -r : r);
|
||||||
|
long ad = den < 0 ? -den : den;
|
||||||
|
if (twice > ad)
|
||||||
|
q += (num < 0 ? -1 : 1);
|
||||||
|
else if (twice == ad && (q % 2 != 0))
|
||||||
|
q += (num < 0 ? -1 : 1);
|
||||||
|
return q;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 초과분에만 요율 적용하는 누진 구간 */
|
||||||
long au_cu_0002_fee(long amount, int rate_bp)
|
long au_cu_0002_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee = 0, a = amount;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
if (a > 1000000L) { fee += (a - 1000000L) * (long)rate_bp / 10000L; a = 1000000L; }
|
||||||
if (fee < 0)
|
if (a > 100000L) { fee += (a - 100000L) * (long)(rate_bp + 10) / 10000L; a = 100000L; }
|
||||||
fee = 0;
|
fee += a * (long)(rate_bp + 20) / 10000L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 뱅커스 반올림 단위 정규화 */
|
||||||
long au_cu_0002_round_unit(long amount, long unit)
|
long au_cu_0002_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
return au_cu_0002_bankers(amount, unit) * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 10의 거듭제곱 지수(로그10 정수부) */
|
||||||
int au_cu_0002_classify(long amount)
|
int au_cu_0002_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int e = 0;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
while (v >= 10) { v /= 10; e++; }
|
||||||
return 1;
|
return e;
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,49 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* CRC-8(다항식 0x07) 계산: 고정길이 필드 무결성 */
|
||||||
|
static unsigned au_cu_0003_crc8(const char *s, int n)
|
||||||
|
{
|
||||||
|
unsigned crc = 0;
|
||||||
|
int i, b;
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
crc ^= (unsigned char)s[i];
|
||||||
|
for (b = 0; b < 8; b++)
|
||||||
|
crc = (crc & 0x80) ? ((crc << 1) ^ 0x07) & 0xFF : (crc << 1) & 0xFF;
|
||||||
|
}
|
||||||
|
return crc & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 금액을 12자리 고정필드로 pack 후 CRC 가산 */
|
||||||
long au_cu_0003_fee(long amount, int rate_bp)
|
long au_cu_0003_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
char buf[16];
|
||||||
|
long v = amount < 0 ? 0 : amount;
|
||||||
|
int i;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 11; i >= 0; i--) { buf[i] = (char)('0' + (int)(v % 10)); v /= 10; }
|
||||||
if (fee < 0)
|
buf[12] = '\0';
|
||||||
fee = 0;
|
return (amount * (long)rate_bp) / 10000L + (long)au_cu_0003_crc8(buf, 12);
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최근접 배수 반올림(round-half-away-from-zero) */
|
||||||
long au_cu_0003_round_unit(long amount, long unit)
|
long au_cu_0003_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r, h;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
h = (unit + 1) / 2;
|
||||||
|
if (r < 0)
|
||||||
|
return (-r >= h) ? amount - (unit + r) : amount - r;
|
||||||
|
return (r >= h) ? amount + (unit - r) : amount - r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 부호·홀짝 조합 4가지 */
|
||||||
int au_cu_0003_classify(long amount)
|
int au_cu_0003_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int s = amount < 0 ? 2 : 0;
|
||||||
return 0;
|
int p = (amount % 2 != 0) ? 1 : 0;
|
||||||
if (amount < 1000000L)
|
return s + p;
|
||||||
return 1;
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,39 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 수수료: 12개월 균등분할 잔액에 대한 단리 이자 합 */
|
||||||
long au_cu_0004_fee(long amount, int rate_bp)
|
long au_cu_0004_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long total = 0, principal;
|
||||||
|
int m;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
principal = amount / 12;
|
||||||
if (fee < 0)
|
for (m = 1; m <= 12; m++) {
|
||||||
fee = 0;
|
long bal = amount - principal * (m - 1);
|
||||||
return fee;
|
total += bal * (long)rate_bp / 120000L;
|
||||||
|
}
|
||||||
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 잔돈 재분배 반올림: 잔여의 2배가 unit 이상이면 올림 */
|
||||||
long au_cu_0004_round_unit(long amount, long unit)
|
long au_cu_0004_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long base, rem;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
base = (amount / unit) * unit;
|
||||||
|
rem = amount - base;
|
||||||
|
return (rem * 2 >= unit) ? base + unit : base;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 최상위(선두) 숫자 1~9 */
|
||||||
int au_cu_0004_classify(long amount)
|
int au_cu_0004_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
while (v >= 10)
|
||||||
return 1;
|
v /= 10;
|
||||||
return 2;
|
return (int)v;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,33 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 수수료: 소수 2자리 스케일로 확대 후 요율 적용, 원 단위 복귀 */
|
||||||
long au_cu_0005_fee(long amount, int rate_bp)
|
long au_cu_0005_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long scaled, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
scaled = amount * 100L;
|
||||||
if (fee < 0)
|
fee = scaled * (long)rate_bp / 10000L;
|
||||||
fee = 0;
|
return fee / 100L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 단위가 2의 거듭제곱이면 비트마스크 정렬, 아니면 일반 절사 */
|
||||||
long au_cu_0005_round_unit(long amount, long unit)
|
long au_cu_0005_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
|
if ((unit & (unit - 1)) == 0)
|
||||||
|
return amount & ~(unit - 1);
|
||||||
return (amount / unit) * unit;
|
return (amount / unit) * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 금액 구간 비트맵 플래그(bit0=만,bit1=십만,bit2=백만) */
|
||||||
int au_cu_0005_classify(long amount)
|
int au_cu_0005_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int f = 0;
|
||||||
return 0;
|
if (amount >= 10000L) f |= 1;
|
||||||
if (amount < 1000000L)
|
if (amount >= 100000L) f |= 2;
|
||||||
return 1;
|
if (amount >= 1000000L) f |= 4;
|
||||||
return 2;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 수수료: 금액 구간별 요율을 선형보간하여 적용 */
|
||||||
long au_cu_0006_fee(long amount, int rate_bp)
|
long au_cu_0006_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
static const long x[4] = {0L, 100000L, 1000000L, 10000000L};
|
||||||
if (amount <= 0 || rate_bp < 0)
|
static const long y[4] = {30L, 20L, 10L, 5L};
|
||||||
|
long r = rate_bp;
|
||||||
|
int i;
|
||||||
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 0; i < 3; i++) {
|
||||||
if (fee < 0)
|
if (amount <= x[i + 1]) {
|
||||||
fee = 0;
|
long span = x[i + 1] - x[i];
|
||||||
return fee;
|
r = y[i] + (y[i + 1] - y[i]) * (amount - x[i]) / span;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return amount * r / 10000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 5사6입: 잔여가 unit 의 60% 이상일 때만 올림 */
|
||||||
long au_cu_0006_round_unit(long amount, long unit)
|
long au_cu_0006_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
return (r * 10 >= unit * 6) ? amount + (unit - r) : amount - r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 이진탐색으로 경계 버킷 결정 */
|
||||||
int au_cu_0006_classify(long amount)
|
int au_cu_0006_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long b[7] = {5000L, 20000L, 50000L, 200000L,
|
||||||
return 0;
|
500000L, 2000000L, 5000000L};
|
||||||
if (amount < 1000000L)
|
int lo = 0, hi = 7, mid;
|
||||||
return 1;
|
while (lo < hi) {
|
||||||
return 2;
|
mid = (lo + hi) / 2;
|
||||||
|
if (amount < b[mid]) hi = mid; else lo = mid + 1;
|
||||||
|
}
|
||||||
|
return lo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,35 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 그레고리력 → 율리우스일수 근사 변환 */
|
||||||
long au_cu_0007_fee(long amount, int rate_bp)
|
static long au_cu_0007_jdn(int y, int m, int d)
|
||||||
{
|
{
|
||||||
long fee;
|
long a = (14 - m) / 12;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
long yy = y + 4800 - a;
|
||||||
return 0;
|
long mm = m + 12 * a - 3;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
return d + (153 * mm + 2) / 5 + 365 * yy + yy / 4 - yy / 100 + yy / 400 - 32045;
|
||||||
if (fee < 0)
|
|
||||||
fee = 0;
|
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 수수료: amount=YYYYMMDD 에 rate_bp 영업일 더한 율리우스일 반환 */
|
||||||
|
long au_cu_0007_fee(long amount, int rate_bp)
|
||||||
|
{
|
||||||
|
int y, m, d, added = 0;
|
||||||
|
long jd;
|
||||||
|
if (amount <= 0)
|
||||||
|
return 0;
|
||||||
|
y = (int)(amount / 10000L);
|
||||||
|
m = (int)((amount / 100L) % 100L);
|
||||||
|
d = (int)(amount % 100L);
|
||||||
|
jd = au_cu_0007_jdn(y, m, d);
|
||||||
|
while (added < rate_bp) {
|
||||||
|
jd++;
|
||||||
|
if (jd % 7 != 5 && jd % 7 != 6)
|
||||||
|
added++;
|
||||||
|
}
|
||||||
|
return jd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 0 방향 대칭 절사(truncate toward zero) */
|
||||||
long au_cu_0007_round_unit(long amount, long unit)
|
long au_cu_0007_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
|
|
@ -26,12 +42,15 @@ long au_cu_0007_round_unit(long amount, long unit)
|
||||||
return (amount / unit) * unit;
|
return (amount / unit) * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: FNV-1a 해시의 하위 3비트 */
|
||||||
int au_cu_0007_classify(long amount)
|
int au_cu_0007_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
unsigned long h = 2166136261UL;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
do {
|
||||||
return 1;
|
h ^= (unsigned long)(v % 10);
|
||||||
return 2;
|
h *= 16777619UL;
|
||||||
|
v /= 10;
|
||||||
|
} while (v > 0);
|
||||||
|
return (int)(h & 0x7UL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 디지털 루트(각 자리 합 반복) 계산 */
|
||||||
|
static int au_cu_0008_droot(long v)
|
||||||
|
{
|
||||||
|
if (v < 0) v = -v;
|
||||||
|
while (v >= 10) {
|
||||||
|
long s = 0;
|
||||||
|
while (v > 0) { s += v % 10; v /= 10; }
|
||||||
|
v = s;
|
||||||
|
}
|
||||||
|
return (int)v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 정률 계산 후 상한(cap) 적용 */
|
||||||
long au_cu_0008_fee(long amount, int rate_bp)
|
long au_cu_0008_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee, cap = 50000L;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
fee = amount * (long)rate_bp / 10000L;
|
||||||
if (fee < 0)
|
if (fee > cap)
|
||||||
fee = 0;
|
fee = cap;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 이중 절사: 1차 절사 후 잔여 2/3 이상이면 한 단위 보정 */
|
||||||
long au_cu_0008_round_unit(long amount, long unit)
|
long au_cu_0008_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long f1;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
f1 = (amount / unit) * unit;
|
||||||
|
if ((amount - f1) * 3 >= unit * 2)
|
||||||
|
f1 += unit;
|
||||||
|
return f1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 디지털 루트(1~9, 0) */
|
||||||
int au_cu_0008_classify(long amount)
|
int au_cu_0008_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
return au_cu_0008_droot(amount);
|
||||||
return 0;
|
|
||||||
if (amount < 1000000L)
|
|
||||||
return 1;
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,49 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 슬랩(구간별 고정액) 수수료 테이블 조회 */
|
||||||
|
static long au_cu_0009_slab(long a)
|
||||||
|
{
|
||||||
|
static const long lim[4] = {10000L, 100000L, 1000000L, 10000000L};
|
||||||
|
static const long fixed[5] = {100L, 500L, 2000L, 8000L, 30000L};
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
if (a < lim[i])
|
||||||
|
return fixed[i];
|
||||||
|
return fixed[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 슬랩 고정액 + 미세 요율 가산 */
|
||||||
long au_cu_0009_fee(long amount, int rate_bp)
|
long au_cu_0009_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long f;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
f = au_cu_0009_slab(amount);
|
||||||
if (fee < 0)
|
f += amount * (long)rate_bp / 100000L;
|
||||||
fee = 0;
|
return f;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 가장 가까운 배수(반올림, 동점은 올림) */
|
||||||
long au_cu_0009_round_unit(long amount, long unit)
|
long au_cu_0009_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount % unit;
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q++;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 통과한 임계 개수(0~5) */
|
||||||
int au_cu_0009_classify(long amount)
|
int au_cu_0009_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long g[5] = {1000L, 10000L, 100000L, 1000000L, 10000000L};
|
||||||
return 0;
|
int i, c = 0;
|
||||||
if (amount < 1000000L)
|
for (i = 0; i < 5; i++)
|
||||||
return 1;
|
if (amount >= g[i])
|
||||||
return 2;
|
c++;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,52 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* Luhn(mod-10) 체크섬 계산: 우대카드 판별용 */
|
||||||
|
static int au_cu_0010_luhn(long v)
|
||||||
|
{
|
||||||
|
int sum = 0, alt = 0;
|
||||||
|
if (v < 0) v = -v;
|
||||||
|
while (v > 0) {
|
||||||
|
int d = (int)(v % 10);
|
||||||
|
if (alt) { d *= 2; if (d > 9) d -= 9; }
|
||||||
|
sum += d;
|
||||||
|
alt = !alt;
|
||||||
|
v /= 10;
|
||||||
|
}
|
||||||
|
return sum % 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: Luhn 체크섬이 0(정상 카드)이면 면제, 그 외 정률 */
|
||||||
long au_cu_0010_fee(long amount, int rate_bp)
|
long au_cu_0010_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
if (au_cu_0010_luhn(amount) == 0)
|
||||||
if (fee < 0)
|
return 0;
|
||||||
fee = 0;
|
return (amount * (long)rate_bp) / 10000L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(round-half-up) 단위 정규화 */
|
||||||
long au_cu_0010_round_unit(long amount, long unit)
|
long au_cu_0010_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r, half;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
half = unit / 2;
|
||||||
|
amount -= r;
|
||||||
|
if (r >= half)
|
||||||
|
amount += unit;
|
||||||
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 10진 자릿수 개수 반환 */
|
||||||
int au_cu_0010_classify(long amount)
|
int au_cu_0010_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int digits = 0;
|
||||||
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
while (v > 0) { digits++; v /= 10; }
|
||||||
return 1;
|
return digits;
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,54 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* BIN 범위 조회: 카드 앞 6자리 → 등급 */
|
||||||
|
static int au_cu_0011_bin_grade(long n)
|
||||||
|
{
|
||||||
|
static const long lo[3] = {400000L, 510000L, 600000L};
|
||||||
|
static const long hi[3] = {499999L, 559999L, 699999L};
|
||||||
|
long bin = n < 0 ? -n : n;
|
||||||
|
int i;
|
||||||
|
while (bin >= 1000000L)
|
||||||
|
bin /= 10;
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
if (bin >= lo[i] && bin <= hi[i])
|
||||||
|
return i + 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 카드 등급별 가산 bp 적용 */
|
||||||
long au_cu_0011_fee(long amount, int rate_bp)
|
long au_cu_0011_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
int g;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
g = au_cu_0011_bin_grade(amount);
|
||||||
if (fee < 0)
|
rate_bp += g * 5;
|
||||||
fee = 0;
|
return (amount * (long)rate_bp) / 10000L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 올림(ceil) 단위 정규화 */
|
||||||
long au_cu_0011_round_unit(long amount, long unit)
|
long au_cu_0011_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
if (r == 0)
|
||||||
|
return amount;
|
||||||
|
if (r < 0)
|
||||||
|
return amount - r;
|
||||||
|
return amount + (unit - r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 퍼센타일 경계 버킷(0~9) */
|
||||||
int au_cu_0011_classify(long amount)
|
int au_cu_0011_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long b[9] = {1000L, 5000L, 10000L, 50000L, 100000L,
|
||||||
return 0;
|
500000L, 1000000L, 5000000L, 10000000L};
|
||||||
if (amount < 1000000L)
|
int i;
|
||||||
return 1;
|
for (i = 0; i < 9; i++)
|
||||||
return 2;
|
if (amount < b[i])
|
||||||
|
return i;
|
||||||
|
return 9;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,55 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 누진 구간 수수료: 금액 구간별 한계요율을 누적 적용한다 */
|
||||||
long cl_cu_0001_fee(long amount, int rate_bp)
|
long cl_cu_0001_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
static const long band[] = { 100000L, 1000000L, 10000000L };
|
||||||
|
static const int mul[] = { 1, 2, 3, 5 };
|
||||||
|
long remain = amount;
|
||||||
|
long fee = 0;
|
||||||
|
long prev = 0;
|
||||||
|
int i;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 0; i < 3; i++) {
|
||||||
if (fee < 0)
|
long span = band[i] - prev;
|
||||||
fee = 0;
|
long part = remain < span ? remain : span;
|
||||||
|
if (part <= 0)
|
||||||
|
break;
|
||||||
|
fee += (part * (long)rate_bp * mul[i]) / 10000L;
|
||||||
|
remain -= part;
|
||||||
|
prev = band[i];
|
||||||
|
}
|
||||||
|
if (remain > 0)
|
||||||
|
fee += (remain * (long)rate_bp * mul[3]) / 10000L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 은행가 반올림(사사오입, 짝수 반올림)으로 unit 배수 정규화 */
|
||||||
long cl_cu_0001_round_unit(long amount, long unit)
|
long cl_cu_0001_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r, half;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
half = unit / 2;
|
||||||
|
if (r > half || (r == half && (q & 1L)))
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 자릿수(log10) 규모로 5단계 분류 */
|
||||||
int cl_cu_0001_classify(long amount)
|
int cl_cu_0001_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int digits = 0;
|
||||||
if (amount < 1000000L)
|
while (v > 0) { digits++; v /= 10; }
|
||||||
return 1;
|
if (digits <= 3) return 0;
|
||||||
return 2;
|
if (digits <= 5) return 1;
|
||||||
|
if (digits <= 7) return 2;
|
||||||
|
if (digits <= 9) return 3;
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,48 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 원리금 이자액: rate_bp 연이율을 월할(1/12) 적용 */
|
||||||
long cl_cu_0002_fee(long amount, int rate_bp)
|
long cl_cu_0002_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long annual_bp;
|
||||||
|
long interest;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
annual_bp = (long)rate_bp;
|
||||||
if (fee < 0)
|
interest = (amount * annual_bp) / (10000L * 12L);
|
||||||
fee = 0;
|
if (interest < 0)
|
||||||
return fee;
|
interest = 0;
|
||||||
|
return interest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(오사오입, 0.5 이상 올림)으로 unit 정규화 */
|
||||||
long cl_cu_0002_round_unit(long amount, long unit)
|
long cl_cu_0002_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* Luhn 체크섬 유효성으로 분류: 유효=2, 무효 소액=0, 무효 고액=1 */
|
||||||
int cl_cu_0002_classify(long amount)
|
int cl_cu_0002_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int sum = 0, alt = 0, d;
|
||||||
if (amount < 1000000L)
|
long t = v;
|
||||||
return 1;
|
while (t > 0) {
|
||||||
return 2;
|
d = (int)(t % 10);
|
||||||
|
if (alt) { d *= 2; if (d > 9) d -= 9; }
|
||||||
|
sum += d;
|
||||||
|
alt = !alt;
|
||||||
|
t /= 10;
|
||||||
|
}
|
||||||
|
if (sum % 10 == 0)
|
||||||
|
return 2;
|
||||||
|
return v < 1000000L ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,45 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 일할 정산: rate_bp 를 경과일(1..10000) 비율로 안분한다 */
|
||||||
long cl_cu_0003_fee(long amount, int rate_bp)
|
long cl_cu_0003_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long days, prorated;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
days = (long)rate_bp;
|
||||||
if (fee < 0)
|
if (days > 10000L)
|
||||||
fee = 0;
|
days = 10000L;
|
||||||
return fee;
|
prorated = (amount * days) / 10000L;
|
||||||
|
return prorated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(절대값 0.5 기준 올림, 부호 보존)으로 unit 정규화 */
|
||||||
long cl_cu_0003_round_unit(long amount, long unit)
|
long cl_cu_0003_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long a, q, r, res;
|
||||||
|
int neg;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
neg = amount < 0;
|
||||||
|
a = neg ? -amount : amount;
|
||||||
|
q = a / unit;
|
||||||
|
r = a - q * unit;
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q += 1;
|
||||||
|
res = q * unit;
|
||||||
|
return neg ? -res : res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 디지털 루트(반복 자릿수합)로 분류 */
|
||||||
int cl_cu_0003_classify(long amount)
|
int cl_cu_0003_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
int root;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
root = (int)(1 + (v - 1) % 9);
|
||||||
return 1;
|
if (root <= 3) return 0;
|
||||||
|
if (root <= 6) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,51 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* FNV 해시로 결정적 가산분을 산출하는 보조 함수 */
|
||||||
|
static unsigned long cl_cu_0004_mix(long x)
|
||||||
|
{
|
||||||
|
unsigned long h = 1469598103934665603UL;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
h ^= (unsigned long)((x >> (i * 8)) & 0xFF);
|
||||||
|
h *= 1099511628211UL;
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 해시 기반 가산 수수료: 기본 수수료에 결정적 잔돈을 더한다 */
|
||||||
long cl_cu_0004_fee(long amount, int rate_bp)
|
long cl_cu_0004_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long base, extra;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
base = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
extra = (long)(cl_cu_0004_mix(amount) % 100UL);
|
||||||
fee = 0;
|
return base + extra;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 올림(상향)으로 unit 배수 정규화 */
|
||||||
long cl_cu_0004_round_unit(long amount, long unit)
|
long cl_cu_0004_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r > 0)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* BIN 범위표로 분류: 상위 6자리를 카드 BIN 처럼 구간 판정 */
|
||||||
int cl_cu_0004_classify(long amount)
|
int cl_cu_0004_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
long bin = v;
|
||||||
if (amount < 1000000L)
|
while (bin >= 1000000L)
|
||||||
return 1;
|
bin /= 10;
|
||||||
return 2;
|
if (bin >= 400000L && bin <= 499999L) return 1;
|
||||||
|
if (bin >= 510000L && bin <= 559999L) return 2;
|
||||||
|
if (bin >= 340000L && bin <= 379999L) return 3;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,39 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 통화 스케일 환산 수수료: minor unit 로 확장 후 요율 적용, major 복귀 */
|
||||||
long cl_cu_0005_fee(long amount, int rate_bp)
|
long cl_cu_0005_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long scaled, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
scaled = amount * 100L;
|
||||||
if (fee < 0)
|
fee = (scaled * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
fee = fee / 100L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 내림(음의 무한대 방향)으로 unit 정규화 */
|
||||||
long cl_cu_0005_round_unit(long amount, long unit)
|
long cl_cu_0005_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0)
|
||||||
|
q -= 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 임계값 테이블 이분 탐색으로 백분위 버킷 분류 */
|
||||||
int cl_cu_0005_classify(long amount)
|
int cl_cu_0005_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long th[] = { 5000L, 50000L, 500000L, 5000000L, 50000000L };
|
||||||
return 0;
|
int lo = 0, hi = 5, mid;
|
||||||
if (amount < 1000000L)
|
while (lo < hi) {
|
||||||
return 1;
|
mid = (lo + hi) / 2;
|
||||||
return 2;
|
if (amount < th[mid]) hi = mid; else lo = mid + 1;
|
||||||
|
}
|
||||||
|
return lo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,38 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 상계(netting) 수수료: 기준 30bp 에서 rate_bp 크레딧을 차감한 순수수료 */
|
||||||
long cl_cu_0006_fee(long amount, int rate_bp)
|
long cl_cu_0006_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long gross, credit, net;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
gross = (amount * 30L) / 10000L;
|
||||||
if (fee < 0)
|
credit = (amount * (long)(rate_bp < 0 ? 0 : rate_bp)) / 10000L;
|
||||||
fee = 0;
|
net = gross - credit;
|
||||||
return fee;
|
if (net < 0)
|
||||||
|
net = 0;
|
||||||
|
return net;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 절사(0 방향)으로 unit 정규화 */
|
||||||
long cl_cu_0006_round_unit(long amount, long unit)
|
long cl_cu_0006_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 비트맵 플래그 합성 분류: 특성 비트를 OR 로 조합 */
|
||||||
int cl_cu_0006_classify(long amount)
|
int cl_cu_0006_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int flags = 0;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
if (amount < 0) flags |= 0x1;
|
||||||
return 1;
|
if (v % 2 == 0) flags |= 0x2;
|
||||||
return 2;
|
if (v >= 1000000L) flags |= 0x4;
|
||||||
|
if (v % 1000L == 0) flags |= 0x8;
|
||||||
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 할부 분할 수수료: rate_bp 를 할부개월(1..60)로 보고 회차수수료 산정 */
|
||||||
long cl_cu_0007_fee(long amount, int rate_bp)
|
long cl_cu_0007_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long n, per;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
n = rate_bp <= 0 ? 1 : (rate_bp > 60 ? 60 : rate_bp);
|
||||||
if (fee < 0)
|
per = amount / n;
|
||||||
fee = 0;
|
if (amount % n != 0)
|
||||||
return fee;
|
per += 1;
|
||||||
|
return per;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(0.5 초과에서만 올림, 정확히 0.5는 내림)으로 unit 정규화 */
|
||||||
long cl_cu_0007_round_unit(long amount, long unit)
|
long cl_cu_0007_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
if (r * 2 > unit)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 날짜 산술: amount 를 YYYYMMDD 로 보고 Zeller 공식으로 요일 분류(0=일..6=토) */
|
||||||
int cl_cu_0007_classify(long amount)
|
int cl_cu_0007_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y = (int)(amount / 10000L);
|
||||||
return 0;
|
int m = (int)((amount / 100L) % 100L);
|
||||||
if (amount < 1000000L)
|
int d = (int)(amount % 100L);
|
||||||
return 1;
|
int k, j, h;
|
||||||
return 2;
|
if (m < 1 || m > 12 || d < 1 || d > 31)
|
||||||
|
return -1;
|
||||||
|
if (m < 3) { m += 12; y -= 1; }
|
||||||
|
k = y % 100; j = y / 100;
|
||||||
|
h = (d + (13 * (m + 1)) / 5 + k + k / 4 + j / 4 + 5 * j) % 7;
|
||||||
|
return (h + 6) % 7;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,57 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 상·하한 적용 정률 수수료 */
|
||||||
long cl_cu_0008_fee(long amount, int rate_bp)
|
long cl_cu_0008_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee;
|
||||||
|
const long floor_fee = 100L;
|
||||||
|
const long cap_fee = 500000L;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
fee = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
if (fee < floor_fee)
|
||||||
fee = 0;
|
fee = floor_fee;
|
||||||
|
if (fee > cap_fee)
|
||||||
|
fee = cap_fee;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최근접 배수 선택: 아래/위 배수 중 더 가까운 쪽으로 정규화 */
|
||||||
long cl_cu_0008_round_unit(long amount, long unit)
|
long cl_cu_0008_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long down, up, dd, du;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
if (amount % unit == 0)
|
||||||
|
return amount;
|
||||||
|
down = (amount / unit) * unit;
|
||||||
|
if (amount > 0)
|
||||||
|
up = down + unit;
|
||||||
|
else
|
||||||
|
up = down - unit;
|
||||||
|
dd = amount - down; if (dd < 0) dd = -dd;
|
||||||
|
du = up - amount; if (du < 0) du = -du;
|
||||||
|
return dd <= du ? down : up;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* amount 를 YYYYMMDD 로 보고 월말/윤년 유효성 분류: 0=무효 1=정상 2=월말 */
|
||||||
int cl_cu_0008_classify(long amount)
|
int cl_cu_0008_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y = (int)(amount / 10000L);
|
||||||
|
int m = (int)((amount / 100L) % 100L);
|
||||||
|
int d = (int)(amount % 100L);
|
||||||
|
int dim[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
|
int leap, last;
|
||||||
|
if (m < 1 || m > 12 || d < 1)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
|
||||||
return 1;
|
last = dim[m - 1];
|
||||||
return 2;
|
if (m == 2 && leap)
|
||||||
|
last = 29;
|
||||||
|
if (d > last)
|
||||||
|
return 0;
|
||||||
|
if (d == last)
|
||||||
|
return 2;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,43 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 복리형 단계 수수료: 기본 수수료에 2차(수수료에 대한) 수수료를 가산 */
|
||||||
long cl_cu_0009_fee(long amount, int rate_bp)
|
long cl_cu_0009_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long f1, f2;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
f1 = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
f2 = (f1 * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
return f1 + f2;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최대공약수 계산 보조 함수 */
|
||||||
|
static long cl_cu_0009_gcd(long a, long b)
|
||||||
|
{
|
||||||
|
a = a < 0 ? -a : a;
|
||||||
|
b = b < 0 ? -b : b;
|
||||||
|
while (b) { long t = a % b; a = b; b = t; }
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GCD 기반 유효 배수로 절사 정규화 */
|
||||||
long cl_cu_0009_round_unit(long amount, long unit)
|
long cl_cu_0009_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long g, step;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
g = cl_cu_0009_gcd(amount, unit);
|
||||||
|
step = g > 0 ? g : unit;
|
||||||
|
return (amount / step) * step;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 나머지 패턴(mod 7)으로 분류 */
|
||||||
int cl_cu_0009_classify(long amount)
|
int cl_cu_0009_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int r = (int)(v % 7L);
|
||||||
if (amount < 1000000L)
|
if (r == 0) return 0;
|
||||||
return 1;
|
if (r <= 3) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,35 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 마스킹 후 수수료: 하위 2자리를 마스킹한 금액에 요율 적용 */
|
||||||
long cl_cu_0010_fee(long amount, int rate_bp)
|
long cl_cu_0010_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long masked, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
masked = (amount / 100L) * 100L;
|
||||||
if (fee < 0)
|
fee = (masked * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 고정소수점 스케일(x2) 반올림으로 unit 정규화 */
|
||||||
long cl_cu_0010_round_unit(long amount, long unit)
|
long cl_cu_0010_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long scaled, q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
scaled = amount * 2L + (amount >= 0 ? unit : -unit);
|
||||||
|
q = scaled / (unit * 2L);
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 비트 개수(popcount)로 분류 */
|
||||||
int cl_cu_0010_classify(long amount)
|
int cl_cu_0010_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
unsigned long v = (unsigned long)(amount < 0 ? -amount : amount);
|
||||||
return 0;
|
int bits = 0;
|
||||||
if (amount < 1000000L)
|
while (v) { bits += (int)(v & 1UL); v >>= 1; }
|
||||||
return 1;
|
if (bits <= 4) return 0;
|
||||||
|
if (bits <= 8) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,55 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 누진 구간 수수료: 금액 구간별 한계요율을 누적 적용한다 */
|
||||||
long cm_cu_0001_fee(long amount, int rate_bp)
|
long cm_cu_0001_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
static const long band[] = { 100000L, 1000000L, 10000000L };
|
||||||
|
static const int mul[] = { 1, 2, 3, 5 };
|
||||||
|
long remain = amount;
|
||||||
|
long fee = 0;
|
||||||
|
long prev = 0;
|
||||||
|
int i;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 0; i < 3; i++) {
|
||||||
if (fee < 0)
|
long span = band[i] - prev;
|
||||||
fee = 0;
|
long part = remain < span ? remain : span;
|
||||||
|
if (part <= 0)
|
||||||
|
break;
|
||||||
|
fee += (part * (long)rate_bp * mul[i]) / 10000L;
|
||||||
|
remain -= part;
|
||||||
|
prev = band[i];
|
||||||
|
}
|
||||||
|
if (remain > 0)
|
||||||
|
fee += (remain * (long)rate_bp * mul[3]) / 10000L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 은행가 반올림(사사오입, 짝수 반올림)으로 unit 배수 정규화 */
|
||||||
long cm_cu_0001_round_unit(long amount, long unit)
|
long cm_cu_0001_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r, half;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
half = unit / 2;
|
||||||
|
if (r > half || (r == half && (q & 1L)))
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 자릿수(log10) 규모로 5단계 분류 */
|
||||||
int cm_cu_0001_classify(long amount)
|
int cm_cu_0001_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int digits = 0;
|
||||||
if (amount < 1000000L)
|
while (v > 0) { digits++; v /= 10; }
|
||||||
return 1;
|
if (digits <= 3) return 0;
|
||||||
return 2;
|
if (digits <= 5) return 1;
|
||||||
|
if (digits <= 7) return 2;
|
||||||
|
if (digits <= 9) return 3;
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,48 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 원리금 이자액: rate_bp 연이율을 월할(1/12) 적용 */
|
||||||
long cm_cu_0002_fee(long amount, int rate_bp)
|
long cm_cu_0002_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long annual_bp;
|
||||||
|
long interest;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
annual_bp = (long)rate_bp;
|
||||||
if (fee < 0)
|
interest = (amount * annual_bp) / (10000L * 12L);
|
||||||
fee = 0;
|
if (interest < 0)
|
||||||
return fee;
|
interest = 0;
|
||||||
|
return interest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(오사오입, 0.5 이상 올림)으로 unit 정규화 */
|
||||||
long cm_cu_0002_round_unit(long amount, long unit)
|
long cm_cu_0002_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* Luhn 체크섬 유효성으로 분류: 유효=2, 무효 소액=0, 무효 고액=1 */
|
||||||
int cm_cu_0002_classify(long amount)
|
int cm_cu_0002_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int sum = 0, alt = 0, d;
|
||||||
if (amount < 1000000L)
|
long t = v;
|
||||||
return 1;
|
while (t > 0) {
|
||||||
return 2;
|
d = (int)(t % 10);
|
||||||
|
if (alt) { d *= 2; if (d > 9) d -= 9; }
|
||||||
|
sum += d;
|
||||||
|
alt = !alt;
|
||||||
|
t /= 10;
|
||||||
|
}
|
||||||
|
if (sum % 10 == 0)
|
||||||
|
return 2;
|
||||||
|
return v < 1000000L ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,45 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 일할 정산: rate_bp 를 경과일(1..10000) 비율로 안분한다 */
|
||||||
long cm_cu_0003_fee(long amount, int rate_bp)
|
long cm_cu_0003_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long days, prorated;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
days = (long)rate_bp;
|
||||||
if (fee < 0)
|
if (days > 10000L)
|
||||||
fee = 0;
|
days = 10000L;
|
||||||
return fee;
|
prorated = (amount * days) / 10000L;
|
||||||
|
return prorated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(절대값 0.5 기준 올림, 부호 보존)으로 unit 정규화 */
|
||||||
long cm_cu_0003_round_unit(long amount, long unit)
|
long cm_cu_0003_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long a, q, r, res;
|
||||||
|
int neg;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
neg = amount < 0;
|
||||||
|
a = neg ? -amount : amount;
|
||||||
|
q = a / unit;
|
||||||
|
r = a - q * unit;
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q += 1;
|
||||||
|
res = q * unit;
|
||||||
|
return neg ? -res : res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 디지털 루트(반복 자릿수합)로 분류 */
|
||||||
int cm_cu_0003_classify(long amount)
|
int cm_cu_0003_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
int root;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
root = (int)(1 + (v - 1) % 9);
|
||||||
return 1;
|
if (root <= 3) return 0;
|
||||||
|
if (root <= 6) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,51 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* FNV 해시로 결정적 가산분을 산출하는 보조 함수 */
|
||||||
|
static unsigned long cm_cu_0004_mix(long x)
|
||||||
|
{
|
||||||
|
unsigned long h = 1469598103934665603UL;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
h ^= (unsigned long)((x >> (i * 8)) & 0xFF);
|
||||||
|
h *= 1099511628211UL;
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 해시 기반 가산 수수료: 기본 수수료에 결정적 잔돈을 더한다 */
|
||||||
long cm_cu_0004_fee(long amount, int rate_bp)
|
long cm_cu_0004_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long base, extra;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
base = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
extra = (long)(cm_cu_0004_mix(amount) % 100UL);
|
||||||
fee = 0;
|
return base + extra;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 올림(상향)으로 unit 배수 정규화 */
|
||||||
long cm_cu_0004_round_unit(long amount, long unit)
|
long cm_cu_0004_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r > 0)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* BIN 범위표로 분류: 상위 6자리를 카드 BIN 처럼 구간 판정 */
|
||||||
int cm_cu_0004_classify(long amount)
|
int cm_cu_0004_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
long bin = v;
|
||||||
if (amount < 1000000L)
|
while (bin >= 1000000L)
|
||||||
return 1;
|
bin /= 10;
|
||||||
return 2;
|
if (bin >= 400000L && bin <= 499999L) return 1;
|
||||||
|
if (bin >= 510000L && bin <= 559999L) return 2;
|
||||||
|
if (bin >= 340000L && bin <= 379999L) return 3;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,39 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 통화 스케일 환산 수수료: minor unit 로 확장 후 요율 적용, major 복귀 */
|
||||||
long cm_cu_0005_fee(long amount, int rate_bp)
|
long cm_cu_0005_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long scaled, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
scaled = amount * 100L;
|
||||||
if (fee < 0)
|
fee = (scaled * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
fee = fee / 100L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 내림(음의 무한대 방향)으로 unit 정규화 */
|
||||||
long cm_cu_0005_round_unit(long amount, long unit)
|
long cm_cu_0005_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0)
|
||||||
|
q -= 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 임계값 테이블 이분 탐색으로 백분위 버킷 분류 */
|
||||||
int cm_cu_0005_classify(long amount)
|
int cm_cu_0005_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long th[] = { 5000L, 50000L, 500000L, 5000000L, 50000000L };
|
||||||
return 0;
|
int lo = 0, hi = 5, mid;
|
||||||
if (amount < 1000000L)
|
while (lo < hi) {
|
||||||
return 1;
|
mid = (lo + hi) / 2;
|
||||||
return 2;
|
if (amount < th[mid]) hi = mid; else lo = mid + 1;
|
||||||
|
}
|
||||||
|
return lo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,38 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 상계(netting) 수수료: 기준 30bp 에서 rate_bp 크레딧을 차감한 순수수료 */
|
||||||
long cm_cu_0006_fee(long amount, int rate_bp)
|
long cm_cu_0006_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long gross, credit, net;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
gross = (amount * 30L) / 10000L;
|
||||||
if (fee < 0)
|
credit = (amount * (long)(rate_bp < 0 ? 0 : rate_bp)) / 10000L;
|
||||||
fee = 0;
|
net = gross - credit;
|
||||||
return fee;
|
if (net < 0)
|
||||||
|
net = 0;
|
||||||
|
return net;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 절사(0 방향)으로 unit 정규화 */
|
||||||
long cm_cu_0006_round_unit(long amount, long unit)
|
long cm_cu_0006_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 비트맵 플래그 합성 분류: 특성 비트를 OR 로 조합 */
|
||||||
int cm_cu_0006_classify(long amount)
|
int cm_cu_0006_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int flags = 0;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
if (amount < 0) flags |= 0x1;
|
||||||
return 1;
|
if (v % 2 == 0) flags |= 0x2;
|
||||||
return 2;
|
if (v >= 1000000L) flags |= 0x4;
|
||||||
|
if (v % 1000L == 0) flags |= 0x8;
|
||||||
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 할부 분할 수수료: rate_bp 를 할부개월(1..60)로 보고 회차수수료 산정 */
|
||||||
long cm_cu_0007_fee(long amount, int rate_bp)
|
long cm_cu_0007_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long n, per;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
n = rate_bp <= 0 ? 1 : (rate_bp > 60 ? 60 : rate_bp);
|
||||||
if (fee < 0)
|
per = amount / n;
|
||||||
fee = 0;
|
if (amount % n != 0)
|
||||||
return fee;
|
per += 1;
|
||||||
|
return per;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(0.5 초과에서만 올림, 정확히 0.5는 내림)으로 unit 정규화 */
|
||||||
long cm_cu_0007_round_unit(long amount, long unit)
|
long cm_cu_0007_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
if (r * 2 > unit)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 날짜 산술: amount 를 YYYYMMDD 로 보고 Zeller 공식으로 요일 분류(0=일..6=토) */
|
||||||
int cm_cu_0007_classify(long amount)
|
int cm_cu_0007_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y = (int)(amount / 10000L);
|
||||||
return 0;
|
int m = (int)((amount / 100L) % 100L);
|
||||||
if (amount < 1000000L)
|
int d = (int)(amount % 100L);
|
||||||
return 1;
|
int k, j, h;
|
||||||
return 2;
|
if (m < 1 || m > 12 || d < 1 || d > 31)
|
||||||
|
return -1;
|
||||||
|
if (m < 3) { m += 12; y -= 1; }
|
||||||
|
k = y % 100; j = y / 100;
|
||||||
|
h = (d + (13 * (m + 1)) / 5 + k + k / 4 + j / 4 + 5 * j) % 7;
|
||||||
|
return (h + 6) % 7;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,57 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 상·하한 적용 정률 수수료 */
|
||||||
long cm_cu_0008_fee(long amount, int rate_bp)
|
long cm_cu_0008_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee;
|
||||||
|
const long floor_fee = 100L;
|
||||||
|
const long cap_fee = 500000L;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
fee = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
if (fee < floor_fee)
|
||||||
fee = 0;
|
fee = floor_fee;
|
||||||
|
if (fee > cap_fee)
|
||||||
|
fee = cap_fee;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최근접 배수 선택: 아래/위 배수 중 더 가까운 쪽으로 정규화 */
|
||||||
long cm_cu_0008_round_unit(long amount, long unit)
|
long cm_cu_0008_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long down, up, dd, du;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
if (amount % unit == 0)
|
||||||
|
return amount;
|
||||||
|
down = (amount / unit) * unit;
|
||||||
|
if (amount > 0)
|
||||||
|
up = down + unit;
|
||||||
|
else
|
||||||
|
up = down - unit;
|
||||||
|
dd = amount - down; if (dd < 0) dd = -dd;
|
||||||
|
du = up - amount; if (du < 0) du = -du;
|
||||||
|
return dd <= du ? down : up;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* amount 를 YYYYMMDD 로 보고 월말/윤년 유효성 분류: 0=무효 1=정상 2=월말 */
|
||||||
int cm_cu_0008_classify(long amount)
|
int cm_cu_0008_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y = (int)(amount / 10000L);
|
||||||
|
int m = (int)((amount / 100L) % 100L);
|
||||||
|
int d = (int)(amount % 100L);
|
||||||
|
int dim[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
|
int leap, last;
|
||||||
|
if (m < 1 || m > 12 || d < 1)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
|
||||||
return 1;
|
last = dim[m - 1];
|
||||||
return 2;
|
if (m == 2 && leap)
|
||||||
|
last = 29;
|
||||||
|
if (d > last)
|
||||||
|
return 0;
|
||||||
|
if (d == last)
|
||||||
|
return 2;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,43 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 복리형 단계 수수료: 기본 수수료에 2차(수수료에 대한) 수수료를 가산 */
|
||||||
long cm_cu_0009_fee(long amount, int rate_bp)
|
long cm_cu_0009_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long f1, f2;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
f1 = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
f2 = (f1 * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
return f1 + f2;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최대공약수 계산 보조 함수 */
|
||||||
|
static long cm_cu_0009_gcd(long a, long b)
|
||||||
|
{
|
||||||
|
a = a < 0 ? -a : a;
|
||||||
|
b = b < 0 ? -b : b;
|
||||||
|
while (b) { long t = a % b; a = b; b = t; }
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GCD 기반 유효 배수로 절사 정규화 */
|
||||||
long cm_cu_0009_round_unit(long amount, long unit)
|
long cm_cu_0009_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long g, step;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
g = cm_cu_0009_gcd(amount, unit);
|
||||||
|
step = g > 0 ? g : unit;
|
||||||
|
return (amount / step) * step;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 나머지 패턴(mod 7)으로 분류 */
|
||||||
int cm_cu_0009_classify(long amount)
|
int cm_cu_0009_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int r = (int)(v % 7L);
|
||||||
if (amount < 1000000L)
|
if (r == 0) return 0;
|
||||||
return 1;
|
if (r <= 3) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,35 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 마스킹 후 수수료: 하위 2자리를 마스킹한 금액에 요율 적용 */
|
||||||
long cm_cu_0010_fee(long amount, int rate_bp)
|
long cm_cu_0010_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long masked, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
masked = (amount / 100L) * 100L;
|
||||||
if (fee < 0)
|
fee = (masked * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 고정소수점 스케일(x2) 반올림으로 unit 정규화 */
|
||||||
long cm_cu_0010_round_unit(long amount, long unit)
|
long cm_cu_0010_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long scaled, q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
scaled = amount * 2L + (amount >= 0 ? unit : -unit);
|
||||||
|
q = scaled / (unit * 2L);
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 비트 개수(popcount)로 분류 */
|
||||||
int cm_cu_0010_classify(long amount)
|
int cm_cu_0010_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
unsigned long v = (unsigned long)(amount < 0 ? -amount : amount);
|
||||||
return 0;
|
int bits = 0;
|
||||||
if (amount < 1000000L)
|
while (v) { bits += (int)(v & 1UL); v >>= 1; }
|
||||||
return 1;
|
if (bits <= 4) return 0;
|
||||||
|
if (bits <= 8) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,59 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* CRC16(CCITT) 계산 보조 함수 */
|
||||||
|
static unsigned int cm_cu_0011_crc16(long x)
|
||||||
|
{
|
||||||
|
unsigned int crc = 0xFFFF;
|
||||||
|
unsigned char buf[8];
|
||||||
|
int i, b;
|
||||||
|
for (i = 0; i < 8; i++)
|
||||||
|
buf[i] = (unsigned char)((x >> (i * 8)) & 0xFF);
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
crc ^= (unsigned int)buf[i] << 8;
|
||||||
|
for (b = 0; b < 8; b++)
|
||||||
|
crc = (crc & 0x8000) ? (unsigned int)((crc << 1) ^ 0x1021)
|
||||||
|
: (unsigned int)(crc << 1);
|
||||||
|
}
|
||||||
|
return crc & 0xFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CRC16 혼합 가산 수수료: 기본 수수료에 결정적 소액 가산분을 더한다 */
|
||||||
long cm_cu_0011_fee(long amount, int rate_bp)
|
long cm_cu_0011_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long base;
|
||||||
|
unsigned int c;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
base = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
c = cm_cu_0011_crc16(amount);
|
||||||
fee = 0;
|
return base + (long)(c % 50U);
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 상향 임계 반올림((unit+1)/2 기준)으로 unit 정규화 */
|
||||||
long cm_cu_0011_round_unit(long amount, long unit)
|
long cm_cu_0011_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r, threshold;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
threshold = (unit + 1) / 2;
|
||||||
|
if (r >= threshold)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 누적분포(CDF) 근사 스캔으로 백분위 분류 */
|
||||||
int cm_cu_0011_classify(long amount)
|
int cm_cu_0011_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long cum[] = { 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L };
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
int i;
|
||||||
return 1;
|
for (i = 0; i < 6; i++) {
|
||||||
return 2;
|
if (v < cum[i])
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,55 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 누진 구간 수수료: 금액 구간별 한계요율을 누적 적용한다 */
|
||||||
long lg_cu_0001_fee(long amount, int rate_bp)
|
long lg_cu_0001_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
static const long band[] = { 100000L, 1000000L, 10000000L };
|
||||||
|
static const int mul[] = { 1, 2, 3, 5 };
|
||||||
|
long remain = amount;
|
||||||
|
long fee = 0;
|
||||||
|
long prev = 0;
|
||||||
|
int i;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 0; i < 3; i++) {
|
||||||
if (fee < 0)
|
long span = band[i] - prev;
|
||||||
fee = 0;
|
long part = remain < span ? remain : span;
|
||||||
|
if (part <= 0)
|
||||||
|
break;
|
||||||
|
fee += (part * (long)rate_bp * mul[i]) / 10000L;
|
||||||
|
remain -= part;
|
||||||
|
prev = band[i];
|
||||||
|
}
|
||||||
|
if (remain > 0)
|
||||||
|
fee += (remain * (long)rate_bp * mul[3]) / 10000L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 은행가 반올림(사사오입, 짝수 반올림)으로 unit 배수 정규화 */
|
||||||
long lg_cu_0001_round_unit(long amount, long unit)
|
long lg_cu_0001_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r, half;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
half = unit / 2;
|
||||||
|
if (r > half || (r == half && (q & 1L)))
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 자릿수(log10) 규모로 5단계 분류 */
|
||||||
int lg_cu_0001_classify(long amount)
|
int lg_cu_0001_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int digits = 0;
|
||||||
if (amount < 1000000L)
|
while (v > 0) { digits++; v /= 10; }
|
||||||
return 1;
|
if (digits <= 3) return 0;
|
||||||
return 2;
|
if (digits <= 5) return 1;
|
||||||
|
if (digits <= 7) return 2;
|
||||||
|
if (digits <= 9) return 3;
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,48 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 원리금 이자액: rate_bp 연이율을 월할(1/12) 적용 */
|
||||||
long lg_cu_0002_fee(long amount, int rate_bp)
|
long lg_cu_0002_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long annual_bp;
|
||||||
|
long interest;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
annual_bp = (long)rate_bp;
|
||||||
if (fee < 0)
|
interest = (amount * annual_bp) / (10000L * 12L);
|
||||||
fee = 0;
|
if (interest < 0)
|
||||||
return fee;
|
interest = 0;
|
||||||
|
return interest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(오사오입, 0.5 이상 올림)으로 unit 정규화 */
|
||||||
long lg_cu_0002_round_unit(long amount, long unit)
|
long lg_cu_0002_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* Luhn 체크섬 유효성으로 분류: 유효=2, 무효 소액=0, 무효 고액=1 */
|
||||||
int lg_cu_0002_classify(long amount)
|
int lg_cu_0002_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int sum = 0, alt = 0, d;
|
||||||
if (amount < 1000000L)
|
long t = v;
|
||||||
return 1;
|
while (t > 0) {
|
||||||
return 2;
|
d = (int)(t % 10);
|
||||||
|
if (alt) { d *= 2; if (d > 9) d -= 9; }
|
||||||
|
sum += d;
|
||||||
|
alt = !alt;
|
||||||
|
t /= 10;
|
||||||
|
}
|
||||||
|
if (sum % 10 == 0)
|
||||||
|
return 2;
|
||||||
|
return v < 1000000L ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,45 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 일할 정산: rate_bp 를 경과일(1..10000) 비율로 안분한다 */
|
||||||
long lg_cu_0003_fee(long amount, int rate_bp)
|
long lg_cu_0003_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long days, prorated;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
days = (long)rate_bp;
|
||||||
if (fee < 0)
|
if (days > 10000L)
|
||||||
fee = 0;
|
days = 10000L;
|
||||||
return fee;
|
prorated = (amount * days) / 10000L;
|
||||||
|
return prorated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(절대값 0.5 기준 올림, 부호 보존)으로 unit 정규화 */
|
||||||
long lg_cu_0003_round_unit(long amount, long unit)
|
long lg_cu_0003_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long a, q, r, res;
|
||||||
|
int neg;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
neg = amount < 0;
|
||||||
|
a = neg ? -amount : amount;
|
||||||
|
q = a / unit;
|
||||||
|
r = a - q * unit;
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q += 1;
|
||||||
|
res = q * unit;
|
||||||
|
return neg ? -res : res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 디지털 루트(반복 자릿수합)로 분류 */
|
||||||
int lg_cu_0003_classify(long amount)
|
int lg_cu_0003_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
int root;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
root = (int)(1 + (v - 1) % 9);
|
||||||
return 1;
|
if (root <= 3) return 0;
|
||||||
|
if (root <= 6) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,51 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* FNV 해시로 결정적 가산분을 산출하는 보조 함수 */
|
||||||
|
static unsigned long lg_cu_0004_mix(long x)
|
||||||
|
{
|
||||||
|
unsigned long h = 1469598103934665603UL;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
h ^= (unsigned long)((x >> (i * 8)) & 0xFF);
|
||||||
|
h *= 1099511628211UL;
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 해시 기반 가산 수수료: 기본 수수료에 결정적 잔돈을 더한다 */
|
||||||
long lg_cu_0004_fee(long amount, int rate_bp)
|
long lg_cu_0004_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long base, extra;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
base = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
extra = (long)(lg_cu_0004_mix(amount) % 100UL);
|
||||||
fee = 0;
|
return base + extra;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 올림(상향)으로 unit 배수 정규화 */
|
||||||
long lg_cu_0004_round_unit(long amount, long unit)
|
long lg_cu_0004_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r > 0)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* BIN 범위표로 분류: 상위 6자리를 카드 BIN 처럼 구간 판정 */
|
||||||
int lg_cu_0004_classify(long amount)
|
int lg_cu_0004_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
long bin = v;
|
||||||
if (amount < 1000000L)
|
while (bin >= 1000000L)
|
||||||
return 1;
|
bin /= 10;
|
||||||
return 2;
|
if (bin >= 400000L && bin <= 499999L) return 1;
|
||||||
|
if (bin >= 510000L && bin <= 559999L) return 2;
|
||||||
|
if (bin >= 340000L && bin <= 379999L) return 3;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,39 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 통화 스케일 환산 수수료: minor unit 로 확장 후 요율 적용, major 복귀 */
|
||||||
long lg_cu_0005_fee(long amount, int rate_bp)
|
long lg_cu_0005_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long scaled, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
scaled = amount * 100L;
|
||||||
if (fee < 0)
|
fee = (scaled * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
fee = fee / 100L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 내림(음의 무한대 방향)으로 unit 정규화 */
|
||||||
long lg_cu_0005_round_unit(long amount, long unit)
|
long lg_cu_0005_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0)
|
||||||
|
q -= 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 임계값 테이블 이분 탐색으로 백분위 버킷 분류 */
|
||||||
int lg_cu_0005_classify(long amount)
|
int lg_cu_0005_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long th[] = { 5000L, 50000L, 500000L, 5000000L, 50000000L };
|
||||||
return 0;
|
int lo = 0, hi = 5, mid;
|
||||||
if (amount < 1000000L)
|
while (lo < hi) {
|
||||||
return 1;
|
mid = (lo + hi) / 2;
|
||||||
return 2;
|
if (amount < th[mid]) hi = mid; else lo = mid + 1;
|
||||||
|
}
|
||||||
|
return lo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,38 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 상계(netting) 수수료: 기준 30bp 에서 rate_bp 크레딧을 차감한 순수수료 */
|
||||||
long lg_cu_0006_fee(long amount, int rate_bp)
|
long lg_cu_0006_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long gross, credit, net;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
gross = (amount * 30L) / 10000L;
|
||||||
if (fee < 0)
|
credit = (amount * (long)(rate_bp < 0 ? 0 : rate_bp)) / 10000L;
|
||||||
fee = 0;
|
net = gross - credit;
|
||||||
return fee;
|
if (net < 0)
|
||||||
|
net = 0;
|
||||||
|
return net;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 절사(0 방향)으로 unit 정규화 */
|
||||||
long lg_cu_0006_round_unit(long amount, long unit)
|
long lg_cu_0006_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 비트맵 플래그 합성 분류: 특성 비트를 OR 로 조합 */
|
||||||
int lg_cu_0006_classify(long amount)
|
int lg_cu_0006_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int flags = 0;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
if (amount < 0) flags |= 0x1;
|
||||||
return 1;
|
if (v % 2 == 0) flags |= 0x2;
|
||||||
return 2;
|
if (v >= 1000000L) flags |= 0x4;
|
||||||
|
if (v % 1000L == 0) flags |= 0x8;
|
||||||
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 할부 분할 수수료: rate_bp 를 할부개월(1..60)로 보고 회차수수료 산정 */
|
||||||
long lg_cu_0007_fee(long amount, int rate_bp)
|
long lg_cu_0007_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long n, per;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
n = rate_bp <= 0 ? 1 : (rate_bp > 60 ? 60 : rate_bp);
|
||||||
if (fee < 0)
|
per = amount / n;
|
||||||
fee = 0;
|
if (amount % n != 0)
|
||||||
return fee;
|
per += 1;
|
||||||
|
return per;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(0.5 초과에서만 올림, 정확히 0.5는 내림)으로 unit 정규화 */
|
||||||
long lg_cu_0007_round_unit(long amount, long unit)
|
long lg_cu_0007_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
if (r * 2 > unit)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 날짜 산술: amount 를 YYYYMMDD 로 보고 Zeller 공식으로 요일 분류(0=일..6=토) */
|
||||||
int lg_cu_0007_classify(long amount)
|
int lg_cu_0007_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y = (int)(amount / 10000L);
|
||||||
return 0;
|
int m = (int)((amount / 100L) % 100L);
|
||||||
if (amount < 1000000L)
|
int d = (int)(amount % 100L);
|
||||||
return 1;
|
int k, j, h;
|
||||||
return 2;
|
if (m < 1 || m > 12 || d < 1 || d > 31)
|
||||||
|
return -1;
|
||||||
|
if (m < 3) { m += 12; y -= 1; }
|
||||||
|
k = y % 100; j = y / 100;
|
||||||
|
h = (d + (13 * (m + 1)) / 5 + k + k / 4 + j / 4 + 5 * j) % 7;
|
||||||
|
return (h + 6) % 7;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,57 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 상·하한 적용 정률 수수료 */
|
||||||
long lg_cu_0008_fee(long amount, int rate_bp)
|
long lg_cu_0008_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee;
|
||||||
|
const long floor_fee = 100L;
|
||||||
|
const long cap_fee = 500000L;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
fee = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
if (fee < floor_fee)
|
||||||
fee = 0;
|
fee = floor_fee;
|
||||||
|
if (fee > cap_fee)
|
||||||
|
fee = cap_fee;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최근접 배수 선택: 아래/위 배수 중 더 가까운 쪽으로 정규화 */
|
||||||
long lg_cu_0008_round_unit(long amount, long unit)
|
long lg_cu_0008_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long down, up, dd, du;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
if (amount % unit == 0)
|
||||||
|
return amount;
|
||||||
|
down = (amount / unit) * unit;
|
||||||
|
if (amount > 0)
|
||||||
|
up = down + unit;
|
||||||
|
else
|
||||||
|
up = down - unit;
|
||||||
|
dd = amount - down; if (dd < 0) dd = -dd;
|
||||||
|
du = up - amount; if (du < 0) du = -du;
|
||||||
|
return dd <= du ? down : up;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* amount 를 YYYYMMDD 로 보고 월말/윤년 유효성 분류: 0=무효 1=정상 2=월말 */
|
||||||
int lg_cu_0008_classify(long amount)
|
int lg_cu_0008_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y = (int)(amount / 10000L);
|
||||||
|
int m = (int)((amount / 100L) % 100L);
|
||||||
|
int d = (int)(amount % 100L);
|
||||||
|
int dim[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
|
int leap, last;
|
||||||
|
if (m < 1 || m > 12 || d < 1)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
|
||||||
return 1;
|
last = dim[m - 1];
|
||||||
return 2;
|
if (m == 2 && leap)
|
||||||
|
last = 29;
|
||||||
|
if (d > last)
|
||||||
|
return 0;
|
||||||
|
if (d == last)
|
||||||
|
return 2;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,43 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 복리형 단계 수수료: 기본 수수료에 2차(수수료에 대한) 수수료를 가산 */
|
||||||
long lg_cu_0009_fee(long amount, int rate_bp)
|
long lg_cu_0009_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long f1, f2;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
f1 = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
f2 = (f1 * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
return f1 + f2;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최대공약수 계산 보조 함수 */
|
||||||
|
static long lg_cu_0009_gcd(long a, long b)
|
||||||
|
{
|
||||||
|
a = a < 0 ? -a : a;
|
||||||
|
b = b < 0 ? -b : b;
|
||||||
|
while (b) { long t = a % b; a = b; b = t; }
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GCD 기반 유효 배수로 절사 정규화 */
|
||||||
long lg_cu_0009_round_unit(long amount, long unit)
|
long lg_cu_0009_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long g, step;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
g = lg_cu_0009_gcd(amount, unit);
|
||||||
|
step = g > 0 ? g : unit;
|
||||||
|
return (amount / step) * step;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 나머지 패턴(mod 7)으로 분류 */
|
||||||
int lg_cu_0009_classify(long amount)
|
int lg_cu_0009_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int r = (int)(v % 7L);
|
||||||
if (amount < 1000000L)
|
if (r == 0) return 0;
|
||||||
return 1;
|
if (r <= 3) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,35 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 마스킹 후 수수료: 하위 2자리를 마스킹한 금액에 요율 적용 */
|
||||||
long lg_cu_0010_fee(long amount, int rate_bp)
|
long lg_cu_0010_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long masked, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
masked = (amount / 100L) * 100L;
|
||||||
if (fee < 0)
|
fee = (masked * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 고정소수점 스케일(x2) 반올림으로 unit 정규화 */
|
||||||
long lg_cu_0010_round_unit(long amount, long unit)
|
long lg_cu_0010_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long scaled, q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
scaled = amount * 2L + (amount >= 0 ? unit : -unit);
|
||||||
|
q = scaled / (unit * 2L);
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 비트 개수(popcount)로 분류 */
|
||||||
int lg_cu_0010_classify(long amount)
|
int lg_cu_0010_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
unsigned long v = (unsigned long)(amount < 0 ? -amount : amount);
|
||||||
return 0;
|
int bits = 0;
|
||||||
if (amount < 1000000L)
|
while (v) { bits += (int)(v & 1UL); v >>= 1; }
|
||||||
return 1;
|
if (bits <= 4) return 0;
|
||||||
|
if (bits <= 8) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,59 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* CRC16(CCITT) 계산 보조 함수 */
|
||||||
|
static unsigned int lg_cu_0011_crc16(long x)
|
||||||
|
{
|
||||||
|
unsigned int crc = 0xFFFF;
|
||||||
|
unsigned char buf[8];
|
||||||
|
int i, b;
|
||||||
|
for (i = 0; i < 8; i++)
|
||||||
|
buf[i] = (unsigned char)((x >> (i * 8)) & 0xFF);
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
crc ^= (unsigned int)buf[i] << 8;
|
||||||
|
for (b = 0; b < 8; b++)
|
||||||
|
crc = (crc & 0x8000) ? (unsigned int)((crc << 1) ^ 0x1021)
|
||||||
|
: (unsigned int)(crc << 1);
|
||||||
|
}
|
||||||
|
return crc & 0xFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CRC16 혼합 가산 수수료: 기본 수수료에 결정적 소액 가산분을 더한다 */
|
||||||
long lg_cu_0011_fee(long amount, int rate_bp)
|
long lg_cu_0011_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long base;
|
||||||
|
unsigned int c;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
base = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
c = lg_cu_0011_crc16(amount);
|
||||||
fee = 0;
|
return base + (long)(c % 50U);
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 상향 임계 반올림((unit+1)/2 기준)으로 unit 정규화 */
|
||||||
long lg_cu_0011_round_unit(long amount, long unit)
|
long lg_cu_0011_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r, threshold;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
threshold = (unit + 1) / 2;
|
||||||
|
if (r >= threshold)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 누적분포(CDF) 근사 스캔으로 백분위 분류 */
|
||||||
int lg_cu_0011_classify(long amount)
|
int lg_cu_0011_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long cum[] = { 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L };
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
int i;
|
||||||
return 1;
|
for (i = 0; i < 6; i++) {
|
||||||
return 2;
|
if (v < cum[i])
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,52 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* Luhn(mod-10) 체크섬 계산: 우대카드 판별용 */
|
||||||
|
static int mg_cu_0001_luhn(long v)
|
||||||
|
{
|
||||||
|
int sum = 0, alt = 0;
|
||||||
|
if (v < 0) v = -v;
|
||||||
|
while (v > 0) {
|
||||||
|
int d = (int)(v % 10);
|
||||||
|
if (alt) { d *= 2; if (d > 9) d -= 9; }
|
||||||
|
sum += d;
|
||||||
|
alt = !alt;
|
||||||
|
v /= 10;
|
||||||
|
}
|
||||||
|
return sum % 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: Luhn 체크섬이 0(정상 카드)이면 면제, 그 외 정률 */
|
||||||
long mg_cu_0001_fee(long amount, int rate_bp)
|
long mg_cu_0001_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
if (mg_cu_0001_luhn(amount) == 0)
|
||||||
if (fee < 0)
|
return 0;
|
||||||
fee = 0;
|
return (amount * (long)rate_bp) / 10000L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(round-half-up) 단위 정규화 */
|
||||||
long mg_cu_0001_round_unit(long amount, long unit)
|
long mg_cu_0001_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r, half;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
half = unit / 2;
|
||||||
|
amount -= r;
|
||||||
|
if (r >= half)
|
||||||
|
amount += unit;
|
||||||
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 10진 자릿수 개수 반환 */
|
||||||
int mg_cu_0001_classify(long amount)
|
int mg_cu_0001_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int digits = 0;
|
||||||
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
while (v > 0) { digits++; v /= 10; }
|
||||||
return 1;
|
return digits;
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,54 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* BIN 범위 조회: 카드 앞 6자리 → 등급 */
|
||||||
|
static int mg_cu_0002_bin_grade(long n)
|
||||||
|
{
|
||||||
|
static const long lo[3] = {400000L, 510000L, 600000L};
|
||||||
|
static const long hi[3] = {499999L, 559999L, 699999L};
|
||||||
|
long bin = n < 0 ? -n : n;
|
||||||
|
int i;
|
||||||
|
while (bin >= 1000000L)
|
||||||
|
bin /= 10;
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
if (bin >= lo[i] && bin <= hi[i])
|
||||||
|
return i + 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 카드 등급별 가산 bp 적용 */
|
||||||
long mg_cu_0002_fee(long amount, int rate_bp)
|
long mg_cu_0002_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
int g;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
g = mg_cu_0002_bin_grade(amount);
|
||||||
if (fee < 0)
|
rate_bp += g * 5;
|
||||||
fee = 0;
|
return (amount * (long)rate_bp) / 10000L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 올림(ceil) 단위 정규화 */
|
||||||
long mg_cu_0002_round_unit(long amount, long unit)
|
long mg_cu_0002_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
if (r == 0)
|
||||||
|
return amount;
|
||||||
|
if (r < 0)
|
||||||
|
return amount - r;
|
||||||
|
return amount + (unit - r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 퍼센타일 경계 버킷(0~9) */
|
||||||
int mg_cu_0002_classify(long amount)
|
int mg_cu_0002_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long b[9] = {1000L, 5000L, 10000L, 50000L, 100000L,
|
||||||
return 0;
|
500000L, 1000000L, 5000000L, 10000000L};
|
||||||
if (amount < 1000000L)
|
int i;
|
||||||
return 1;
|
for (i = 0; i < 9; i++)
|
||||||
return 2;
|
if (amount < b[i])
|
||||||
|
return i;
|
||||||
|
return 9;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,53 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* Zeller 합동식으로 요일 계산: 0=토,1=일,...,6=금 */
|
||||||
|
static int mg_cu_0003_dow(int y, int m, int d)
|
||||||
|
{
|
||||||
|
int k, j;
|
||||||
|
if (m < 3) { m += 12; y--; }
|
||||||
|
k = y % 100;
|
||||||
|
j = y / 100;
|
||||||
|
return (d + 13 * (m + 1) / 5 + k + k / 4 + j / 4 + 5 * j) % 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: amount=YYYYMMDD, 주말이면 할증 rate 반환 */
|
||||||
long mg_cu_0003_fee(long amount, int rate_bp)
|
long mg_cu_0003_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
int y, m, d, w;
|
||||||
|
long base;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
y = (int)(amount / 10000L);
|
||||||
if (fee < 0)
|
m = (int)((amount / 100L) % 100L);
|
||||||
fee = 0;
|
d = (int)(amount % 100L);
|
||||||
return fee;
|
w = mg_cu_0003_dow(y, m, d);
|
||||||
|
base = rate_bp;
|
||||||
|
if (w == 0 || w == 1)
|
||||||
|
base += (long)rate_bp / 10;
|
||||||
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 내림(floor) 단위 정규화: 음수 방향 보정 */
|
||||||
long mg_cu_0003_round_unit(long amount, long unit)
|
long mg_cu_0003_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
if (amount % unit != 0 && amount < 0)
|
||||||
|
q--;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: YYYYMMDD 의 요일(0~6), 오류 -1 */
|
||||||
int mg_cu_0003_classify(long amount)
|
int mg_cu_0003_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y, m, d;
|
||||||
return 0;
|
if (amount <= 0)
|
||||||
if (amount < 1000000L)
|
return -1;
|
||||||
return 1;
|
y = (int)(amount / 10000L);
|
||||||
return 2;
|
m = (int)((amount / 100L) % 100L);
|
||||||
|
d = (int)(amount % 100L);
|
||||||
|
return mg_cu_0003_dow(y, m, d);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,45 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 뱅커스 반올림(사사오입): num/den 을 최근접 정수로, 동점은 짝수 */
|
||||||
|
static long mg_cu_0004_bankers(long num, long den)
|
||||||
|
{
|
||||||
|
long q = num / den;
|
||||||
|
long r = num % den;
|
||||||
|
long twice = 2 * (r < 0 ? -r : r);
|
||||||
|
long ad = den < 0 ? -den : den;
|
||||||
|
if (twice > ad)
|
||||||
|
q += (num < 0 ? -1 : 1);
|
||||||
|
else if (twice == ad && (q % 2 != 0))
|
||||||
|
q += (num < 0 ? -1 : 1);
|
||||||
|
return q;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 초과분에만 요율 적용하는 누진 구간 */
|
||||||
long mg_cu_0004_fee(long amount, int rate_bp)
|
long mg_cu_0004_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee = 0, a = amount;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
if (a > 1000000L) { fee += (a - 1000000L) * (long)rate_bp / 10000L; a = 1000000L; }
|
||||||
if (fee < 0)
|
if (a > 100000L) { fee += (a - 100000L) * (long)(rate_bp + 10) / 10000L; a = 100000L; }
|
||||||
fee = 0;
|
fee += a * (long)(rate_bp + 20) / 10000L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 뱅커스 반올림 단위 정규화 */
|
||||||
long mg_cu_0004_round_unit(long amount, long unit)
|
long mg_cu_0004_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
return mg_cu_0004_bankers(amount, unit) * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 10의 거듭제곱 지수(로그10 정수부) */
|
||||||
int mg_cu_0004_classify(long amount)
|
int mg_cu_0004_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int e = 0;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
while (v >= 10) { v /= 10; e++; }
|
||||||
return 1;
|
return e;
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,49 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* CRC-8(다항식 0x07) 계산: 고정길이 필드 무결성 */
|
||||||
|
static unsigned mg_cu_0005_crc8(const char *s, int n)
|
||||||
|
{
|
||||||
|
unsigned crc = 0;
|
||||||
|
int i, b;
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
crc ^= (unsigned char)s[i];
|
||||||
|
for (b = 0; b < 8; b++)
|
||||||
|
crc = (crc & 0x80) ? ((crc << 1) ^ 0x07) & 0xFF : (crc << 1) & 0xFF;
|
||||||
|
}
|
||||||
|
return crc & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 금액을 12자리 고정필드로 pack 후 CRC 가산 */
|
||||||
long mg_cu_0005_fee(long amount, int rate_bp)
|
long mg_cu_0005_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
char buf[16];
|
||||||
|
long v = amount < 0 ? 0 : amount;
|
||||||
|
int i;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 11; i >= 0; i--) { buf[i] = (char)('0' + (int)(v % 10)); v /= 10; }
|
||||||
if (fee < 0)
|
buf[12] = '\0';
|
||||||
fee = 0;
|
return (amount * (long)rate_bp) / 10000L + (long)mg_cu_0005_crc8(buf, 12);
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최근접 배수 반올림(round-half-away-from-zero) */
|
||||||
long mg_cu_0005_round_unit(long amount, long unit)
|
long mg_cu_0005_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r, h;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
h = (unit + 1) / 2;
|
||||||
|
if (r < 0)
|
||||||
|
return (-r >= h) ? amount - (unit + r) : amount - r;
|
||||||
|
return (r >= h) ? amount + (unit - r) : amount - r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 부호·홀짝 조합 4가지 */
|
||||||
int mg_cu_0005_classify(long amount)
|
int mg_cu_0005_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int s = amount < 0 ? 2 : 0;
|
||||||
return 0;
|
int p = (amount % 2 != 0) ? 1 : 0;
|
||||||
if (amount < 1000000L)
|
return s + p;
|
||||||
return 1;
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,39 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 수수료: 12개월 균등분할 잔액에 대한 단리 이자 합 */
|
||||||
long mg_cu_0006_fee(long amount, int rate_bp)
|
long mg_cu_0006_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long total = 0, principal;
|
||||||
|
int m;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
principal = amount / 12;
|
||||||
if (fee < 0)
|
for (m = 1; m <= 12; m++) {
|
||||||
fee = 0;
|
long bal = amount - principal * (m - 1);
|
||||||
return fee;
|
total += bal * (long)rate_bp / 120000L;
|
||||||
|
}
|
||||||
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 잔돈 재분배 반올림: 잔여의 2배가 unit 이상이면 올림 */
|
||||||
long mg_cu_0006_round_unit(long amount, long unit)
|
long mg_cu_0006_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long base, rem;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
base = (amount / unit) * unit;
|
||||||
|
rem = amount - base;
|
||||||
|
return (rem * 2 >= unit) ? base + unit : base;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 최상위(선두) 숫자 1~9 */
|
||||||
int mg_cu_0006_classify(long amount)
|
int mg_cu_0006_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
while (v >= 10)
|
||||||
return 1;
|
v /= 10;
|
||||||
return 2;
|
return (int)v;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,33 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 수수료: 소수 2자리 스케일로 확대 후 요율 적용, 원 단위 복귀 */
|
||||||
long mg_cu_0007_fee(long amount, int rate_bp)
|
long mg_cu_0007_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long scaled, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
scaled = amount * 100L;
|
||||||
if (fee < 0)
|
fee = scaled * (long)rate_bp / 10000L;
|
||||||
fee = 0;
|
return fee / 100L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 단위가 2의 거듭제곱이면 비트마스크 정렬, 아니면 일반 절사 */
|
||||||
long mg_cu_0007_round_unit(long amount, long unit)
|
long mg_cu_0007_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
|
if ((unit & (unit - 1)) == 0)
|
||||||
|
return amount & ~(unit - 1);
|
||||||
return (amount / unit) * unit;
|
return (amount / unit) * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 금액 구간 비트맵 플래그(bit0=만,bit1=십만,bit2=백만) */
|
||||||
int mg_cu_0007_classify(long amount)
|
int mg_cu_0007_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int f = 0;
|
||||||
return 0;
|
if (amount >= 10000L) f |= 1;
|
||||||
if (amount < 1000000L)
|
if (amount >= 100000L) f |= 2;
|
||||||
return 1;
|
if (amount >= 1000000L) f |= 4;
|
||||||
return 2;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 수수료: 금액 구간별 요율을 선형보간하여 적용 */
|
||||||
long mg_cu_0008_fee(long amount, int rate_bp)
|
long mg_cu_0008_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
static const long x[4] = {0L, 100000L, 1000000L, 10000000L};
|
||||||
if (amount <= 0 || rate_bp < 0)
|
static const long y[4] = {30L, 20L, 10L, 5L};
|
||||||
|
long r = rate_bp;
|
||||||
|
int i;
|
||||||
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 0; i < 3; i++) {
|
||||||
if (fee < 0)
|
if (amount <= x[i + 1]) {
|
||||||
fee = 0;
|
long span = x[i + 1] - x[i];
|
||||||
return fee;
|
r = y[i] + (y[i + 1] - y[i]) * (amount - x[i]) / span;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return amount * r / 10000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 5사6입: 잔여가 unit 의 60% 이상일 때만 올림 */
|
||||||
long mg_cu_0008_round_unit(long amount, long unit)
|
long mg_cu_0008_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
return (r * 10 >= unit * 6) ? amount + (unit - r) : amount - r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 이진탐색으로 경계 버킷 결정 */
|
||||||
int mg_cu_0008_classify(long amount)
|
int mg_cu_0008_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long b[7] = {5000L, 20000L, 50000L, 200000L,
|
||||||
return 0;
|
500000L, 2000000L, 5000000L};
|
||||||
if (amount < 1000000L)
|
int lo = 0, hi = 7, mid;
|
||||||
return 1;
|
while (lo < hi) {
|
||||||
return 2;
|
mid = (lo + hi) / 2;
|
||||||
|
if (amount < b[mid]) hi = mid; else lo = mid + 1;
|
||||||
|
}
|
||||||
|
return lo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,35 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 그레고리력 → 율리우스일수 근사 변환 */
|
||||||
long mg_cu_0009_fee(long amount, int rate_bp)
|
static long mg_cu_0009_jdn(int y, int m, int d)
|
||||||
{
|
{
|
||||||
long fee;
|
long a = (14 - m) / 12;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
long yy = y + 4800 - a;
|
||||||
return 0;
|
long mm = m + 12 * a - 3;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
return d + (153 * mm + 2) / 5 + 365 * yy + yy / 4 - yy / 100 + yy / 400 - 32045;
|
||||||
if (fee < 0)
|
|
||||||
fee = 0;
|
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 수수료: amount=YYYYMMDD 에 rate_bp 영업일 더한 율리우스일 반환 */
|
||||||
|
long mg_cu_0009_fee(long amount, int rate_bp)
|
||||||
|
{
|
||||||
|
int y, m, d, added = 0;
|
||||||
|
long jd;
|
||||||
|
if (amount <= 0)
|
||||||
|
return 0;
|
||||||
|
y = (int)(amount / 10000L);
|
||||||
|
m = (int)((amount / 100L) % 100L);
|
||||||
|
d = (int)(amount % 100L);
|
||||||
|
jd = mg_cu_0009_jdn(y, m, d);
|
||||||
|
while (added < rate_bp) {
|
||||||
|
jd++;
|
||||||
|
if (jd % 7 != 5 && jd % 7 != 6)
|
||||||
|
added++;
|
||||||
|
}
|
||||||
|
return jd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 0 방향 대칭 절사(truncate toward zero) */
|
||||||
long mg_cu_0009_round_unit(long amount, long unit)
|
long mg_cu_0009_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
|
|
@ -26,12 +42,15 @@ long mg_cu_0009_round_unit(long amount, long unit)
|
||||||
return (amount / unit) * unit;
|
return (amount / unit) * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: FNV-1a 해시의 하위 3비트 */
|
||||||
int mg_cu_0009_classify(long amount)
|
int mg_cu_0009_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
unsigned long h = 2166136261UL;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
do {
|
||||||
return 1;
|
h ^= (unsigned long)(v % 10);
|
||||||
return 2;
|
h *= 16777619UL;
|
||||||
|
v /= 10;
|
||||||
|
} while (v > 0);
|
||||||
|
return (int)(h & 0x7UL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 디지털 루트(각 자리 합 반복) 계산 */
|
||||||
|
static int mg_cu_0010_droot(long v)
|
||||||
|
{
|
||||||
|
if (v < 0) v = -v;
|
||||||
|
while (v >= 10) {
|
||||||
|
long s = 0;
|
||||||
|
while (v > 0) { s += v % 10; v /= 10; }
|
||||||
|
v = s;
|
||||||
|
}
|
||||||
|
return (int)v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 정률 계산 후 상한(cap) 적용 */
|
||||||
long mg_cu_0010_fee(long amount, int rate_bp)
|
long mg_cu_0010_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee, cap = 50000L;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
fee = amount * (long)rate_bp / 10000L;
|
||||||
if (fee < 0)
|
if (fee > cap)
|
||||||
fee = 0;
|
fee = cap;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 이중 절사: 1차 절사 후 잔여 2/3 이상이면 한 단위 보정 */
|
||||||
long mg_cu_0010_round_unit(long amount, long unit)
|
long mg_cu_0010_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long f1;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
f1 = (amount / unit) * unit;
|
||||||
|
if ((amount - f1) * 3 >= unit * 2)
|
||||||
|
f1 += unit;
|
||||||
|
return f1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 디지털 루트(1~9, 0) */
|
||||||
int mg_cu_0010_classify(long amount)
|
int mg_cu_0010_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
return mg_cu_0010_droot(amount);
|
||||||
return 0;
|
|
||||||
if (amount < 1000000L)
|
|
||||||
return 1;
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,49 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 슬랩(구간별 고정액) 수수료 테이블 조회 */
|
||||||
|
static long mg_cu_0011_slab(long a)
|
||||||
|
{
|
||||||
|
static const long lim[4] = {10000L, 100000L, 1000000L, 10000000L};
|
||||||
|
static const long fixed[5] = {100L, 500L, 2000L, 8000L, 30000L};
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
if (a < lim[i])
|
||||||
|
return fixed[i];
|
||||||
|
return fixed[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 슬랩 고정액 + 미세 요율 가산 */
|
||||||
long mg_cu_0011_fee(long amount, int rate_bp)
|
long mg_cu_0011_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long f;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
f = mg_cu_0011_slab(amount);
|
||||||
if (fee < 0)
|
f += amount * (long)rate_bp / 100000L;
|
||||||
fee = 0;
|
return f;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 가장 가까운 배수(반올림, 동점은 올림) */
|
||||||
long mg_cu_0011_round_unit(long amount, long unit)
|
long mg_cu_0011_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount % unit;
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q++;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 통과한 임계 개수(0~5) */
|
||||||
int mg_cu_0011_classify(long amount)
|
int mg_cu_0011_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long g[5] = {1000L, 10000L, 100000L, 1000000L, 10000000L};
|
||||||
return 0;
|
int i, c = 0;
|
||||||
if (amount < 1000000L)
|
for (i = 0; i < 5; i++)
|
||||||
return 1;
|
if (amount >= g[i])
|
||||||
return 2;
|
c++;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,55 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 누진 구간 수수료: 금액 구간별 한계요율을 누적 적용한다 */
|
||||||
long mm_cu_0001_fee(long amount, int rate_bp)
|
long mm_cu_0001_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
static const long band[] = { 100000L, 1000000L, 10000000L };
|
||||||
|
static const int mul[] = { 1, 2, 3, 5 };
|
||||||
|
long remain = amount;
|
||||||
|
long fee = 0;
|
||||||
|
long prev = 0;
|
||||||
|
int i;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 0; i < 3; i++) {
|
||||||
if (fee < 0)
|
long span = band[i] - prev;
|
||||||
fee = 0;
|
long part = remain < span ? remain : span;
|
||||||
|
if (part <= 0)
|
||||||
|
break;
|
||||||
|
fee += (part * (long)rate_bp * mul[i]) / 10000L;
|
||||||
|
remain -= part;
|
||||||
|
prev = band[i];
|
||||||
|
}
|
||||||
|
if (remain > 0)
|
||||||
|
fee += (remain * (long)rate_bp * mul[3]) / 10000L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 은행가 반올림(사사오입, 짝수 반올림)으로 unit 배수 정규화 */
|
||||||
long mm_cu_0001_round_unit(long amount, long unit)
|
long mm_cu_0001_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r, half;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
half = unit / 2;
|
||||||
|
if (r > half || (r == half && (q & 1L)))
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 자릿수(log10) 규모로 5단계 분류 */
|
||||||
int mm_cu_0001_classify(long amount)
|
int mm_cu_0001_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int digits = 0;
|
||||||
if (amount < 1000000L)
|
while (v > 0) { digits++; v /= 10; }
|
||||||
return 1;
|
if (digits <= 3) return 0;
|
||||||
return 2;
|
if (digits <= 5) return 1;
|
||||||
|
if (digits <= 7) return 2;
|
||||||
|
if (digits <= 9) return 3;
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,48 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 원리금 이자액: rate_bp 연이율을 월할(1/12) 적용 */
|
||||||
long mm_cu_0002_fee(long amount, int rate_bp)
|
long mm_cu_0002_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long annual_bp;
|
||||||
|
long interest;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
annual_bp = (long)rate_bp;
|
||||||
if (fee < 0)
|
interest = (amount * annual_bp) / (10000L * 12L);
|
||||||
fee = 0;
|
if (interest < 0)
|
||||||
return fee;
|
interest = 0;
|
||||||
|
return interest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(오사오입, 0.5 이상 올림)으로 unit 정규화 */
|
||||||
long mm_cu_0002_round_unit(long amount, long unit)
|
long mm_cu_0002_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* Luhn 체크섬 유효성으로 분류: 유효=2, 무효 소액=0, 무효 고액=1 */
|
||||||
int mm_cu_0002_classify(long amount)
|
int mm_cu_0002_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int sum = 0, alt = 0, d;
|
||||||
if (amount < 1000000L)
|
long t = v;
|
||||||
return 1;
|
while (t > 0) {
|
||||||
return 2;
|
d = (int)(t % 10);
|
||||||
|
if (alt) { d *= 2; if (d > 9) d -= 9; }
|
||||||
|
sum += d;
|
||||||
|
alt = !alt;
|
||||||
|
t /= 10;
|
||||||
|
}
|
||||||
|
if (sum % 10 == 0)
|
||||||
|
return 2;
|
||||||
|
return v < 1000000L ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,45 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 일할 정산: rate_bp 를 경과일(1..10000) 비율로 안분한다 */
|
||||||
long mm_cu_0003_fee(long amount, int rate_bp)
|
long mm_cu_0003_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long days, prorated;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
days = (long)rate_bp;
|
||||||
if (fee < 0)
|
if (days > 10000L)
|
||||||
fee = 0;
|
days = 10000L;
|
||||||
return fee;
|
prorated = (amount * days) / 10000L;
|
||||||
|
return prorated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(절대값 0.5 기준 올림, 부호 보존)으로 unit 정규화 */
|
||||||
long mm_cu_0003_round_unit(long amount, long unit)
|
long mm_cu_0003_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long a, q, r, res;
|
||||||
|
int neg;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
neg = amount < 0;
|
||||||
|
a = neg ? -amount : amount;
|
||||||
|
q = a / unit;
|
||||||
|
r = a - q * unit;
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q += 1;
|
||||||
|
res = q * unit;
|
||||||
|
return neg ? -res : res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 디지털 루트(반복 자릿수합)로 분류 */
|
||||||
int mm_cu_0003_classify(long amount)
|
int mm_cu_0003_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
int root;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
root = (int)(1 + (v - 1) % 9);
|
||||||
return 1;
|
if (root <= 3) return 0;
|
||||||
|
if (root <= 6) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,51 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* FNV 해시로 결정적 가산분을 산출하는 보조 함수 */
|
||||||
|
static unsigned long mm_cu_0004_mix(long x)
|
||||||
|
{
|
||||||
|
unsigned long h = 1469598103934665603UL;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
h ^= (unsigned long)((x >> (i * 8)) & 0xFF);
|
||||||
|
h *= 1099511628211UL;
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 해시 기반 가산 수수료: 기본 수수료에 결정적 잔돈을 더한다 */
|
||||||
long mm_cu_0004_fee(long amount, int rate_bp)
|
long mm_cu_0004_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long base, extra;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
base = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
extra = (long)(mm_cu_0004_mix(amount) % 100UL);
|
||||||
fee = 0;
|
return base + extra;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 올림(상향)으로 unit 배수 정규화 */
|
||||||
long mm_cu_0004_round_unit(long amount, long unit)
|
long mm_cu_0004_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r > 0)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* BIN 범위표로 분류: 상위 6자리를 카드 BIN 처럼 구간 판정 */
|
||||||
int mm_cu_0004_classify(long amount)
|
int mm_cu_0004_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
long bin = v;
|
||||||
if (amount < 1000000L)
|
while (bin >= 1000000L)
|
||||||
return 1;
|
bin /= 10;
|
||||||
return 2;
|
if (bin >= 400000L && bin <= 499999L) return 1;
|
||||||
|
if (bin >= 510000L && bin <= 559999L) return 2;
|
||||||
|
if (bin >= 340000L && bin <= 379999L) return 3;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,39 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 통화 스케일 환산 수수료: minor unit 로 확장 후 요율 적용, major 복귀 */
|
||||||
long mm_cu_0005_fee(long amount, int rate_bp)
|
long mm_cu_0005_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long scaled, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
scaled = amount * 100L;
|
||||||
if (fee < 0)
|
fee = (scaled * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
fee = fee / 100L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 내림(음의 무한대 방향)으로 unit 정규화 */
|
||||||
long mm_cu_0005_round_unit(long amount, long unit)
|
long mm_cu_0005_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0)
|
||||||
|
q -= 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 임계값 테이블 이분 탐색으로 백분위 버킷 분류 */
|
||||||
int mm_cu_0005_classify(long amount)
|
int mm_cu_0005_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long th[] = { 5000L, 50000L, 500000L, 5000000L, 50000000L };
|
||||||
return 0;
|
int lo = 0, hi = 5, mid;
|
||||||
if (amount < 1000000L)
|
while (lo < hi) {
|
||||||
return 1;
|
mid = (lo + hi) / 2;
|
||||||
return 2;
|
if (amount < th[mid]) hi = mid; else lo = mid + 1;
|
||||||
|
}
|
||||||
|
return lo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,38 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 상계(netting) 수수료: 기준 30bp 에서 rate_bp 크레딧을 차감한 순수수료 */
|
||||||
long mm_cu_0006_fee(long amount, int rate_bp)
|
long mm_cu_0006_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long gross, credit, net;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
gross = (amount * 30L) / 10000L;
|
||||||
if (fee < 0)
|
credit = (amount * (long)(rate_bp < 0 ? 0 : rate_bp)) / 10000L;
|
||||||
fee = 0;
|
net = gross - credit;
|
||||||
return fee;
|
if (net < 0)
|
||||||
|
net = 0;
|
||||||
|
return net;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 절사(0 방향)으로 unit 정규화 */
|
||||||
long mm_cu_0006_round_unit(long amount, long unit)
|
long mm_cu_0006_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 비트맵 플래그 합성 분류: 특성 비트를 OR 로 조합 */
|
||||||
int mm_cu_0006_classify(long amount)
|
int mm_cu_0006_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int flags = 0;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
if (amount < 0) flags |= 0x1;
|
||||||
return 1;
|
if (v % 2 == 0) flags |= 0x2;
|
||||||
return 2;
|
if (v >= 1000000L) flags |= 0x4;
|
||||||
|
if (v % 1000L == 0) flags |= 0x8;
|
||||||
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 할부 분할 수수료: rate_bp 를 할부개월(1..60)로 보고 회차수수료 산정 */
|
||||||
long mm_cu_0007_fee(long amount, int rate_bp)
|
long mm_cu_0007_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long n, per;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
n = rate_bp <= 0 ? 1 : (rate_bp > 60 ? 60 : rate_bp);
|
||||||
if (fee < 0)
|
per = amount / n;
|
||||||
fee = 0;
|
if (amount % n != 0)
|
||||||
return fee;
|
per += 1;
|
||||||
|
return per;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(0.5 초과에서만 올림, 정확히 0.5는 내림)으로 unit 정규화 */
|
||||||
long mm_cu_0007_round_unit(long amount, long unit)
|
long mm_cu_0007_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
if (r * 2 > unit)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 날짜 산술: amount 를 YYYYMMDD 로 보고 Zeller 공식으로 요일 분류(0=일..6=토) */
|
||||||
int mm_cu_0007_classify(long amount)
|
int mm_cu_0007_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y = (int)(amount / 10000L);
|
||||||
return 0;
|
int m = (int)((amount / 100L) % 100L);
|
||||||
if (amount < 1000000L)
|
int d = (int)(amount % 100L);
|
||||||
return 1;
|
int k, j, h;
|
||||||
return 2;
|
if (m < 1 || m > 12 || d < 1 || d > 31)
|
||||||
|
return -1;
|
||||||
|
if (m < 3) { m += 12; y -= 1; }
|
||||||
|
k = y % 100; j = y / 100;
|
||||||
|
h = (d + (13 * (m + 1)) / 5 + k + k / 4 + j / 4 + 5 * j) % 7;
|
||||||
|
return (h + 6) % 7;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,57 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 상·하한 적용 정률 수수료 */
|
||||||
long mm_cu_0008_fee(long amount, int rate_bp)
|
long mm_cu_0008_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee;
|
||||||
|
const long floor_fee = 100L;
|
||||||
|
const long cap_fee = 500000L;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
fee = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
if (fee < floor_fee)
|
||||||
fee = 0;
|
fee = floor_fee;
|
||||||
|
if (fee > cap_fee)
|
||||||
|
fee = cap_fee;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최근접 배수 선택: 아래/위 배수 중 더 가까운 쪽으로 정규화 */
|
||||||
long mm_cu_0008_round_unit(long amount, long unit)
|
long mm_cu_0008_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long down, up, dd, du;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
if (amount % unit == 0)
|
||||||
|
return amount;
|
||||||
|
down = (amount / unit) * unit;
|
||||||
|
if (amount > 0)
|
||||||
|
up = down + unit;
|
||||||
|
else
|
||||||
|
up = down - unit;
|
||||||
|
dd = amount - down; if (dd < 0) dd = -dd;
|
||||||
|
du = up - amount; if (du < 0) du = -du;
|
||||||
|
return dd <= du ? down : up;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* amount 를 YYYYMMDD 로 보고 월말/윤년 유효성 분류: 0=무효 1=정상 2=월말 */
|
||||||
int mm_cu_0008_classify(long amount)
|
int mm_cu_0008_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y = (int)(amount / 10000L);
|
||||||
|
int m = (int)((amount / 100L) % 100L);
|
||||||
|
int d = (int)(amount % 100L);
|
||||||
|
int dim[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
|
int leap, last;
|
||||||
|
if (m < 1 || m > 12 || d < 1)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
|
||||||
return 1;
|
last = dim[m - 1];
|
||||||
return 2;
|
if (m == 2 && leap)
|
||||||
|
last = 29;
|
||||||
|
if (d > last)
|
||||||
|
return 0;
|
||||||
|
if (d == last)
|
||||||
|
return 2;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,43 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 복리형 단계 수수료: 기본 수수료에 2차(수수료에 대한) 수수료를 가산 */
|
||||||
long mm_cu_0009_fee(long amount, int rate_bp)
|
long mm_cu_0009_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long f1, f2;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
f1 = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
f2 = (f1 * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
return f1 + f2;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최대공약수 계산 보조 함수 */
|
||||||
|
static long mm_cu_0009_gcd(long a, long b)
|
||||||
|
{
|
||||||
|
a = a < 0 ? -a : a;
|
||||||
|
b = b < 0 ? -b : b;
|
||||||
|
while (b) { long t = a % b; a = b; b = t; }
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GCD 기반 유효 배수로 절사 정규화 */
|
||||||
long mm_cu_0009_round_unit(long amount, long unit)
|
long mm_cu_0009_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long g, step;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
g = mm_cu_0009_gcd(amount, unit);
|
||||||
|
step = g > 0 ? g : unit;
|
||||||
|
return (amount / step) * step;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 나머지 패턴(mod 7)으로 분류 */
|
||||||
int mm_cu_0009_classify(long amount)
|
int mm_cu_0009_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int r = (int)(v % 7L);
|
||||||
if (amount < 1000000L)
|
if (r == 0) return 0;
|
||||||
return 1;
|
if (r <= 3) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,35 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 마스킹 후 수수료: 하위 2자리를 마스킹한 금액에 요율 적용 */
|
||||||
long mm_cu_0010_fee(long amount, int rate_bp)
|
long mm_cu_0010_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long masked, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
masked = (amount / 100L) * 100L;
|
||||||
if (fee < 0)
|
fee = (masked * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 고정소수점 스케일(x2) 반올림으로 unit 정규화 */
|
||||||
long mm_cu_0010_round_unit(long amount, long unit)
|
long mm_cu_0010_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long scaled, q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
scaled = amount * 2L + (amount >= 0 ? unit : -unit);
|
||||||
|
q = scaled / (unit * 2L);
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 비트 개수(popcount)로 분류 */
|
||||||
int mm_cu_0010_classify(long amount)
|
int mm_cu_0010_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
unsigned long v = (unsigned long)(amount < 0 ? -amount : amount);
|
||||||
return 0;
|
int bits = 0;
|
||||||
if (amount < 1000000L)
|
while (v) { bits += (int)(v & 1UL); v >>= 1; }
|
||||||
return 1;
|
if (bits <= 4) return 0;
|
||||||
|
if (bits <= 8) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,59 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* CRC16(CCITT) 계산 보조 함수 */
|
||||||
|
static unsigned int mm_cu_0011_crc16(long x)
|
||||||
|
{
|
||||||
|
unsigned int crc = 0xFFFF;
|
||||||
|
unsigned char buf[8];
|
||||||
|
int i, b;
|
||||||
|
for (i = 0; i < 8; i++)
|
||||||
|
buf[i] = (unsigned char)((x >> (i * 8)) & 0xFF);
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
crc ^= (unsigned int)buf[i] << 8;
|
||||||
|
for (b = 0; b < 8; b++)
|
||||||
|
crc = (crc & 0x8000) ? (unsigned int)((crc << 1) ^ 0x1021)
|
||||||
|
: (unsigned int)(crc << 1);
|
||||||
|
}
|
||||||
|
return crc & 0xFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CRC16 혼합 가산 수수료: 기본 수수료에 결정적 소액 가산분을 더한다 */
|
||||||
long mm_cu_0011_fee(long amount, int rate_bp)
|
long mm_cu_0011_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long base;
|
||||||
|
unsigned int c;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
base = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
c = mm_cu_0011_crc16(amount);
|
||||||
fee = 0;
|
return base + (long)(c % 50U);
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 상향 임계 반올림((unit+1)/2 기준)으로 unit 정규화 */
|
||||||
long mm_cu_0011_round_unit(long amount, long unit)
|
long mm_cu_0011_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r, threshold;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
threshold = (unit + 1) / 2;
|
||||||
|
if (r >= threshold)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 누적분포(CDF) 근사 스캔으로 백분위 분류 */
|
||||||
int mm_cu_0011_classify(long amount)
|
int mm_cu_0011_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long cum[] = { 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L };
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
int i;
|
||||||
return 1;
|
for (i = 0; i < 6; i++) {
|
||||||
return 2;
|
if (v < cum[i])
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,55 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 누진 구간 수수료: 금액 구간별 한계요율을 누적 적용한다 */
|
||||||
long py_cu_0001_fee(long amount, int rate_bp)
|
long py_cu_0001_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
static const long band[] = { 100000L, 1000000L, 10000000L };
|
||||||
|
static const int mul[] = { 1, 2, 3, 5 };
|
||||||
|
long remain = amount;
|
||||||
|
long fee = 0;
|
||||||
|
long prev = 0;
|
||||||
|
int i;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 0; i < 3; i++) {
|
||||||
if (fee < 0)
|
long span = band[i] - prev;
|
||||||
fee = 0;
|
long part = remain < span ? remain : span;
|
||||||
|
if (part <= 0)
|
||||||
|
break;
|
||||||
|
fee += (part * (long)rate_bp * mul[i]) / 10000L;
|
||||||
|
remain -= part;
|
||||||
|
prev = band[i];
|
||||||
|
}
|
||||||
|
if (remain > 0)
|
||||||
|
fee += (remain * (long)rate_bp * mul[3]) / 10000L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 은행가 반올림(사사오입, 짝수 반올림)으로 unit 배수 정규화 */
|
||||||
long py_cu_0001_round_unit(long amount, long unit)
|
long py_cu_0001_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r, half;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
half = unit / 2;
|
||||||
|
if (r > half || (r == half && (q & 1L)))
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 자릿수(log10) 규모로 5단계 분류 */
|
||||||
int py_cu_0001_classify(long amount)
|
int py_cu_0001_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int digits = 0;
|
||||||
if (amount < 1000000L)
|
while (v > 0) { digits++; v /= 10; }
|
||||||
return 1;
|
if (digits <= 3) return 0;
|
||||||
return 2;
|
if (digits <= 5) return 1;
|
||||||
|
if (digits <= 7) return 2;
|
||||||
|
if (digits <= 9) return 3;
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,48 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 원리금 이자액: rate_bp 연이율을 월할(1/12) 적용 */
|
||||||
long py_cu_0002_fee(long amount, int rate_bp)
|
long py_cu_0002_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long annual_bp;
|
||||||
|
long interest;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
annual_bp = (long)rate_bp;
|
||||||
if (fee < 0)
|
interest = (amount * annual_bp) / (10000L * 12L);
|
||||||
fee = 0;
|
if (interest < 0)
|
||||||
return fee;
|
interest = 0;
|
||||||
|
return interest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(오사오입, 0.5 이상 올림)으로 unit 정규화 */
|
||||||
long py_cu_0002_round_unit(long amount, long unit)
|
long py_cu_0002_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* Luhn 체크섬 유효성으로 분류: 유효=2, 무효 소액=0, 무효 고액=1 */
|
||||||
int py_cu_0002_classify(long amount)
|
int py_cu_0002_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int sum = 0, alt = 0, d;
|
||||||
if (amount < 1000000L)
|
long t = v;
|
||||||
return 1;
|
while (t > 0) {
|
||||||
return 2;
|
d = (int)(t % 10);
|
||||||
|
if (alt) { d *= 2; if (d > 9) d -= 9; }
|
||||||
|
sum += d;
|
||||||
|
alt = !alt;
|
||||||
|
t /= 10;
|
||||||
|
}
|
||||||
|
if (sum % 10 == 0)
|
||||||
|
return 2;
|
||||||
|
return v < 1000000L ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,45 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 일할 정산: rate_bp 를 경과일(1..10000) 비율로 안분한다 */
|
||||||
long py_cu_0003_fee(long amount, int rate_bp)
|
long py_cu_0003_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long days, prorated;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
days = (long)rate_bp;
|
||||||
if (fee < 0)
|
if (days > 10000L)
|
||||||
fee = 0;
|
days = 10000L;
|
||||||
return fee;
|
prorated = (amount * days) / 10000L;
|
||||||
|
return prorated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(절대값 0.5 기준 올림, 부호 보존)으로 unit 정규화 */
|
||||||
long py_cu_0003_round_unit(long amount, long unit)
|
long py_cu_0003_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long a, q, r, res;
|
||||||
|
int neg;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
neg = amount < 0;
|
||||||
|
a = neg ? -amount : amount;
|
||||||
|
q = a / unit;
|
||||||
|
r = a - q * unit;
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q += 1;
|
||||||
|
res = q * unit;
|
||||||
|
return neg ? -res : res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 디지털 루트(반복 자릿수합)로 분류 */
|
||||||
int py_cu_0003_classify(long amount)
|
int py_cu_0003_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
int root;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
root = (int)(1 + (v - 1) % 9);
|
||||||
return 1;
|
if (root <= 3) return 0;
|
||||||
|
if (root <= 6) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,51 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* FNV 해시로 결정적 가산분을 산출하는 보조 함수 */
|
||||||
|
static unsigned long py_cu_0004_mix(long x)
|
||||||
|
{
|
||||||
|
unsigned long h = 1469598103934665603UL;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
h ^= (unsigned long)((x >> (i * 8)) & 0xFF);
|
||||||
|
h *= 1099511628211UL;
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 해시 기반 가산 수수료: 기본 수수료에 결정적 잔돈을 더한다 */
|
||||||
long py_cu_0004_fee(long amount, int rate_bp)
|
long py_cu_0004_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long base, extra;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
base = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
extra = (long)(py_cu_0004_mix(amount) % 100UL);
|
||||||
fee = 0;
|
return base + extra;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 올림(상향)으로 unit 배수 정규화 */
|
||||||
long py_cu_0004_round_unit(long amount, long unit)
|
long py_cu_0004_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r > 0)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* BIN 범위표로 분류: 상위 6자리를 카드 BIN 처럼 구간 판정 */
|
||||||
int py_cu_0004_classify(long amount)
|
int py_cu_0004_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
long bin = v;
|
||||||
if (amount < 1000000L)
|
while (bin >= 1000000L)
|
||||||
return 1;
|
bin /= 10;
|
||||||
return 2;
|
if (bin >= 400000L && bin <= 499999L) return 1;
|
||||||
|
if (bin >= 510000L && bin <= 559999L) return 2;
|
||||||
|
if (bin >= 340000L && bin <= 379999L) return 3;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,39 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 통화 스케일 환산 수수료: minor unit 로 확장 후 요율 적용, major 복귀 */
|
||||||
long py_cu_0005_fee(long amount, int rate_bp)
|
long py_cu_0005_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long scaled, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
scaled = amount * 100L;
|
||||||
if (fee < 0)
|
fee = (scaled * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
fee = fee / 100L;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 내림(음의 무한대 방향)으로 unit 정규화 */
|
||||||
long py_cu_0005_round_unit(long amount, long unit)
|
long py_cu_0005_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0)
|
||||||
|
q -= 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 임계값 테이블 이분 탐색으로 백분위 버킷 분류 */
|
||||||
int py_cu_0005_classify(long amount)
|
int py_cu_0005_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long th[] = { 5000L, 50000L, 500000L, 5000000L, 50000000L };
|
||||||
return 0;
|
int lo = 0, hi = 5, mid;
|
||||||
if (amount < 1000000L)
|
while (lo < hi) {
|
||||||
return 1;
|
mid = (lo + hi) / 2;
|
||||||
return 2;
|
if (amount < th[mid]) hi = mid; else lo = mid + 1;
|
||||||
|
}
|
||||||
|
return lo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,38 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 상계(netting) 수수료: 기준 30bp 에서 rate_bp 크레딧을 차감한 순수수료 */
|
||||||
long py_cu_0006_fee(long amount, int rate_bp)
|
long py_cu_0006_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long gross, credit, net;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
gross = (amount * 30L) / 10000L;
|
||||||
if (fee < 0)
|
credit = (amount * (long)(rate_bp < 0 ? 0 : rate_bp)) / 10000L;
|
||||||
fee = 0;
|
net = gross - credit;
|
||||||
return fee;
|
if (net < 0)
|
||||||
|
net = 0;
|
||||||
|
return net;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 절사(0 방향)으로 unit 정규화 */
|
||||||
long py_cu_0006_round_unit(long amount, long unit)
|
long py_cu_0006_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 비트맵 플래그 합성 분류: 특성 비트를 OR 로 조합 */
|
||||||
int py_cu_0006_classify(long amount)
|
int py_cu_0006_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int flags = 0;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
if (amount < 0) flags |= 0x1;
|
||||||
return 1;
|
if (v % 2 == 0) flags |= 0x2;
|
||||||
return 2;
|
if (v >= 1000000L) flags |= 0x4;
|
||||||
|
if (v % 1000L == 0) flags |= 0x8;
|
||||||
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 할부 분할 수수료: rate_bp 를 할부개월(1..60)로 보고 회차수수료 산정 */
|
||||||
long py_cu_0007_fee(long amount, int rate_bp)
|
long py_cu_0007_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long n, per;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
n = rate_bp <= 0 ? 1 : (rate_bp > 60 ? 60 : rate_bp);
|
||||||
if (fee < 0)
|
per = amount / n;
|
||||||
fee = 0;
|
if (amount % n != 0)
|
||||||
return fee;
|
per += 1;
|
||||||
|
return per;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(0.5 초과에서만 올림, 정확히 0.5는 내림)으로 unit 정규화 */
|
||||||
long py_cu_0007_round_unit(long amount, long unit)
|
long py_cu_0007_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
if (r * 2 > unit)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 날짜 산술: amount 를 YYYYMMDD 로 보고 Zeller 공식으로 요일 분류(0=일..6=토) */
|
||||||
int py_cu_0007_classify(long amount)
|
int py_cu_0007_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y = (int)(amount / 10000L);
|
||||||
return 0;
|
int m = (int)((amount / 100L) % 100L);
|
||||||
if (amount < 1000000L)
|
int d = (int)(amount % 100L);
|
||||||
return 1;
|
int k, j, h;
|
||||||
return 2;
|
if (m < 1 || m > 12 || d < 1 || d > 31)
|
||||||
|
return -1;
|
||||||
|
if (m < 3) { m += 12; y -= 1; }
|
||||||
|
k = y % 100; j = y / 100;
|
||||||
|
h = (d + (13 * (m + 1)) / 5 + k + k / 4 + j / 4 + 5 * j) % 7;
|
||||||
|
return (h + 6) % 7;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,57 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 상·하한 적용 정률 수수료 */
|
||||||
long py_cu_0008_fee(long amount, int rate_bp)
|
long py_cu_0008_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee;
|
||||||
|
const long floor_fee = 100L;
|
||||||
|
const long cap_fee = 500000L;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
fee = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
if (fee < floor_fee)
|
||||||
fee = 0;
|
fee = floor_fee;
|
||||||
|
if (fee > cap_fee)
|
||||||
|
fee = cap_fee;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최근접 배수 선택: 아래/위 배수 중 더 가까운 쪽으로 정규화 */
|
||||||
long py_cu_0008_round_unit(long amount, long unit)
|
long py_cu_0008_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long down, up, dd, du;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
if (amount % unit == 0)
|
||||||
|
return amount;
|
||||||
|
down = (amount / unit) * unit;
|
||||||
|
if (amount > 0)
|
||||||
|
up = down + unit;
|
||||||
|
else
|
||||||
|
up = down - unit;
|
||||||
|
dd = amount - down; if (dd < 0) dd = -dd;
|
||||||
|
du = up - amount; if (du < 0) du = -du;
|
||||||
|
return dd <= du ? down : up;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* amount 를 YYYYMMDD 로 보고 월말/윤년 유효성 분류: 0=무효 1=정상 2=월말 */
|
||||||
int py_cu_0008_classify(long amount)
|
int py_cu_0008_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int y = (int)(amount / 10000L);
|
||||||
|
int m = (int)((amount / 100L) % 100L);
|
||||||
|
int d = (int)(amount % 100L);
|
||||||
|
int dim[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
|
int leap, last;
|
||||||
|
if (m < 1 || m > 12 || d < 1)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
|
||||||
return 1;
|
last = dim[m - 1];
|
||||||
return 2;
|
if (m == 2 && leap)
|
||||||
|
last = 29;
|
||||||
|
if (d > last)
|
||||||
|
return 0;
|
||||||
|
if (d == last)
|
||||||
|
return 2;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,43 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 복리형 단계 수수료: 기본 수수료에 2차(수수료에 대한) 수수료를 가산 */
|
||||||
long py_cu_0009_fee(long amount, int rate_bp)
|
long py_cu_0009_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long f1, f2;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
f1 = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
f2 = (f1 * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
return f1 + f2;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 최대공약수 계산 보조 함수 */
|
||||||
|
static long py_cu_0009_gcd(long a, long b)
|
||||||
|
{
|
||||||
|
a = a < 0 ? -a : a;
|
||||||
|
b = b < 0 ? -b : b;
|
||||||
|
while (b) { long t = a % b; a = b; b = t; }
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GCD 기반 유효 배수로 절사 정규화 */
|
||||||
long py_cu_0009_round_unit(long amount, long unit)
|
long py_cu_0009_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long g, step;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
g = py_cu_0009_gcd(amount, unit);
|
||||||
|
step = g > 0 ? g : unit;
|
||||||
|
return (amount / step) * step;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 나머지 패턴(mod 7)으로 분류 */
|
||||||
int py_cu_0009_classify(long amount)
|
int py_cu_0009_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
long v = amount < 0 ? -amount : amount;
|
||||||
return 0;
|
int r = (int)(v % 7L);
|
||||||
if (amount < 1000000L)
|
if (r == 0) return 0;
|
||||||
return 1;
|
if (r <= 3) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,35 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 마스킹 후 수수료: 하위 2자리를 마스킹한 금액에 요율 적용 */
|
||||||
long py_cu_0010_fee(long amount, int rate_bp)
|
long py_cu_0010_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long masked, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
masked = (amount / 100L) * 100L;
|
||||||
if (fee < 0)
|
fee = (masked * (long)rate_bp) / 10000L;
|
||||||
fee = 0;
|
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 고정소수점 스케일(x2) 반올림으로 unit 정규화 */
|
||||||
long py_cu_0010_round_unit(long amount, long unit)
|
long py_cu_0010_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long scaled, q;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
scaled = amount * 2L + (amount >= 0 ? unit : -unit);
|
||||||
|
q = scaled / (unit * 2L);
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 비트 개수(popcount)로 분류 */
|
||||||
int py_cu_0010_classify(long amount)
|
int py_cu_0010_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
unsigned long v = (unsigned long)(amount < 0 ? -amount : amount);
|
||||||
return 0;
|
int bits = 0;
|
||||||
if (amount < 1000000L)
|
while (v) { bits += (int)(v & 1UL); v >>= 1; }
|
||||||
return 1;
|
if (bits <= 4) return 0;
|
||||||
|
if (bits <= 8) return 1;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,59 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* CRC16(CCITT) 계산 보조 함수 */
|
||||||
|
static unsigned int py_cu_0011_crc16(long x)
|
||||||
|
{
|
||||||
|
unsigned int crc = 0xFFFF;
|
||||||
|
unsigned char buf[8];
|
||||||
|
int i, b;
|
||||||
|
for (i = 0; i < 8; i++)
|
||||||
|
buf[i] = (unsigned char)((x >> (i * 8)) & 0xFF);
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
crc ^= (unsigned int)buf[i] << 8;
|
||||||
|
for (b = 0; b < 8; b++)
|
||||||
|
crc = (crc & 0x8000) ? (unsigned int)((crc << 1) ^ 0x1021)
|
||||||
|
: (unsigned int)(crc << 1);
|
||||||
|
}
|
||||||
|
return crc & 0xFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CRC16 혼합 가산 수수료: 기본 수수료에 결정적 소액 가산분을 더한다 */
|
||||||
long py_cu_0011_fee(long amount, int rate_bp)
|
long py_cu_0011_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long base;
|
||||||
|
unsigned int c;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
base = (amount * (long)rate_bp) / 10000L;
|
||||||
if (fee < 0)
|
c = py_cu_0011_crc16(amount);
|
||||||
fee = 0;
|
return base + (long)(c % 50U);
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 상향 임계 반올림((unit+1)/2 기준)으로 unit 정규화 */
|
||||||
long py_cu_0011_round_unit(long amount, long unit)
|
long py_cu_0011_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r, threshold;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount - q * unit;
|
||||||
|
if (r < 0) { r += unit; q -= 1; }
|
||||||
|
threshold = (unit + 1) / 2;
|
||||||
|
if (r >= threshold)
|
||||||
|
q += 1;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 누적분포(CDF) 근사 스캔으로 백분위 분류 */
|
||||||
int py_cu_0011_classify(long amount)
|
int py_cu_0011_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long cum[] = { 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L };
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
int i;
|
||||||
return 1;
|
for (i = 0; i < 6; i++) {
|
||||||
return 2;
|
if (v < cum[i])
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,33 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 수수료: 소수 2자리 스케일로 확대 후 요율 적용, 원 단위 복귀 */
|
||||||
long rc_cu_0001_fee(long amount, int rate_bp)
|
long rc_cu_0001_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long scaled, fee;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
scaled = amount * 100L;
|
||||||
if (fee < 0)
|
fee = scaled * (long)rate_bp / 10000L;
|
||||||
fee = 0;
|
return fee / 100L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 단위가 2의 거듭제곱이면 비트마스크 정렬, 아니면 일반 절사 */
|
||||||
long rc_cu_0001_round_unit(long amount, long unit)
|
long rc_cu_0001_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
|
if ((unit & (unit - 1)) == 0)
|
||||||
|
return amount & ~(unit - 1);
|
||||||
return (amount / unit) * unit;
|
return (amount / unit) * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 금액 구간 비트맵 플래그(bit0=만,bit1=십만,bit2=백만) */
|
||||||
int rc_cu_0001_classify(long amount)
|
int rc_cu_0001_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int f = 0;
|
||||||
return 0;
|
if (amount >= 10000L) f |= 1;
|
||||||
if (amount < 1000000L)
|
if (amount >= 100000L) f |= 2;
|
||||||
return 1;
|
if (amount >= 1000000L) f |= 4;
|
||||||
return 2;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 수수료: 금액 구간별 요율을 선형보간하여 적용 */
|
||||||
long rc_cu_0002_fee(long amount, int rate_bp)
|
long rc_cu_0002_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
static const long x[4] = {0L, 100000L, 1000000L, 10000000L};
|
||||||
if (amount <= 0 || rate_bp < 0)
|
static const long y[4] = {30L, 20L, 10L, 5L};
|
||||||
|
long r = rate_bp;
|
||||||
|
int i;
|
||||||
|
if (amount <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
for (i = 0; i < 3; i++) {
|
||||||
if (fee < 0)
|
if (amount <= x[i + 1]) {
|
||||||
fee = 0;
|
long span = x[i + 1] - x[i];
|
||||||
return fee;
|
r = y[i] + (y[i + 1] - y[i]) * (amount - x[i]) / span;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return amount * r / 10000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 5사6입: 잔여가 unit 의 60% 이상일 때만 올림 */
|
||||||
long rc_cu_0002_round_unit(long amount, long unit)
|
long rc_cu_0002_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
return (r * 10 >= unit * 6) ? amount + (unit - r) : amount - r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 이진탐색으로 경계 버킷 결정 */
|
||||||
int rc_cu_0002_classify(long amount)
|
int rc_cu_0002_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long b[7] = {5000L, 20000L, 50000L, 200000L,
|
||||||
return 0;
|
500000L, 2000000L, 5000000L};
|
||||||
if (amount < 1000000L)
|
int lo = 0, hi = 7, mid;
|
||||||
return 1;
|
while (lo < hi) {
|
||||||
return 2;
|
mid = (lo + hi) / 2;
|
||||||
|
if (amount < b[mid]) hi = mid; else lo = mid + 1;
|
||||||
|
}
|
||||||
|
return lo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,35 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 그레고리력 → 율리우스일수 근사 변환 */
|
||||||
long rc_cu_0003_fee(long amount, int rate_bp)
|
static long rc_cu_0003_jdn(int y, int m, int d)
|
||||||
{
|
{
|
||||||
long fee;
|
long a = (14 - m) / 12;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
long yy = y + 4800 - a;
|
||||||
return 0;
|
long mm = m + 12 * a - 3;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
return d + (153 * mm + 2) / 5 + 365 * yy + yy / 4 - yy / 100 + yy / 400 - 32045;
|
||||||
if (fee < 0)
|
|
||||||
fee = 0;
|
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 수수료: amount=YYYYMMDD 에 rate_bp 영업일 더한 율리우스일 반환 */
|
||||||
|
long rc_cu_0003_fee(long amount, int rate_bp)
|
||||||
|
{
|
||||||
|
int y, m, d, added = 0;
|
||||||
|
long jd;
|
||||||
|
if (amount <= 0)
|
||||||
|
return 0;
|
||||||
|
y = (int)(amount / 10000L);
|
||||||
|
m = (int)((amount / 100L) % 100L);
|
||||||
|
d = (int)(amount % 100L);
|
||||||
|
jd = rc_cu_0003_jdn(y, m, d);
|
||||||
|
while (added < rate_bp) {
|
||||||
|
jd++;
|
||||||
|
if (jd % 7 != 5 && jd % 7 != 6)
|
||||||
|
added++;
|
||||||
|
}
|
||||||
|
return jd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 0 방향 대칭 절사(truncate toward zero) */
|
||||||
long rc_cu_0003_round_unit(long amount, long unit)
|
long rc_cu_0003_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
|
|
@ -26,12 +42,15 @@ long rc_cu_0003_round_unit(long amount, long unit)
|
||||||
return (amount / unit) * unit;
|
return (amount / unit) * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: FNV-1a 해시의 하위 3비트 */
|
||||||
int rc_cu_0003_classify(long amount)
|
int rc_cu_0003_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
unsigned long h = 2166136261UL;
|
||||||
return 0;
|
long v = amount < 0 ? -amount : amount;
|
||||||
if (amount < 1000000L)
|
do {
|
||||||
return 1;
|
h ^= (unsigned long)(v % 10);
|
||||||
return 2;
|
h *= 16777619UL;
|
||||||
|
v /= 10;
|
||||||
|
} while (v > 0);
|
||||||
|
return (int)(h & 0x7UL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,44 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 디지털 루트(각 자리 합 반복) 계산 */
|
||||||
|
static int rc_cu_0004_droot(long v)
|
||||||
|
{
|
||||||
|
if (v < 0) v = -v;
|
||||||
|
while (v >= 10) {
|
||||||
|
long s = 0;
|
||||||
|
while (v > 0) { s += v % 10; v /= 10; }
|
||||||
|
v = s;
|
||||||
|
}
|
||||||
|
return (int)v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 정률 계산 후 상한(cap) 적용 */
|
||||||
long rc_cu_0004_fee(long amount, int rate_bp)
|
long rc_cu_0004_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long fee, cap = 50000L;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
fee = amount * (long)rate_bp / 10000L;
|
||||||
if (fee < 0)
|
if (fee > cap)
|
||||||
fee = 0;
|
fee = cap;
|
||||||
return fee;
|
return fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 이중 절사: 1차 절사 후 잔여 2/3 이상이면 한 단위 보정 */
|
||||||
long rc_cu_0004_round_unit(long amount, long unit)
|
long rc_cu_0004_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long f1;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
f1 = (amount / unit) * unit;
|
||||||
|
if ((amount - f1) * 3 >= unit * 2)
|
||||||
|
f1 += unit;
|
||||||
|
return f1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 디지털 루트(1~9, 0) */
|
||||||
int rc_cu_0004_classify(long amount)
|
int rc_cu_0004_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
return rc_cu_0004_droot(amount);
|
||||||
return 0;
|
|
||||||
if (amount < 1000000L)
|
|
||||||
return 1;
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,49 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* 슬랩(구간별 고정액) 수수료 테이블 조회 */
|
||||||
|
static long rc_cu_0005_slab(long a)
|
||||||
|
{
|
||||||
|
static const long lim[4] = {10000L, 100000L, 1000000L, 10000000L};
|
||||||
|
static const long fixed[5] = {100L, 500L, 2000L, 8000L, 30000L};
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
if (a < lim[i])
|
||||||
|
return fixed[i];
|
||||||
|
return fixed[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 슬랩 고정액 + 미세 요율 가산 */
|
||||||
long rc_cu_0005_fee(long amount, int rate_bp)
|
long rc_cu_0005_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
long f;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
f = rc_cu_0005_slab(amount);
|
||||||
if (fee < 0)
|
f += amount * (long)rate_bp / 100000L;
|
||||||
fee = 0;
|
return f;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 가장 가까운 배수(반올림, 동점은 올림) */
|
||||||
long rc_cu_0005_round_unit(long amount, long unit)
|
long rc_cu_0005_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long q, r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
q = amount / unit;
|
||||||
|
r = amount % unit;
|
||||||
|
if (r * 2 >= unit)
|
||||||
|
q++;
|
||||||
|
return q * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 통과한 임계 개수(0~5) */
|
||||||
int rc_cu_0005_classify(long amount)
|
int rc_cu_0005_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long g[5] = {1000L, 10000L, 100000L, 1000000L, 10000000L};
|
||||||
return 0;
|
int i, c = 0;
|
||||||
if (amount < 1000000L)
|
for (i = 0; i < 5; i++)
|
||||||
return 1;
|
if (amount >= g[i])
|
||||||
return 2;
|
c++;
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,52 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* Luhn(mod-10) 체크섬 계산: 우대카드 판별용 */
|
||||||
|
static int rc_cu_0006_luhn(long v)
|
||||||
|
{
|
||||||
|
int sum = 0, alt = 0;
|
||||||
|
if (v < 0) v = -v;
|
||||||
|
while (v > 0) {
|
||||||
|
int d = (int)(v % 10);
|
||||||
|
if (alt) { d *= 2; if (d > 9) d -= 9; }
|
||||||
|
sum += d;
|
||||||
|
alt = !alt;
|
||||||
|
v /= 10;
|
||||||
|
}
|
||||||
|
return sum % 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: Luhn 체크섬이 0(정상 카드)이면 면제, 그 외 정률 */
|
||||||
long rc_cu_0006_fee(long amount, int rate_bp)
|
long rc_cu_0006_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
if (rc_cu_0006_luhn(amount) == 0)
|
||||||
if (fee < 0)
|
return 0;
|
||||||
fee = 0;
|
return (amount * (long)rate_bp) / 10000L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 반올림(round-half-up) 단위 정규화 */
|
||||||
long rc_cu_0006_round_unit(long amount, long unit)
|
long rc_cu_0006_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r, half;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
half = unit / 2;
|
||||||
|
amount -= r;
|
||||||
|
if (r >= half)
|
||||||
|
amount += unit;
|
||||||
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 10진 자릿수 개수 반환 */
|
||||||
int rc_cu_0006_classify(long amount)
|
int rc_cu_0006_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
int digits = 0;
|
||||||
|
long v = amount < 0 ? -amount : amount;
|
||||||
|
if (v == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (amount < 1000000L)
|
while (v > 0) { digits++; v /= 10; }
|
||||||
return 1;
|
return digits;
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,32 +6,54 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
|
/* BIN 범위 조회: 카드 앞 6자리 → 등급 */
|
||||||
|
static int rc_cu_0007_bin_grade(long n)
|
||||||
|
{
|
||||||
|
static const long lo[3] = {400000L, 510000L, 600000L};
|
||||||
|
static const long hi[3] = {499999L, 559999L, 699999L};
|
||||||
|
long bin = n < 0 ? -n : n;
|
||||||
|
int i;
|
||||||
|
while (bin >= 1000000L)
|
||||||
|
bin /= 10;
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
if (bin >= lo[i] && bin <= hi[i])
|
||||||
|
return i + 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 수수료: 카드 등급별 가산 bp 적용 */
|
||||||
long rc_cu_0007_fee(long amount, int rate_bp)
|
long rc_cu_0007_fee(long amount, int rate_bp)
|
||||||
{
|
{
|
||||||
long fee;
|
int g;
|
||||||
if (amount <= 0 || rate_bp < 0)
|
if (amount <= 0 || rate_bp < 0)
|
||||||
return 0;
|
return 0;
|
||||||
fee = (amount * (long)rate_bp) / 10000L;
|
g = rc_cu_0007_bin_grade(amount);
|
||||||
if (fee < 0)
|
rate_bp += g * 5;
|
||||||
fee = 0;
|
return (amount * (long)rate_bp) / 10000L;
|
||||||
return fee;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 절사(내림) 단위 정규화 */
|
/* 올림(ceil) 단위 정규화 */
|
||||||
long rc_cu_0007_round_unit(long amount, long unit)
|
long rc_cu_0007_round_unit(long amount, long unit)
|
||||||
{
|
{
|
||||||
|
long r;
|
||||||
if (unit <= 0)
|
if (unit <= 0)
|
||||||
return amount;
|
return amount;
|
||||||
return (amount / unit) * unit;
|
r = amount % unit;
|
||||||
|
if (r == 0)
|
||||||
|
return amount;
|
||||||
|
if (r < 0)
|
||||||
|
return amount - r;
|
||||||
|
return amount + (unit - r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
|
/* 분류: 퍼센타일 경계 버킷(0~9) */
|
||||||
int rc_cu_0007_classify(long amount)
|
int rc_cu_0007_classify(long amount)
|
||||||
{
|
{
|
||||||
if (amount < 10000L)
|
static const long b[9] = {1000L, 5000L, 10000L, 50000L, 100000L,
|
||||||
return 0;
|
500000L, 1000000L, 5000000L, 10000000L};
|
||||||
if (amount < 1000000L)
|
int i;
|
||||||
return 1;
|
for (i = 0; i < 9; i++)
|
||||||
return 2;
|
if (amount < b[i])
|
||||||
|
return i;
|
||||||
|
return 9;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue