다양화 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:
forge-bot 2026-07-19 04:54:59 +00:00
parent c3a0259e95
commit 93c3cb74af
1111 changed files with 31539 additions and 17258 deletions

View file

@ -6,32 +6,49 @@
#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 fee;
char buf[16];
long v = amount < 0 ? 0 : amount;
int i;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
for (i = 11; i >= 0; i--) { buf[i] = (char)('0' + (int)(v % 10)); v /= 10; }
buf[12] = '\0';
return (amount * (long)rate_bp) / 10000L + (long)ac_cu_0001_crc8(buf, 12);
}
/* 절사(내림) 단위 정규화 */
/* 최근접 배수 반올림(round-half-away-from-zero) */
long ac_cu_0001_round_unit(long amount, long unit)
{
long r, h;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int s = amount < 0 ? 2 : 0;
int p = (amount % 2 != 0) ? 1 : 0;
return s + p;
}

View file

@ -6,32 +6,39 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 12개월 균등분할 잔액에 대한 단리 이자 합 */
long ac_cu_0002_fee(long amount, int rate_bp)
{
long fee;
long total = 0, principal;
int m;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
principal = amount / 12;
for (m = 1; m <= 12; m++) {
long bal = amount - principal * (m - 1);
total += bal * (long)rate_bp / 120000L;
}
return total;
}
/* 절사(내림) 단위 정규화 */
/* 잔돈 재분배 반올림: 잔여의 2배가 unit 이상이면 올림 */
long ac_cu_0002_round_unit(long amount, long unit)
{
long base, rem;
if (unit <= 0)
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)
{
if (amount < 10000L)
long v = amount < 0 ? -amount : amount;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
return 2;
while (v >= 10)
v /= 10;
return (int)v;
}

View file

@ -6,32 +6,33 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 소수 2자리 스케일로 확대 후 요율 적용, 원 단위 복귀 */
long ac_cu_0003_fee(long amount, int rate_bp)
{
long fee;
long scaled, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
scaled = amount * 100L;
fee = scaled * (long)rate_bp / 10000L;
return fee / 100L;
}
/* 절사(내림) 단위 정규화 */
/* 단위가 2의 거듭제곱이면 비트마스크 정렬, 아니면 일반 절사 */
long ac_cu_0003_round_unit(long amount, long unit)
{
if (unit <= 0)
return amount;
if ((unit & (unit - 1)) == 0)
return amount & ~(unit - 1);
return (amount / unit) * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 분류: 금액 구간 비트맵 플래그(bit0=만,bit1=십만,bit2=백만) */
int ac_cu_0003_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int f = 0;
if (amount >= 10000L) f |= 1;
if (amount >= 100000L) f |= 2;
if (amount >= 1000000L) f |= 4;
return f;
}

View file

@ -6,32 +6,44 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 금액 구간별 요율을 선형보간하여 적용 */
long ac_cu_0004_fee(long amount, int rate_bp)
{
long fee;
if (amount <= 0 || rate_bp < 0)
static const long x[4] = {0L, 100000L, 1000000L, 10000000L};
static const long y[4] = {30L, 20L, 10L, 5L};
long r = rate_bp;
int i;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
for (i = 0; i < 3; i++) {
if (amount <= x[i + 1]) {
long span = x[i + 1] - x[i];
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 r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long b[7] = {5000L, 20000L, 50000L, 200000L,
500000L, 2000000L, 5000000L};
int lo = 0, hi = 7, mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (amount < b[mid]) hi = mid; else lo = mid + 1;
}
return lo;
}

View file

@ -6,19 +6,35 @@
#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;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
long a = (14 - m) / 12;
long yy = y + 4800 - a;
long mm = m + 12 * a - 3;
return d + (153 * mm + 2) / 5 + 365 * yy + yy / 4 - yy / 100 + yy / 400 - 32045;
}
/* 절사(내림) 단위 정규화 */
/* 수수료: 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)
{
if (unit <= 0)
@ -26,12 +42,15 @@ long ac_cu_0005_round_unit(long amount, long unit)
return (amount / unit) * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 분류: FNV-1a 해시의 하위 3비트 */
int ac_cu_0005_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
unsigned long h = 2166136261UL;
long v = amount < 0 ? -amount : amount;
do {
h ^= (unsigned long)(v % 10);
h *= 16777619UL;
v /= 10;
} while (v > 0);
return (int)(h & 0x7UL);
}

View file

@ -6,32 +6,44 @@
#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 fee;
long fee, cap = 50000L;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
fee = amount * (long)rate_bp / 10000L;
if (fee > cap)
fee = cap;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 이중 절사: 1차 절사 후 잔여 2/3 이상이면 한 단위 보정 */
long ac_cu_0006_round_unit(long amount, long unit)
{
long f1;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
return ac_cu_0006_droot(amount);
}

View file

@ -6,32 +6,49 @@
#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 fee;
long f;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
f = ac_cu_0007_slab(amount);
f += amount * (long)rate_bp / 100000L;
return f;
}
/* 절사(내림) 단위 정규화 */
/* 가장 가까운 배수(반올림, 동점은 올림) */
long ac_cu_0007_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long g[5] = {1000L, 10000L, 100000L, 1000000L, 10000000L};
int i, c = 0;
for (i = 0; i < 5; i++)
if (amount >= g[i])
c++;
return c;
}

View file

@ -6,32 +6,52 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
if (ac_cu_0008_luhn(amount) == 0)
return 0;
return (amount * (long)rate_bp) / 10000L;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(round-half-up) 단위 정규화 */
long ac_cu_0008_round_unit(long amount, long unit)
{
long r, half;
if (unit <= 0)
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)
{
if (amount < 10000L)
int digits = 0;
long v = amount < 0 ? -amount : amount;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
return 2;
while (v > 0) { digits++; v /= 10; }
return digits;
}

View file

@ -6,32 +6,54 @@
#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 fee;
int g;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
g = ac_cu_0009_bin_grade(amount);
rate_bp += g * 5;
return (amount * (long)rate_bp) / 10000L;
}
/* 절사(내림) 단위 정규화 */
/* 올림(ceil) 단위 정규화 */
long ac_cu_0009_round_unit(long amount, long unit)
{
long r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long b[9] = {1000L, 5000L, 10000L, 50000L, 100000L,
500000L, 1000000L, 5000000L, 10000000L};
int i;
for (i = 0; i < 9; i++)
if (amount < b[i])
return i;
return 9;
}

View file

@ -6,32 +6,53 @@
#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 fee;
int y, m, d, w;
long base;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
y = (int)(amount / 10000L);
m = (int)((amount / 100L) % 100L);
d = (int)(amount % 100L);
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 q;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int y, m, d;
if (amount <= 0)
return -1;
y = (int)(amount / 10000L);
m = (int)((amount / 100L) % 100L);
d = (int)(amount % 100L);
return ac_cu_0010_dow(y, m, d);
}

View file

@ -6,32 +6,45 @@
#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 fee;
long fee = 0, a = amount;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
if (a > 1000000L) { fee += (a - 1000000L) * (long)rate_bp / 10000L; a = 1000000L; }
if (a > 100000L) { fee += (a - 100000L) * (long)(rate_bp + 10) / 10000L; a = 100000L; }
fee += a * (long)(rate_bp + 20) / 10000L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 뱅커스 반올림 단위 정규화 */
long ac_cu_0011_round_unit(long amount, long unit)
{
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int e = 0;
long v = amount < 0 ? -amount : amount;
while (v >= 10) { v /= 10; e++; }
return e;
}

View file

@ -6,32 +6,53 @@
#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 fee;
int y, m, d, w;
long base;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
y = (int)(amount / 10000L);
m = (int)((amount / 100L) % 100L);
d = (int)(amount % 100L);
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 q;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int y, m, d;
if (amount <= 0)
return -1;
y = (int)(amount / 10000L);
m = (int)((amount / 100L) % 100L);
d = (int)(amount % 100L);
return au_cu_0001_dow(y, m, d);
}

View file

@ -6,32 +6,45 @@
#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 fee;
long fee = 0, a = amount;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
if (a > 1000000L) { fee += (a - 1000000L) * (long)rate_bp / 10000L; a = 1000000L; }
if (a > 100000L) { fee += (a - 100000L) * (long)(rate_bp + 10) / 10000L; a = 100000L; }
fee += a * (long)(rate_bp + 20) / 10000L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 뱅커스 반올림 단위 정규화 */
long au_cu_0002_round_unit(long amount, long unit)
{
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int e = 0;
long v = amount < 0 ? -amount : amount;
while (v >= 10) { v /= 10; e++; }
return e;
}

View file

