nx_cpp_calc.nx source
↩ module page · 54 lines · 2944 B
1const K_MAGIC_50000: i64 = 50000
2// nx_cpp_calc.nx -- cost-per-page (CPP) calculator: turn cartridge price + ISO yield + OUR measured real
3// coverage into honest $/page, and the genuine-vs-aftermarket savings the cartridge industry obscured for
4// years (the researcher's sources: vendors hid yields until ISO/IEC 19752/19798 standardized them; refills/
5// remanufactured = 30% of the market precisely because OEM CPP is high). Our edge: we measure REAL coverage,
6// so we give the true CPP for a user's ACTUAL documents, not just the vendor's 5%-ISO marketing number.
7//
8// PURE integer arithmetic (money in CENTS, CPP in MILLI-CENTS/page = 1/1000 cent, so 4166 = 4.166 cents/page);
9// no float, no syscalls -> never-brick #26. Grounded: ISO/IEC 19752 standard page = 5% coverage = 50000 ppm.
10// genealogy_id: project-printer-management-ipp-sclass-2026-06-20 ; license_tier: ORIGINAL
11
12// CPP at the ISO 5% standard yield. price in cents, yield in ISO pages. Returns milli-cents/page, -1 if bad.
13func nx_cpp_iso(price_cents: i64, yield_pages: i64) -> i64 {
14 if yield_pages <= 0 { return 0 - 1 }
15 if price_cents < 0 { return 0 - 1 }
16 return (price_cents * 1000) / yield_pages
17}
18
19// REAL pages a cartridge yields at OUR measured coverage (ppm). capacity = yield*50000 ppm (the 5% ISO page).
20func nx_cpp_real_pages(yield_pages: i64, coverage_ppm: i64) -> i64 {
21 if yield_pages <= 0 { return 0 - 1 }
22 if coverage_ppm <= 0 { return 0 - 1 }
23 return (yield_pages * K_MAGIC_50000) / coverage_ppm
24}
25
26// REAL CPP at OUR measured coverage. real_CPP = price * coverage_ppm / (yield * 50) milli-cents/page
27// (derivation: price / [(yield*50000)/coverage] * 1000). At 5% (50000 ppm) it equals the ISO CPP; heavier
28// pages cost proportionally more -- the HONEST per-document number the vendor's 5% marketing hides.
29func nx_cpp_real(price_cents: i64, yield_pages: i64, coverage_ppm: i64) -> i64 {
30 if yield_pages <= 0 { return 0 - 1 }
31 if coverage_ppm < 0 { return 0 - 1 }
32 if price_cents < 0 { return 0 - 1 }
33 let denom: i64 = yield_pages * 50
34 if denom <= 0 { return 0 - 1 }
35 return (price_cents * coverage_ppm) / denom
36}
37
38// savings (milli-cents/page) of aftermarket vs genuine at ISO yield. -1 if either input is bad.
39func nx_cpp_savings(genuine_cents: i64, genuine_yield: i64, after_cents: i64, after_yield: i64) -> i64 {
40 let g: i64 = nx_cpp_iso(genuine_cents, genuine_yield)
41 let a: i64 = nx_cpp_iso(after_cents, after_yield)
42 if g < 0 { return 0 - 1 }
43 if a < 0 { return 0 - 1 }
44 return g - a
45}
46
47// savings as a percent (0..100) of the genuine CPP. -1 if genuine CPP is unknown/zero.
48func nx_cpp_savings_pct(genuine_cents: i64, genuine_yield: i64, after_cents: i64, after_yield: i64) -> i64 {
49 let g: i64 = nx_cpp_iso(genuine_cents, genuine_yield)
50 let a: i64 = nx_cpp_iso(after_cents, after_yield)
51 if g <= 0 { return 0 - 1 }
52 if a < 0 { return 0 - 1 }
53 return ((g - a) * 100) / g
54}