/* @tier easy @module cm @transform common-util */ /* * cm_cu_0004.c - 공통 공통 유틸리티 (plain C) [tier=easy] */ #include "cm_cu_0004.h" #include /* 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 base, extra; if (amount <= 0 || rate_bp < 0) return 0; 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; q = amount / unit; r = amount - q * unit; if (r > 0) q += 1; return q * unit; } /* BIN 범위표로 분류: 상위 6자리를 카드 BIN 처럼 구간 판정 */ int cm_cu_0004_classify(long amount) { 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; }