@ -6,32 +6,49 @@
#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 fee;
char buf[16];
long v = amount < 0 ? 0 : amount;
int i;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
for (i = 11; i >= 0; i--) { buf[i] = (char)('0' + (int)(v % 10)); v /= 10; }
buf[12] = '\0';
return (amount * (long)rate_bp) / 10000L + (long)au_cu_0003_crc8(buf, 12);
}
/* 절사(내림) 단위 정규화 */
/* 최근접 배수 반올림(round-half-away-from-zero) */
long au_cu_0003_round_unit(long amount, long unit)
{
long r, h;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int s = amount < 0 ? 2 : 0;
int p = (amount % 2 != 0) ? 1 : 0;
return s + p;
}

View file

@ -6,32 +6,39 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 12개월 균등분할 잔액에 대한 단리 이자 합 */
long au_cu_0004_fee(long amount, int rate_bp)
{
long fee;
long total = 0, principal;
int m;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
principal = amount / 12;
for (m = 1; m <= 12; m++) {
long bal = amount - principal * (m - 1);
total += bal * (long)rate_bp / 120000L;
}
return total;
}
/* 절사(내림) 단위 정규화 */
/* 잔돈 재분배 반올림: 잔여의 2배가 unit 이상이면 올림 */
long au_cu_0004_round_unit(long amount, long unit)
{
long base, rem;
if (unit <= 0)
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)
{
if (amount < 10000L)
long v = amount < 0 ? -amount : amount;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
return 2;
while (v >= 10)
v /= 10;
return (int)v;
}

View file

@ -6,32 +6,33 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 소수 2자리 스케일로 확대 후 요율 적용, 원 단위 복귀 */
long au_cu_0005_fee(long amount, int rate_bp)
{
long fee;
long scaled, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
scaled = amount * 100L;
fee = scaled * (long)rate_bp / 10000L;
return fee / 100L;
}
/* 절사(내림) 단위 정규화 */
/* 단위가 2의 거듭제곱이면 비트마스크 정렬, 아니면 일반 절사 */
long au_cu_0005_round_unit(long amount, long unit)
{
if (unit <= 0)
return amount;
if ((unit & (unit - 1)) == 0)
return amount & ~(unit - 1);
return (amount / unit) * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 분류: 금액 구간 비트맵 플래그(bit0=만,bit1=십만,bit2=백만) */
int au_cu_0005_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int f = 0;
if (amount >= 10000L) f |= 1;
if (amount >= 100000L) f |= 2;
if (amount >= 1000000L) f |= 4;
return f;
}

View file

@ -6,32 +6,44 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 금액 구간별 요율을 선형보간하여 적용 */
long au_cu_0006_fee(long amount, int rate_bp)
{
long fee;
if (amount <= 0 || rate_bp < 0)
static const long x[4] = {0L, 100000L, 1000000L, 10000000L};
static const long y[4] = {30L, 20L, 10L, 5L};
long r = rate_bp;
int i;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
for (i = 0; i < 3; i++) {
if (amount <= x[i + 1]) {
long span = x[i + 1] - x[i];
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 r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long b[7] = {5000L, 20000L, 50000L, 200000L,
500000L, 2000000L, 5000000L};
int lo = 0, hi = 7, mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (amount < b[mid]) hi = mid; else lo = mid + 1;
}
return lo;
}

View file

@ -6,19 +6,35 @@
#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;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
long a = (14 - m) / 12;
long yy = y + 4800 - a;
long mm = m + 12 * a - 3;
return d + (153 * mm + 2) / 5 + 365 * yy + yy / 4 - yy / 100 + yy / 400 - 32045;
}
/* 절사(내림) 단위 정규화 */
/* 수수료: 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)
{
if (unit <= 0)
@ -26,12 +42,15 @@ long au_cu_0007_round_unit(long amount, long unit)
return (amount / unit) * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 분류: FNV-1a 해시의 하위 3비트 */
int au_cu_0007_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
unsigned long h = 2166136261UL;
long v = amount < 0 ? -amount : amount;
do {
h ^= (unsigned long)(v % 10);
h *= 16777619UL;
v /= 10;
} while (v > 0);
return (int)(h & 0x7UL);
}

View file

@ -6,32 +6,44 @@
#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 fee;
long fee, cap = 50000L;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
fee = amount * (long)rate_bp / 10000L;
if (fee > cap)
fee = cap;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 이중 절사: 1차 절사 후 잔여 2/3 이상이면 한 단위 보정 */
long au_cu_0008_round_unit(long amount, long unit)
{
long f1;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
return au_cu_0008_droot(amount);
}

View file

@ -6,32 +6,49 @@
#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 fee;
long f;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
f = au_cu_0009_slab(amount);
f += amount * (long)rate_bp / 100000L;
return f;
}
/* 절사(내림) 단위 정규화 */
/* 가장 가까운 배수(반올림, 동점은 올림) */
long au_cu_0009_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long g[5] = {1000L, 10000L, 100000L, 1000000L, 10000000L};
int i, c = 0;
for (i = 0; i < 5; i++)
if (amount >= g[i])
c++;
return c;
}

View file

@ -6,32 +6,52 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
if (au_cu_0010_luhn(amount) == 0)
return 0;
return (amount * (long)rate_bp) / 10000L;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(round-half-up) 단위 정규화 */
long au_cu_0010_round_unit(long amount, long unit)
{
long r, half;
if (unit <= 0)
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)
{
if (amount < 10000L)
int digits = 0;
long v = amount < 0 ? -amount : amount;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
return 2;
while (v > 0) { digits++; v /= 10; }
return digits;
}

View file

@ -6,32 +6,54 @@
#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 fee;
int g;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
g = au_cu_0011_bin_grade(amount);
rate_bp += g * 5;
return (amount * (long)rate_bp) / 10000L;
}
/* 절사(내림) 단위 정규화 */
/* 올림(ceil) 단위 정규화 */
long au_cu_0011_round_unit(long amount, long unit)
{
long r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long b[9] = {1000L, 5000L, 10000L, 50000L, 100000L,
500000L, 1000000L, 5000000L, 10000000L};
int i;
for (i = 0; i < 9; i++)
if (amount < b[i])
return i;
return 9;
}

View file

@ -6,32 +6,55 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 누진 구간 수수료: 금액 구간별 한계요율을 누적 적용한다 */
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)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
for (i = 0; i < 3; i++) {
long span = band[i] - prev;
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;
}
/* 절사(내림) 단위 정규화 */
/* 은행가 반올림(사사오입, 짝수 반올림)으로 unit 배수 정규화 */
long cl_cu_0001_round_unit(long amount, long unit)
{
long q, r, half;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
int digits = 0;
while (v > 0) { digits++; v /= 10; }
if (digits <= 3) return 0;
if (digits <= 5) return 1;
if (digits <= 7) return 2;
if (digits <= 9) return 3;
return 4;
}

View file

@ -6,32 +6,48 @@
#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 fee;
long annual_bp;
long interest;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
annual_bp = (long)rate_bp;
interest = (amount * annual_bp) / (10000L * 12L);
if (interest < 0)
interest = 0;
return interest;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(오사오입, 0.5 이상 올림)으로 unit 정규화 */
long cl_cu_0002_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
int sum = 0, alt = 0, d;
long t = v;
while (t > 0) {
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;
}

View file

@ -6,32 +6,45 @@
#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 fee;
long days, prorated;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
days = (long)rate_bp;
if (days > 10000L)
days = 10000L;
prorated = (amount * days) / 10000L;
return prorated;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(절대값 0.5 기준 올림, 부호 보존)으로 unit 정규화 */
long cl_cu_0003_round_unit(long amount, long unit)
{
long a, q, r, res;
int neg;
if (unit <= 0)
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)
{
if (amount < 10000L)
long v = amount < 0 ? -amount : amount;
int root;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
root = (int)(1 + (v - 1) % 9);
if (root <= 3) return 0;
if (root <= 6) return 1;
return 2;
}

View file

@ -6,32 +6,51 @@
#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 fee;
long base, extra;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
base = (amount * (long)rate_bp) / 10000L;
extra = (long)(cl_cu_0004_mix(amount) % 100UL);
return base + extra;
}
/* 절사(내림) 단위 정규화 */
/* 올림(상향)으로 unit 배수 정규화 */
long cl_cu_0004_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
long bin = v;
while (bin >= 1000000L)
bin /= 10;
if (bin >= 400000L && bin <= 499999L) return 1;
if (bin >= 510000L && bin <= 559999L) return 2;
if (bin >= 340000L && bin <= 379999L) return 3;
return 0;
}

View file

