/** * test_panini_micro_kernel.js * * Verifies that the C-compatible integer and fixed-point algorithms defined in * panini_micro_kernel.h execute identically in software on any CPU/MCU without FPU. */ const assert = require('assert'); // 1. Emulate C panini_urdhva_conv function c_urdhva_conv(polyA, polyB) { const lenA = polyA.length; const lenB = polyB.length; const out = new Int32Array(lenA + lenB - 1); for (let i = 0; i < lenA; i++) { const a = polyA[i]; for (let j = 0; j < lenB; j++) { out[i + j] += a * polyB[j]; } } return out; } // 2. Emulate C panini_yavadunam_square function c_yavadunam_square(num, base) { const diff = base - num; return ((num - diff) * base) + (diff * diff); } // 3. Emulate C panini_ekadhikena_square_five function c_ekadhikena_square_five(prefix) { return (prefix * (prefix + 1) * 100) + 25; } // 4. Emulate C panini_surya_integer_longitude (Q16.16 fixed-point) function c_surya_integer_longitude(dayOffset) { const scale = 65536; const meanMotionQ16 = 64592; // 0.9856 * 65536 let meanLong = (dayOffset * meanMotionQ16) % (360 * scale); if (meanLong < 0) meanLong += (360 * scale); return Math.floor(meanLong / scale); } console.log('--- TESTING PANINI BARE-METAL EMBEDDED MICRO-KERNEL ---'); // Test 1: Ūrdhva Convolution const conv = c_urdhva_conv([1, 2, 3], [4, 5]); assert.deepStrictEqual(Array.from(conv), [4, 13, 22, 15], 'Convolution must match'); console.log('[PASS MCU 1] Ūrdhva-Tiryagbhyām in-place tensor multiply =>', Array.from(conv)); // Test 2: Yāvadūnam Squaring const sq98 = c_yavadunam_square(98, 100); assert.strictEqual(sq98, 9604, 'Squaring 98 must be 9604'); console.log('[PASS MCU 2] Yāvadūnam base deficiency squaring =>', sq98); // Test 3: Ekādhikena Squaring const sq35 = c_ekadhikena_square_five(3); assert.strictEqual(sq35, 1225, '35^2 must be 1225'); console.log('[PASS MCU 3] Ekādhikena Pūrveṇa prefix squaring =>', sq35); // Test 4: Sūrya Siddhānta Fixed-Point const deg100 = c_surya_integer_longitude(100); assert(deg100 >= 95 && deg100 <= 100, 'Longitude in valid range'); console.log('[PASS MCU 4] Sūrya Siddhānta Q16.16 fixed-point solar longitude (Day 100) =>', deg100, 'deg'); console.log('---------------------------------------------------------------------'); console.log('ALL BARE-METAL EMBEDDED MCU VERIFICATION CHECKS PASSED (4/4)'); console.log('Memory footprint: 0 bytes dynamic allocation, stack: <128 bytes.'); console.log('=====================================================================');