@ -6,32 +6,39 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 통화 스케일 환산 수수료: minor unit 로 확장 후 요율 적용, major 복귀 */
long cl_cu_0005_fee(long amount, int rate_bp)
{
long fee;
long scaled, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
scaled = amount * 100L;
fee = (scaled * (long)rate_bp) / 10000L;
fee = fee / 100L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 내림(음의 무한대 방향)으로 unit 정규화 */
long cl_cu_0005_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long th[] = { 5000L, 50000L, 500000L, 5000000L, 50000000L };
int lo = 0, hi = 5, mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (amount < th[mid]) hi = mid; else lo = mid + 1;
}
return lo;
}

View file

@ -6,32 +6,38 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
long gross, credit, net;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
gross = (amount * 30L) / 10000L;
credit = (amount * (long)(rate_bp < 0 ? 0 : rate_bp)) / 10000L;
net = gross - credit;
if (net < 0)
net = 0;
return net;
}
/* 절사(내림) 단위 정규화 */
/* 절사(0 방향)으로 unit 정규화 */
long cl_cu_0006_round_unit(long amount, long unit)
{
long q;
if (unit <= 0)
return amount;
return (amount / unit) * unit;
q = amount / unit;
return q * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 비트맵 플래그 합성 분류: 특성 비트를 OR 로 조합 */
int cl_cu_0006_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int flags = 0;
long v = amount < 0 ? -amount : amount;
if (amount < 0) flags |= 0x1;
if (v % 2 == 0) flags |= 0x2;
if (v >= 1000000L) flags |= 0x4;
if (v % 1000L == 0) flags |= 0x8;
return flags;
}

View file

@ -6,32 +6,44 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
long n, per;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
n = rate_bp <= 0 ? 1 : (rate_bp > 60 ? 60 : rate_bp);
per = amount / n;
if (amount % n != 0)
per += 1;
return per;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(0.5 초과에서만 올림, 정확히 0.5는 내림)으로 unit 정규화 */
long cl_cu_0007_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int y = (int)(amount / 10000L);
int m = (int)((amount / 100L) % 100L);
int d = (int)(amount % 100L);
int k, j, h;
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;
}

View file

@ -6,32 +6,57 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 상·하한 적용 정률 수수료 */
long cl_cu_0008_fee(long amount, int rate_bp)
{
long fee;
const long floor_fee = 100L;
const long cap_fee = 500000L;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
if (fee < floor_fee)
fee = floor_fee;
if (fee > cap_fee)
fee = cap_fee;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 최근접 배수 선택: 아래/위 배수 중 더 가까운 쪽으로 정규화 */
long cl_cu_0008_round_unit(long amount, long unit)
{
long down, up, dd, du;
if (unit <= 0)
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)
{
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;
if (amount < 1000000L)
return 1;
return 2;
leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
last = dim[m - 1];
if (m == 2 && leap)
last = 29;
if (d > last)
return 0;
if (d == last)
return 2;
return 1;
}

View file

@ -6,32 +6,43 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 복리형 단계 수수료: 기본 수수료에 2차(수수료에 대한) 수수료를 가산 */
long cl_cu_0009_fee(long amount, int rate_bp)
{
long fee;
long f1, f2;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
f1 = (amount * (long)rate_bp) / 10000L;
f2 = (f1 * (long)rate_bp) / 10000L;
return f1 + f2;
}
/* 절사(내림) 단위 정규화 */
/* 최대공약수 계산 보조 함수 */
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 g, step;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
long v = amount < 0 ? -amount : amount;
int r = (int)(v % 7L);
if (r == 0) return 0;
if (r <= 3) return 1;
return 2;
}

View file

@ -6,32 +6,35 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 마스킹 후 수수료: 하위 2자리를 마스킹한 금액에 요율 적용 */
long cl_cu_0010_fee(long amount, int rate_bp)
{
long fee;
long masked, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
masked = (amount / 100L) * 100L;
fee = (masked * (long)rate_bp) / 10000L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 고정소수점 스케일(x2) 반올림으로 unit 정규화 */
long cl_cu_0010_round_unit(long amount, long unit)
{
long scaled, q;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
unsigned long v = (unsigned long)(amount < 0 ? -amount : amount);
int bits = 0;
while (v) { bits += (int)(v & 1UL); v >>= 1; }
if (bits <= 4) return 0;
if (bits <= 8) return 1;
return 2;
}

View file

@ -6,32 +6,55 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 누진 구간 수수료: 금액 구간별 한계요율을 누적 적용한다 */
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)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
for (i = 0; i < 3; i++) {
long span = band[i] - prev;
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;
}
/* 절사(내림) 단위 정규화 */
/* 은행가 반올림(사사오입, 짝수 반올림)으로 unit 배수 정규화 */
long cm_cu_0001_round_unit(long amount, long unit)
{
long q, r, half;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
int digits = 0;
while (v > 0) { digits++; v /= 10; }
if (digits <= 3) return 0;
if (digits <= 5) return 1;
if (digits <= 7) return 2;
if (digits <= 9) return 3;
return 4;
}

View file

@ -6,32 +6,48 @@
#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 fee;
long annual_bp;
long interest;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
annual_bp = (long)rate_bp;
interest = (amount * annual_bp) / (10000L * 12L);
if (interest < 0)
interest = 0;
return interest;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(오사오입, 0.5 이상 올림)으로 unit 정규화 */
long cm_cu_0002_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
int sum = 0, alt = 0, d;
long t = v;
while (t > 0) {
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;
}

View file

@ -6,32 +6,45 @@
#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 fee;
long days, prorated;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
days = (long)rate_bp;
if (days > 10000L)
days = 10000L;
prorated = (amount * days) / 10000L;
return prorated;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(절대값 0.5 기준 올림, 부호 보존)으로 unit 정규화 */
long cm_cu_0003_round_unit(long amount, long unit)
{
long a, q, r, res;
int neg;
if (unit <= 0)
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)
{
if (amount < 10000L)
long v = amount < 0 ? -amount : amount;
int root;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
root = (int)(1 + (v - 1) % 9);
if (root <= 3) return 0;
if (root <= 6) return 1;
return 2;
}

View file

@ -6,32 +6,51 @@
#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 fee;
long base, extra;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
base = (amount * (long)rate_bp) / 10000L;
extra = (long)(cm_cu_0004_mix(amount) % 100UL);
return base + extra;
}
/* 절사(내림) 단위 정규화 */
/* 올림(상향)으로 unit 배수 정규화 */
long cm_cu_0004_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
long bin = v;
while (bin >= 1000000L)
bin /= 10;
if (bin >= 400000L && bin <= 499999L) return 1;
if (bin >= 510000L && bin <= 559999L) return 2;
if (bin >= 340000L && bin <= 379999L) return 3;
return 0;
}

View file

@ -6,32 +6,39 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 통화 스케일 환산 수수료: minor unit 로 확장 후 요율 적용, major 복귀 */
long cm_cu_0005_fee(long amount, int rate_bp)
{
long fee;
long scaled, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
scaled = amount * 100L;
fee = (scaled * (long)rate_bp) / 10000L;
fee = fee / 100L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 내림(음의 무한대 방향)으로 unit 정규화 */
long cm_cu_0005_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long th[] = { 5000L, 50000L, 500000L, 5000000L, 50000000L };
int lo = 0, hi = 5, mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (amount < th[mid]) hi = mid; else lo = mid + 1;
}
return lo;
}

View file

@ -6,32 +6,38 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
long gross, credit, net;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
gross = (amount * 30L) / 10000L;
credit = (amount * (long)(rate_bp < 0 ? 0 : rate_bp)) / 10000L;
net = gross - credit;
if (net < 0)
net = 0;
return net;
}
/* 절사(내림) 단위 정규화 */
/* 절사(0 방향)으로 unit 정규화 */
long cm_cu_0006_round_unit(long amount, long unit)
{
long q;
if (unit <= 0)
return amount;
return (amount / unit) * unit;
q = amount / unit;
return q * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 비트맵 플래그 합성 분류: 특성 비트를 OR 로 조합 */
int cm_cu_0006_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int flags = 0;
long v = amount < 0 ? -amount : amount;
if (amount < 0) flags |= 0x1;
if (v % 2 == 0) flags |= 0x2;
if (v >= 1000000L) flags |= 0x4;
if (v % 1000L == 0) flags |= 0x8;
return flags;
}

View file

@ -6,32 +6,44 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
long n, per;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
n = rate_bp <= 0 ? 1 : (rate_bp > 60 ? 60 : rate_bp);
per = amount / n;
if (amount % n != 0)
per += 1;
return per;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(0.5 초과에서만 올림, 정확히 0.5는 내림)으로 unit 정규화 */
long cm_cu_0007_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int y = (int)(amount / 10000L);
int m = (int)((amount / 100L) % 100L);
int d = (int)(amount % 100L);
int k, j, h;
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;
}

View file

@ -6,32 +6,57 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 상·하한 적용 정률 수수료 */
long cm_cu_0008_fee(long amount, int rate_bp)
{
long fee;
const long floor_fee = 100L;
const long cap_fee = 500000L;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
if (fee < floor_fee)
fee = floor_fee;
if (fee > cap_fee)
fee = cap_fee;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 최근접 배수 선택: 아래/위 배수 중 더 가까운 쪽으로 정규화 */
long cm_cu_0008_round_unit(long amount, long unit)
{
long down, up, dd, du;
if (unit <= 0)
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)
{
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;
if (amount < 1000000L)
return 1;
return 2;
leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
last = dim[m - 1];
if (m == 2 && leap)
last = 29;
if (d > last)
return 0;
if (d == last)
return 2;
return 1;
}

View file

@ -6,32 +6,43 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 복리형 단계 수수료: 기본 수수료에 2차(수수료에 대한) 수수료를 가산 */
long cm_cu_0009_fee(long amount, int rate_bp)
{
long fee;
long f1, f2;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
f1 = (amount * (long)rate_bp) / 10000L;
f2 = (f1 * (long)rate_bp) / 10000L;
return f1 + f2;
}
/* 절사(내림) 단위 정규화 */
/* 최대공약수 계산 보조 함수 */
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 g, step;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
long v = amount < 0 ? -amount : amount;
int r = (int)(v % 7L);
if (r == 0) return 0;
if (r <= 3) return 1;
return 2;
}

View file

@ -6,32 +6,35 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 마스킹 후 수수료: 하위 2자리를 마스킹한 금액에 요율 적용 */
long cm_cu_0010_fee(long amount, int rate_bp)
{
long fee;
long masked, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
masked = (amount / 100L) * 100L;
fee = (masked * (long)rate_bp) / 10000L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 고정소수점 스케일(x2) 반올림으로 unit 정규화 */
long cm_cu_0010_round_unit(long amount, long unit)
{
long scaled, q;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
unsigned long v = (unsigned long)(amount < 0 ? -amount : amount);
int bits = 0;
while (v) { bits += (int)(v & 1UL); v >>= 1; }
if (bits <= 4) return 0;
if (bits <= 8) return 1;
return 2;
}

View file

@ -6,32 +6,59 @@
#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 fee;
long base;
unsigned int c;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
base = (amount * (long)rate_bp) / 10000L;
c = cm_cu_0011_crc16(amount);
return base + (long)(c % 50U);
}
/* 절사(내림) 단위 정규화 */
/* 상향 임계 반올림((unit+1)/2 기준)으로 unit 정규화 */
long cm_cu_0011_round_unit(long amount, long unit)
{
long q, r, threshold;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long cum[] = { 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L };
long v = amount < 0 ? -amount : amount;
int i;
for (i = 0; i < 6; i++) {
if (v < cum[i])
return i;
}
return 6;
}

View file

@ -6,32 +6,55 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 누진 구간 수수료: 금액 구간별 한계요율을 누적 적용한다 */
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)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
for (i = 0; i < 3; i++) {
long span = band[i] - prev;
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;
}
/* 절사(내림) 단위 정규화 */
/* 은행가 반올림(사사오입, 짝수 반올림)으로 unit 배수 정규화 */
long lg_cu_0001_round_unit(long amount, long unit)
{
long q, r, half;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
int digits = 0;
while (v > 0) { digits++; v /= 10; }
if (digits <= 3) return 0;
if (digits <= 5) return 1;
if (digits <= 7) return 2;
if (digits <= 9) return 3;
return 4;
}

View file

@ -6,32 +6,48 @@
#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 fee;
long annual_bp;
long interest;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
annual_bp = (long)rate_bp;
interest = (amount * annual_bp) / (10000L * 12L);
if (interest < 0)
interest = 0;
return interest;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(오사오입, 0.5 이상 올림)으로 unit 정규화 */
long lg_cu_0002_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
int sum = 0, alt = 0, d;
long t = v;
while (t > 0) {
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;
}

View file

@ -6,32 +6,45 @@
#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 fee;
long days, prorated;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
days = (long)rate_bp;
if (days > 10000L)
days = 10000L;
prorated = (amount * days) / 10000L;
return prorated;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(절대값 0.5 기준 올림, 부호 보존)으로 unit 정규화 */
long lg_cu_0003_round_unit(long amount, long unit)
{
long a, q, r, res;
int neg;
if (unit <= 0)
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)
{
if (amount < 10000L)
long v = amount < 0 ? -amount : amount;
int root;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
root = (int)(1 + (v - 1) % 9);
if (root <= 3) return 0;
if (root <= 6) return 1;
return 2;
}

View file

@ -6,32 +6,51 @@
#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 fee;
long base, extra;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
base = (amount * (long)rate_bp) / 10000L;
extra = (long)(lg_cu_0004_mix(amount) % 100UL);
return base + extra;
}
/* 절사(내림) 단위 정규화 */
/* 올림(상향)으로 unit 배수 정규화 */
long lg_cu_0004_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
long bin = v;
while (bin >= 1000000L)
bin /= 10;
if (bin >= 400000L && bin <= 499999L) return 1;
if (bin >= 510000L && bin <= 559999L) return 2;
if (bin >= 340000L && bin <= 379999L) return 3;
return 0;
}

View file

@ -6,32 +6,39 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 통화 스케일 환산 수수료: minor unit 로 확장 후 요율 적용, major 복귀 */
long lg_cu_0005_fee(long amount, int rate_bp)
{
long fee;
long scaled, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
scaled = amount * 100L;
fee = (scaled * (long)rate_bp) / 10000L;
fee = fee / 100L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 내림(음의 무한대 방향)으로 unit 정규화 */
long lg_cu_0005_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long th[] = { 5000L, 50000L, 500000L, 5000000L, 50000000L };
int lo = 0, hi = 5, mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (amount < th[mid]) hi = mid; else lo = mid + 1;
}
return lo;
}

View file

@ -6,32 +6,38 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
long gross, credit, net;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
gross = (amount * 30L) / 10000L;
credit = (amount * (long)(rate_bp < 0 ? 0 : rate_bp)) / 10000L;
net = gross - credit;
if (net < 0)
net = 0;
return net;
}
/* 절사(내림) 단위 정규화 */
/* 절사(0 방향)으로 unit 정규화 */
long lg_cu_0006_round_unit(long amount, long unit)
{
long q;
if (unit <= 0)
return amount;
return (amount / unit) * unit;
q = amount / unit;
return q * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 비트맵 플래그 합성 분류: 특성 비트를 OR 로 조합 */
int lg_cu_0006_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int flags = 0;
long v = amount < 0 ? -amount : amount;
if (amount < 0) flags |= 0x1;
if (v % 2 == 0) flags |= 0x2;
if (v >= 1000000L) flags |= 0x4;
if (v % 1000L == 0) flags |= 0x8;
return flags;
}

View file

@ -6,32 +6,44 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
long n, per;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
n = rate_bp <= 0 ? 1 : (rate_bp > 60 ? 60 : rate_bp);
per = amount / n;
if (amount % n != 0)
per += 1;
return per;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(0.5 초과에서만 올림, 정확히 0.5는 내림)으로 unit 정규화 */
long lg_cu_0007_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int y = (int)(amount / 10000L);
int m = (int)((amount / 100L) % 100L);
int d = (int)(amount % 100L);
int k, j, h;
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;
}

View file

@ -6,32 +6,57 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 상·하한 적용 정률 수수료 */
long lg_cu_0008_fee(long amount, int rate_bp)
{
long fee;
const long floor_fee = 100L;
const long cap_fee = 500000L;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
if (fee < floor_fee)
fee = floor_fee;
if (fee > cap_fee)
fee = cap_fee;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 최근접 배수 선택: 아래/위 배수 중 더 가까운 쪽으로 정규화 */
long lg_cu_0008_round_unit(long amount, long unit)
{
long down, up, dd, du;
if (unit <= 0)
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)
{
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;
if (amount < 1000000L)
return 1;
return 2;
leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
last = dim[m - 1];
if (m == 2 && leap)
last = 29;
if (d > last)
return 0;
if (d == last)
return 2;
return 1;
}

View file

@ -6,32 +6,43 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 복리형 단계 수수료: 기본 수수료에 2차(수수료에 대한) 수수료를 가산 */
long lg_cu_0009_fee(long amount, int rate_bp)
{
long fee;
long f1, f2;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
f1 = (amount * (long)rate_bp) / 10000L;
f2 = (f1 * (long)rate_bp) / 10000L;
return f1 + f2;
}
/* 절사(내림) 단위 정규화 */
/* 최대공약수 계산 보조 함수 */
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 g, step;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
long v = amount < 0 ? -amount : amount;
int r = (int)(v % 7L);
if (r == 0) return 0;
if (r <= 3) return 1;
return 2;
}

View file

@ -6,32 +6,35 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 마스킹 후 수수료: 하위 2자리를 마스킹한 금액에 요율 적용 */
long lg_cu_0010_fee(long amount, int rate_bp)
{
long fee;
long masked, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
masked = (amount / 100L) * 100L;
fee = (masked * (long)rate_bp) / 10000L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 고정소수점 스케일(x2) 반올림으로 unit 정규화 */
long lg_cu_0010_round_unit(long amount, long unit)
{
long scaled, q;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
unsigned long v = (unsigned long)(amount < 0 ? -amount : amount);
int bits = 0;
while (v) { bits += (int)(v & 1UL); v >>= 1; }
if (bits <= 4) return 0;
if (bits <= 8) return 1;
return 2;
}

View file

@ -6,32 +6,59 @@
#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 fee;
long base;
unsigned int c;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
base = (amount * (long)rate_bp) / 10000L;
c = lg_cu_0011_crc16(amount);
return base + (long)(c % 50U);
}
/* 절사(내림) 단위 정규화 */
/* 상향 임계 반올림((unit+1)/2 기준)으로 unit 정규화 */
long lg_cu_0011_round_unit(long amount, long unit)
{
long q, r, threshold;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long cum[] = { 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L };
long v = amount < 0 ? -amount : amount;
int i;
for (i = 0; i < 6; i++) {
if (v < cum[i])
return i;
}
return 6;
}

View file

@ -6,32 +6,52 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
if (mg_cu_0001_luhn(amount) == 0)
return 0;
return (amount * (long)rate_bp) / 10000L;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(round-half-up) 단위 정규화 */
long mg_cu_0001_round_unit(long amount, long unit)
{
long r, half;
if (unit <= 0)
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)
{
if (amount < 10000L)
int digits = 0;
long v = amount < 0 ? -amount : amount;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
return 2;
while (v > 0) { digits++; v /= 10; }
return digits;
}

View file

@ -6,32 +6,54 @@
#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 fee;
int g;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
g = mg_cu_0002_bin_grade(amount);
rate_bp += g * 5;
return (amount * (long)rate_bp) / 10000L;
}
/* 절사(내림) 단위 정규화 */
/* 올림(ceil) 단위 정규화 */
long mg_cu_0002_round_unit(long amount, long unit)
{
long r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long b[9] = {1000L, 5000L, 10000L, 50000L, 100000L,
500000L, 1000000L, 5000000L, 10000000L};
int i;
for (i = 0; i < 9; i++)
if (amount < b[i])
return i;
return 9;
}

View file

@ -6,32 +6,53 @@
#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 fee;
int y, m, d, w;
long base;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
y = (int)(amount / 10000L);
m = (int)((amount / 100L) % 100L);
d = (int)(amount % 100L);
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 q;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int y, m, d;
if (amount <= 0)
return -1;
y = (int)(amount / 10000L);
m = (int)((amount / 100L) % 100L);
d = (int)(amount % 100L);
return mg_cu_0003_dow(y, m, d);
}

View file

@ -6,32 +6,45 @@
#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 fee;
long fee = 0, a = amount;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
if (a > 1000000L) { fee += (a - 1000000L) * (long)rate_bp / 10000L; a = 1000000L; }
if (a > 100000L) { fee += (a - 100000L) * (long)(rate_bp + 10) / 10000L; a = 100000L; }
fee += a * (long)(rate_bp + 20) / 10000L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 뱅커스 반올림 단위 정규화 */
long mg_cu_0004_round_unit(long amount, long unit)
{
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int e = 0;
long v = amount < 0 ? -amount : amount;
while (v >= 10) { v /= 10; e++; }
return e;
}

View file

@ -6,32 +6,49 @@
#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 fee;
char buf[16];
long v = amount < 0 ? 0 : amount;
int i;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
for (i = 11; i >= 0; i--) { buf[i] = (char)('0' + (int)(v % 10)); v /= 10; }
buf[12] = '\0';
return (amount * (long)rate_bp) / 10000L + (long)mg_cu_0005_crc8(buf, 12);
}
/* 절사(내림) 단위 정규화 */
/* 최근접 배수 반올림(round-half-away-from-zero) */
long mg_cu_0005_round_unit(long amount, long unit)
{
long r, h;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int s = amount < 0 ? 2 : 0;
int p = (amount % 2 != 0) ? 1 : 0;
return s + p;
}

View file

@ -6,32 +6,39 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 12개월 균등분할 잔액에 대한 단리 이자 합 */
long mg_cu_0006_fee(long amount, int rate_bp)
{
long fee;
long total = 0, principal;
int m;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
principal = amount / 12;
for (m = 1; m <= 12; m++) {
long bal = amount - principal * (m - 1);
total += bal * (long)rate_bp / 120000L;
}
return total;
}
/* 절사(내림) 단위 정규화 */
/* 잔돈 재분배 반올림: 잔여의 2배가 unit 이상이면 올림 */
long mg_cu_0006_round_unit(long amount, long unit)
{
long base, rem;
if (unit <= 0)
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)
{
if (amount < 10000L)
long v = amount < 0 ? -amount : amount;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
return 2;
while (v >= 10)
v /= 10;
return (int)v;
}

View file

@ -6,32 +6,33 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 소수 2자리 스케일로 확대 후 요율 적용, 원 단위 복귀 */
long mg_cu_0007_fee(long amount, int rate_bp)
{
long fee;
long scaled, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
scaled = amount * 100L;
fee = scaled * (long)rate_bp / 10000L;
return fee / 100L;
}
/* 절사(내림) 단위 정규화 */
/* 단위가 2의 거듭제곱이면 비트마스크 정렬, 아니면 일반 절사 */
long mg_cu_0007_round_unit(long amount, long unit)
{
if (unit <= 0)
return amount;
if ((unit & (unit - 1)) == 0)
return amount & ~(unit - 1);
return (amount / unit) * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 분류: 금액 구간 비트맵 플래그(bit0=만,bit1=십만,bit2=백만) */
int mg_cu_0007_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int f = 0;
if (amount >= 10000L) f |= 1;
if (amount >= 100000L) f |= 2;
if (amount >= 1000000L) f |= 4;
return f;
}

View file

@ -6,32 +6,44 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 금액 구간별 요율을 선형보간하여 적용 */
long mg_cu_0008_fee(long amount, int rate_bp)
{
long fee;
if (amount <= 0 || rate_bp < 0)
static const long x[4] = {0L, 100000L, 1000000L, 10000000L};
static const long y[4] = {30L, 20L, 10L, 5L};
long r = rate_bp;
int i;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
for (i = 0; i < 3; i++) {
if (amount <= x[i + 1]) {
long span = x[i + 1] - x[i];
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 r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long b[7] = {5000L, 20000L, 50000L, 200000L,
500000L, 2000000L, 5000000L};
int lo = 0, hi = 7, mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (amount < b[mid]) hi = mid; else lo = mid + 1;
}
return lo;
}

View file

@ -6,19 +6,35 @@
#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;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
long a = (14 - m) / 12;
long yy = y + 4800 - a;
long mm = m + 12 * a - 3;
return d + (153 * mm + 2) / 5 + 365 * yy + yy / 4 - yy / 100 + yy / 400 - 32045;
}
/* 절사(내림) 단위 정규화 */
/* 수수료: 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)
{
if (unit <= 0)
@ -26,12 +42,15 @@ long mg_cu_0009_round_unit(long amount, long unit)
return (amount / unit) * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 분류: FNV-1a 해시의 하위 3비트 */
int mg_cu_0009_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
unsigned long h = 2166136261UL;
long v = amount < 0 ? -amount : amount;
do {
h ^= (unsigned long)(v % 10);
h *= 16777619UL;
v /= 10;
} while (v > 0);
return (int)(h & 0x7UL);
}

View file

@ -6,32 +6,44 @@
#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 fee;
long fee, cap = 50000L;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
fee = amount * (long)rate_bp / 10000L;
if (fee > cap)
fee = cap;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 이중 절사: 1차 절사 후 잔여 2/3 이상이면 한 단위 보정 */
long mg_cu_0010_round_unit(long amount, long unit)
{
long f1;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
return mg_cu_0010_droot(amount);
}

View file

@ -6,32 +6,49 @@
#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 fee;
long f;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
f = mg_cu_0011_slab(amount);
f += amount * (long)rate_bp / 100000L;
return f;
}
/* 절사(내림) 단위 정규화 */
/* 가장 가까운 배수(반올림, 동점은 올림) */
long mg_cu_0011_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long g[5] = {1000L, 10000L, 100000L, 1000000L, 10000000L};
int i, c = 0;
for (i = 0; i < 5; i++)
if (amount >= g[i])
c++;
return c;
}

View file

@ -6,32 +6,55 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 누진 구간 수수료: 금액 구간별 한계요율을 누적 적용한다 */
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)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
for (i = 0; i < 3; i++) {
long span = band[i] - prev;
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;
}
/* 절사(내림) 단위 정규화 */
/* 은행가 반올림(사사오입, 짝수 반올림)으로 unit 배수 정규화 */
long mm_cu_0001_round_unit(long amount, long unit)
{
long q, r, half;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
int digits = 0;
while (v > 0) { digits++; v /= 10; }
if (digits <= 3) return 0;
if (digits <= 5) return 1;
if (digits <= 7) return 2;
if (digits <= 9) return 3;
return 4;
}

View file

@ -6,32 +6,48 @@
#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 fee;
long annual_bp;
long interest;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
annual_bp = (long)rate_bp;
interest = (amount * annual_bp) / (10000L * 12L);
if (interest < 0)
interest = 0;
return interest;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(오사오입, 0.5 이상 올림)으로 unit 정규화 */
long mm_cu_0002_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
int sum = 0, alt = 0, d;
long t = v;
while (t > 0) {
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;
}

View file

@ -6,32 +6,45 @@
#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 fee;
long days, prorated;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
days = (long)rate_bp;
if (days > 10000L)
days = 10000L;
prorated = (amount * days) / 10000L;
return prorated;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(절대값 0.5 기준 올림, 부호 보존)으로 unit 정규화 */
long mm_cu_0003_round_unit(long amount, long unit)
{
long a, q, r, res;
int neg;
if (unit <= 0)
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)
{
if (amount < 10000L)
long v = amount < 0 ? -amount : amount;
int root;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
root = (int)(1 + (v - 1) % 9);
if (root <= 3) return 0;
if (root <= 6) return 1;
return 2;
}

View file

@ -6,32 +6,51 @@
#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 fee;
long base, extra;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
base = (amount * (long)rate_bp) / 10000L;
extra = (long)(mm_cu_0004_mix(amount) % 100UL);
return base + extra;
}
/* 절사(내림) 단위 정규화 */
/* 올림(상향)으로 unit 배수 정규화 */
long mm_cu_0004_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
long bin = v;
while (bin >= 1000000L)
bin /= 10;
if (bin >= 400000L && bin <= 499999L) return 1;
if (bin >= 510000L && bin <= 559999L) return 2;
if (bin >= 340000L && bin <= 379999L) return 3;
return 0;
}

View file

@ -6,32 +6,39 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 통화 스케일 환산 수수료: minor unit 로 확장 후 요율 적용, major 복귀 */
long mm_cu_0005_fee(long amount, int rate_bp)
{
long fee;
long scaled, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
scaled = amount * 100L;
fee = (scaled * (long)rate_bp) / 10000L;
fee = fee / 100L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 내림(음의 무한대 방향)으로 unit 정규화 */
long mm_cu_0005_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long th[] = { 5000L, 50000L, 500000L, 5000000L, 50000000L };
int lo = 0, hi = 5, mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (amount < th[mid]) hi = mid; else lo = mid + 1;
}
return lo;
}

View file

@ -6,32 +6,38 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
long gross, credit, net;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
gross = (amount * 30L) / 10000L;
credit = (amount * (long)(rate_bp < 0 ? 0 : rate_bp)) / 10000L;
net = gross - credit;
if (net < 0)
net = 0;
return net;
}
/* 절사(내림) 단위 정규화 */
/* 절사(0 방향)으로 unit 정규화 */
long mm_cu_0006_round_unit(long amount, long unit)
{
long q;
if (unit <= 0)
return amount;
return (amount / unit) * unit;
q = amount / unit;
return q * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 비트맵 플래그 합성 분류: 특성 비트를 OR 로 조합 */
int mm_cu_0006_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int flags = 0;
long v = amount < 0 ? -amount : amount;
if (amount < 0) flags |= 0x1;
if (v % 2 == 0) flags |= 0x2;
if (v >= 1000000L) flags |= 0x4;
if (v % 1000L == 0) flags |= 0x8;
return flags;
}

View file

@ -6,32 +6,44 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
long n, per;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
n = rate_bp <= 0 ? 1 : (rate_bp > 60 ? 60 : rate_bp);
per = amount / n;
if (amount % n != 0)
per += 1;
return per;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(0.5 초과에서만 올림, 정확히 0.5는 내림)으로 unit 정규화 */
long mm_cu_0007_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int y = (int)(amount / 10000L);
int m = (int)((amount / 100L) % 100L);
int d = (int)(amount % 100L);
int k, j, h;
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;
}

View file

@ -6,32 +6,57 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 상·하한 적용 정률 수수료 */
long mm_cu_0008_fee(long amount, int rate_bp)
{
long fee;
const long floor_fee = 100L;
const long cap_fee = 500000L;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
if (fee < floor_fee)
fee = floor_fee;
if (fee > cap_fee)
fee = cap_fee;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 최근접 배수 선택: 아래/위 배수 중 더 가까운 쪽으로 정규화 */
long mm_cu_0008_round_unit(long amount, long unit)
{
long down, up, dd, du;
if (unit <= 0)
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)
{
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;
if (amount < 1000000L)
return 1;
return 2;
leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
last = dim[m - 1];
if (m == 2 && leap)
last = 29;
if (d > last)
return 0;
if (d == last)
return 2;
return 1;
}

View file

@ -6,32 +6,43 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 복리형 단계 수수료: 기본 수수료에 2차(수수료에 대한) 수수료를 가산 */
long mm_cu_0009_fee(long amount, int rate_bp)
{
long fee;
long f1, f2;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
f1 = (amount * (long)rate_bp) / 10000L;
f2 = (f1 * (long)rate_bp) / 10000L;
return f1 + f2;
}
/* 절사(내림) 단위 정규화 */
/* 최대공약수 계산 보조 함수 */
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 g, step;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
long v = amount < 0 ? -amount : amount;
int r = (int)(v % 7L);
if (r == 0) return 0;
if (r <= 3) return 1;
return 2;
}

View file

@ -6,32 +6,35 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 마스킹 후 수수료: 하위 2자리를 마스킹한 금액에 요율 적용 */
long mm_cu_0010_fee(long amount, int rate_bp)
{
long fee;
long masked, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
masked = (amount / 100L) * 100L;
fee = (masked * (long)rate_bp) / 10000L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 고정소수점 스케일(x2) 반올림으로 unit 정규화 */
long mm_cu_0010_round_unit(long amount, long unit)
{
long scaled, q;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
unsigned long v = (unsigned long)(amount < 0 ? -amount : amount);
int bits = 0;
while (v) { bits += (int)(v & 1UL); v >>= 1; }
if (bits <= 4) return 0;
if (bits <= 8) return 1;
return 2;
}

View file

@ -6,32 +6,59 @@
#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 fee;
long base;
unsigned int c;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
base = (amount * (long)rate_bp) / 10000L;
c = mm_cu_0011_crc16(amount);
return base + (long)(c % 50U);
}
/* 절사(내림) 단위 정규화 */
/* 상향 임계 반올림((unit+1)/2 기준)으로 unit 정규화 */
long mm_cu_0011_round_unit(long amount, long unit)
{
long q, r, threshold;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long cum[] = { 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L };
long v = amount < 0 ? -amount : amount;
int i;
for (i = 0; i < 6; i++) {
if (v < cum[i])
return i;
}
return 6;
}

View file

@ -6,32 +6,55 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 누진 구간 수수료: 금액 구간별 한계요율을 누적 적용한다 */
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)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
for (i = 0; i < 3; i++) {
long span = band[i] - prev;
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;
}
/* 절사(내림) 단위 정규화 */
/* 은행가 반올림(사사오입, 짝수 반올림)으로 unit 배수 정규화 */
long py_cu_0001_round_unit(long amount, long unit)
{
long q, r, half;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
int digits = 0;
while (v > 0) { digits++; v /= 10; }
if (digits <= 3) return 0;
if (digits <= 5) return 1;
if (digits <= 7) return 2;
if (digits <= 9) return 3;
return 4;
}

View file

@ -6,32 +6,48 @@
#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 fee;
long annual_bp;
long interest;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
annual_bp = (long)rate_bp;
interest = (amount * annual_bp) / (10000L * 12L);
if (interest < 0)
interest = 0;
return interest;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(오사오입, 0.5 이상 올림)으로 unit 정규화 */
long py_cu_0002_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
int sum = 0, alt = 0, d;
long t = v;
while (t > 0) {
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;
}

View file

@ -6,32 +6,45 @@
#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 fee;
long days, prorated;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
days = (long)rate_bp;
if (days > 10000L)
days = 10000L;
prorated = (amount * days) / 10000L;
return prorated;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(절대값 0.5 기준 올림, 부호 보존)으로 unit 정규화 */
long py_cu_0003_round_unit(long amount, long unit)
{
long a, q, r, res;
int neg;
if (unit <= 0)
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)
{
if (amount < 10000L)
long v = amount < 0 ? -amount : amount;
int root;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
root = (int)(1 + (v - 1) % 9);
if (root <= 3) return 0;
if (root <= 6) return 1;
return 2;
}

View file

@ -6,32 +6,51 @@
#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 fee;
long base, extra;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
base = (amount * (long)rate_bp) / 10000L;
extra = (long)(py_cu_0004_mix(amount) % 100UL);
return base + extra;
}
/* 절사(내림) 단위 정규화 */
/* 올림(상향)으로 unit 배수 정규화 */
long py_cu_0004_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
long v = amount < 0 ? -amount : amount;
long bin = v;
while (bin >= 1000000L)
bin /= 10;
if (bin >= 400000L && bin <= 499999L) return 1;
if (bin >= 510000L && bin <= 559999L) return 2;
if (bin >= 340000L && bin <= 379999L) return 3;
return 0;
}

View file

@ -6,32 +6,39 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 통화 스케일 환산 수수료: minor unit 로 확장 후 요율 적용, major 복귀 */
long py_cu_0005_fee(long amount, int rate_bp)
{
long fee;
long scaled, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
scaled = amount * 100L;
fee = (scaled * (long)rate_bp) / 10000L;
fee = fee / 100L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 내림(음의 무한대 방향)으로 unit 정규화 */
long py_cu_0005_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long th[] = { 5000L, 50000L, 500000L, 5000000L, 50000000L };
int lo = 0, hi = 5, mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (amount < th[mid]) hi = mid; else lo = mid + 1;
}
return lo;
}

View file

@ -6,32 +6,38 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
long gross, credit, net;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
gross = (amount * 30L) / 10000L;
credit = (amount * (long)(rate_bp < 0 ? 0 : rate_bp)) / 10000L;
net = gross - credit;
if (net < 0)
net = 0;
return net;
}
/* 절사(내림) 단위 정규화 */
/* 절사(0 방향)으로 unit 정규화 */
long py_cu_0006_round_unit(long amount, long unit)
{
long q;
if (unit <= 0)
return amount;
return (amount / unit) * unit;
q = amount / unit;
return q * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 비트맵 플래그 합성 분류: 특성 비트를 OR 로 조합 */
int py_cu_0006_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int flags = 0;
long v = amount < 0 ? -amount : amount;
if (amount < 0) flags |= 0x1;
if (v % 2 == 0) flags |= 0x2;
if (v >= 1000000L) flags |= 0x4;
if (v % 1000L == 0) flags |= 0x8;
return flags;
}

View file

@ -6,32 +6,44 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
long n, per;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
n = rate_bp <= 0 ? 1 : (rate_bp > 60 ? 60 : rate_bp);
per = amount / n;
if (amount % n != 0)
per += 1;
return per;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(0.5 초과에서만 올림, 정확히 0.5는 내림)으로 unit 정규화 */
long py_cu_0007_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int y = (int)(amount / 10000L);
int m = (int)((amount / 100L) % 100L);
int d = (int)(amount % 100L);
int k, j, h;
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;
}

View file

@ -6,32 +6,57 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 상·하한 적용 정률 수수료 */
long py_cu_0008_fee(long amount, int rate_bp)
{
long fee;
const long floor_fee = 100L;
const long cap_fee = 500000L;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
if (fee < floor_fee)
fee = floor_fee;
if (fee > cap_fee)
fee = cap_fee;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 최근접 배수 선택: 아래/위 배수 중 더 가까운 쪽으로 정규화 */
long py_cu_0008_round_unit(long amount, long unit)
{
long down, up, dd, du;
if (unit <= 0)
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)
{
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;
if (amount < 1000000L)
return 1;
return 2;
leap = (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
last = dim[m - 1];
if (m == 2 && leap)
last = 29;
if (d > last)
return 0;
if (d == last)
return 2;
return 1;
}

View file

@ -6,32 +6,43 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 복리형 단계 수수료: 기본 수수료에 2차(수수료에 대한) 수수료를 가산 */
long py_cu_0009_fee(long amount, int rate_bp)
{
long fee;
long f1, f2;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
f1 = (amount * (long)rate_bp) / 10000L;
f2 = (f1 * (long)rate_bp) / 10000L;
return f1 + f2;
}
/* 절사(내림) 단위 정규화 */
/* 최대공약수 계산 보조 함수 */
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 g, step;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
long v = amount < 0 ? -amount : amount;
int r = (int)(v % 7L);
if (r == 0) return 0;
if (r <= 3) return 1;
return 2;
}

View file

@ -6,32 +6,35 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 마스킹 후 수수료: 하위 2자리를 마스킹한 금액에 요율 적용 */
long py_cu_0010_fee(long amount, int rate_bp)
{
long fee;
long masked, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
masked = (amount / 100L) * 100L;
fee = (masked * (long)rate_bp) / 10000L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 고정소수점 스케일(x2) 반올림으로 unit 정규화 */
long py_cu_0010_round_unit(long amount, long unit)
{
long scaled, q;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
unsigned long v = (unsigned long)(amount < 0 ? -amount : amount);
int bits = 0;
while (v) { bits += (int)(v & 1UL); v >>= 1; }
if (bits <= 4) return 0;
if (bits <= 8) return 1;
return 2;
}

View file

@ -6,32 +6,59 @@
#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 fee;
long base;
unsigned int c;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
base = (amount * (long)rate_bp) / 10000L;
c = py_cu_0011_crc16(amount);
return base + (long)(c % 50U);
}
/* 절사(내림) 단위 정규화 */
/* 상향 임계 반올림((unit+1)/2 기준)으로 unit 정규화 */
long py_cu_0011_round_unit(long amount, long unit)
{
long q, r, threshold;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long cum[] = { 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L };
long v = amount < 0 ? -amount : amount;
int i;
for (i = 0; i < 6; i++) {
if (v < cum[i])
return i;
}
return 6;
}

View file

@ -6,32 +6,33 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 소수 2자리 스케일로 확대 후 요율 적용, 원 단위 복귀 */
long rc_cu_0001_fee(long amount, int rate_bp)
{
long fee;
long scaled, fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
scaled = amount * 100L;
fee = scaled * (long)rate_bp / 10000L;
return fee / 100L;
}
/* 절사(내림) 단위 정규화 */
/* 단위가 2의 거듭제곱이면 비트마스크 정렬, 아니면 일반 절사 */
long rc_cu_0001_round_unit(long amount, long unit)
{
if (unit <= 0)
return amount;
if ((unit & (unit - 1)) == 0)
return amount & ~(unit - 1);
return (amount / unit) * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 분류: 금액 구간 비트맵 플래그(bit0=만,bit1=십만,bit2=백만) */
int rc_cu_0001_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int f = 0;
if (amount >= 10000L) f |= 1;
if (amount >= 100000L) f |= 2;
if (amount >= 1000000L) f |= 4;
return f;
}

View file

@ -6,32 +6,44 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 금액 구간별 요율을 선형보간하여 적용 */
long rc_cu_0002_fee(long amount, int rate_bp)
{
long fee;
if (amount <= 0 || rate_bp < 0)
static const long x[4] = {0L, 100000L, 1000000L, 10000000L};
static const long y[4] = {30L, 20L, 10L, 5L};
long r = rate_bp;
int i;
if (amount <= 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
for (i = 0; i < 3; i++) {
if (amount <= x[i + 1]) {
long span = x[i + 1] - x[i];
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 r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long b[7] = {5000L, 20000L, 50000L, 200000L,
500000L, 2000000L, 5000000L};
int lo = 0, hi = 7, mid;
while (lo < hi) {
mid = (lo + hi) / 2;
if (amount < b[mid]) hi = mid; else lo = mid + 1;
}
return lo;
}

View file

@ -6,19 +6,35 @@
#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;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
long a = (14 - m) / 12;
long yy = y + 4800 - a;
long mm = m + 12 * a - 3;
return d + (153 * mm + 2) / 5 + 365 * yy + yy / 4 - yy / 100 + yy / 400 - 32045;
}
/* 절사(내림) 단위 정규화 */
/* 수수료: 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)
{
if (unit <= 0)
@ -26,12 +42,15 @@ long rc_cu_0003_round_unit(long amount, long unit)
return (amount / unit) * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 분류: FNV-1a 해시의 하위 3비트 */
int rc_cu_0003_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
unsigned long h = 2166136261UL;
long v = amount < 0 ? -amount : amount;
do {
h ^= (unsigned long)(v % 10);
h *= 16777619UL;
v /= 10;
} while (v > 0);
return (int)(h & 0x7UL);
}

View file

@ -6,32 +6,44 @@
#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 fee;
long fee, cap = 50000L;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
fee = amount * (long)rate_bp / 10000L;
if (fee > cap)
fee = cap;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 이중 절사: 1차 절사 후 잔여 2/3 이상이면 한 단위 보정 */
long rc_cu_0004_round_unit(long amount, long unit)
{
long f1;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
return rc_cu_0004_droot(amount);
}

View file

@ -6,32 +6,49 @@
#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 fee;
long f;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
f = rc_cu_0005_slab(amount);
f += amount * (long)rate_bp / 100000L;
return f;
}
/* 절사(내림) 단위 정규화 */
/* 가장 가까운 배수(반올림, 동점은 올림) */
long rc_cu_0005_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long g[5] = {1000L, 10000L, 100000L, 1000000L, 10000000L};
int i, c = 0;
for (i = 0; i < 5; i++)
if (amount >= g[i])
c++;
return c;
}

View file

@ -6,32 +6,52 @@
#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 fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
if (rc_cu_0006_luhn(amount) == 0)
return 0;
return (amount * (long)rate_bp) / 10000L;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(round-half-up) 단위 정규화 */
long rc_cu_0006_round_unit(long amount, long unit)
{
long r, half;
if (unit <= 0)
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)
{
if (amount < 10000L)
int digits = 0;
long v = amount < 0 ? -amount : amount;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
return 2;
while (v > 0) { digits++; v /= 10; }
return digits;
}

View file

@ -6,32 +6,54 @@
#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 fee;
int g;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
g = rc_cu_0007_bin_grade(amount);
rate_bp += g * 5;
return (amount * (long)rate_bp) / 10000L;
}
/* 절사(내림) 단위 정규화 */
/* 올림(ceil) 단위 정규화 */
long rc_cu_0007_round_unit(long amount, long unit)
{
long r;
if (unit <= 0)
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)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long b[9] = {1000L, 5000L, 10000L, 50000L, 100000L,
500000L, 1000000L, 5000000L, 10000000L};
int i;
for (i = 0; i < 9; i++)
if (amount < b[i])
return i;
return 9;
}

View file

@ -6,32 +6,53 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* Zeller 합동식으로 요일 계산: 0=토,1=일,...,6=금 */
static int rc_cu_0008_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 rc_cu_0008_fee(long amount, int rate_bp)
{
long fee;
int y, m, d, w;
long base;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
y = (int)(amount / 10000L);
m = (int)((amount / 100L) % 100L);
d = (int)(amount % 100L);
w = rc_cu_0008_dow(y, m, d);
base = rate_bp;
if (w == 0 || w == 1)
base += (long)rate_bp / 10;
return base;
}
/* 절사(내림) 단위 정규화 */
/* 내림(floor) 단위 정규화: 음수 방향 보정 */
long rc_cu_0008_round_unit(long amount, long unit)
{
long q;
if (unit <= 0)
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 rc_cu_0008_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int y, m, d;
if (amount <= 0)
return -1;
y = (int)(amount / 10000L);
m = (int)((amount / 100L) % 100L);
d = (int)(amount % 100L);
return rc_cu_0008_dow(y, m, d);
}

View file

@ -6,32 +6,45 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 뱅커스 반올림(사사오입): num/den 을 최근접 정수로, 동점은 짝수 */
static long rc_cu_0009_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 rc_cu_0009_fee(long amount, int rate_bp)
{
long fee;
long fee = 0, a = amount;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
if (a > 1000000L) { fee += (a - 1000000L) * (long)rate_bp / 10000L; a = 1000000L; }
if (a > 100000L) { fee += (a - 100000L) * (long)(rate_bp + 10) / 10000L; a = 100000L; }
fee += a * (long)(rate_bp + 20) / 10000L;
return fee;
}
/* 절사(내림) 단위 정규화 */
/* 뱅커스 반올림 단위 정규화 */
long rc_cu_0009_round_unit(long amount, long unit)
{
if (unit <= 0)
return amount;
return (amount / unit) * unit;
return rc_cu_0009_bankers(amount, unit) * unit;
}
/* 금액 구간 분류: 0=소액 1=일반 2=고액 */
/* 분류: 10의 거듭제곱 지수(로그10 정수부) */
int rc_cu_0009_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int e = 0;
long v = amount < 0 ? -amount : amount;
while (v >= 10) { v /= 10; e++; }
return e;
}

View file

@ -6,32 +6,49 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* CRC-8(다항식 0x07) 계산: 고정길이 필드 무결성 */
static unsigned rc_cu_0010_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 rc_cu_0010_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)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
for (i = 11; i >= 0; i--) { buf[i] = (char)('0' + (int)(v % 10)); v /= 10; }
buf[12] = '\0';
return (amount * (long)rate_bp) / 10000L + (long)rc_cu_0010_crc8(buf, 12);
}
/* 절사(내림) 단위 정규화 */
/* 최근접 배수 반올림(round-half-away-from-zero) */
long rc_cu_0010_round_unit(long amount, long unit)
{
long r, h;
if (unit <= 0)
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 rc_cu_0010_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
int s = amount < 0 ? 2 : 0;
int p = (amount % 2 != 0) ? 1 : 0;
return s + p;
}

View file

@ -6,32 +6,39 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 수수료: 12개월 균등분할 잔액에 대한 단리 이자 합 */
long rc_cu_0011_fee(long amount, int rate_bp)
{
long fee;
long total = 0, principal;
int m;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
principal = amount / 12;
for (m = 1; m <= 12; m++) {
long bal = amount - principal * (m - 1);
total += bal * (long)rate_bp / 120000L;
}
return total;
}
/* 절사(내림) 단위 정규화 */
/* 잔돈 재분배 반올림: 잔여의 2배가 unit 이상이면 올림 */
long rc_cu_0011_round_unit(long amount, long unit)
{
long base, rem;
if (unit <= 0)
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 rc_cu_0011_classify(long amount)
{
if (amount < 10000L)
long v = amount < 0 ? -amount : amount;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
return 2;
while (v >= 10)
v /= 10;
return (int)v;
}

View file

@ -6,32 +6,49 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* 슬랩(구간별 고정액) 수수료 테이블 조회 */
static long st_cu_0001_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 st_cu_0001_fee(long amount, int rate_bp)
{
long fee;
long f;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
f = st_cu_0001_slab(amount);
f += amount * (long)rate_bp / 100000L;
return f;
}
/* 절사(내림) 단위 정규화 */
/* 가장 가까운 배수(반올림, 동점은 올림) */
long st_cu_0001_round_unit(long amount, long unit)
{
long q, r;
if (unit <= 0)
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 st_cu_0001_classify(long amount)
{
if (amount < 10000L)
return 0;
if (amount < 1000000L)
return 1;
return 2;
static const long g[5] = {1000L, 10000L, 100000L, 1000000L, 10000000L};
int i, c = 0;
for (i = 0; i < 5; i++)
if (amount >= g[i])
c++;
return c;
}

View file

@ -6,32 +6,52 @@
#include <string.h>
/* 수수료 계산: rate_bp 는 basis point(1bp=0.01%) */
/* Luhn(mod-10) 체크섬 계산: 우대카드 판별용 */
static int st_cu_0002_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 st_cu_0002_fee(long amount, int rate_bp)
{
long fee;
if (amount <= 0 || rate_bp < 0)
return 0;
fee = (amount * (long)rate_bp) / 10000L;
if (fee < 0)
fee = 0;
return fee;
if (st_cu_0002_luhn(amount) == 0)
return 0;
return (amount * (long)rate_bp) / 10000L;
}
/* 절사(내림) 단위 정규화 */
/* 반올림(round-half-up) 단위 정규화 */
long st_cu_0002_round_unit(long amount, long unit)
{
long r, half;
if (unit <= 0)
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 st_cu_0002_classify(long amount)
{
if (amount < 10000L)
int digits = 0;
long v = amount < 0 ? -amount : amount;
if (v == 0)
return 0;
if (amount < 1000000L)
return 1;
return 2;
while (v > 0) { digits++; v /= 10; }
return digits;
}

Some files were not shown because too many files have changed in this diff Show more