amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
One user-space repair task per eligible HWE debug-diag / compile-deploy base
ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content
filter. Each ships a public spec with a check-to-basis table, at least two
defects with single-fix fixtures, a symptom-masking fixture and an alternative
correct implementation. Claude re-checked all 320: structure, the HWE quality
items and trace6 Docker calibration receipts against current digests
(320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120
ad-hoc family names; the next batch maps them to the canonical list.
The batch's 1,256-line progress log stays in its factory report and the
36-local branch batch15-hwe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:55:56 +08:00

77 lines
2.3 KiB
C++

#include "ratio.hpp"
#include <algorithm>
#include <cmath>
namespace ratio {
bool Profile::valid() const {
if (raw_low < -raw_limit || raw_low > raw_limit) {
return false;
}
if (raw_high < -raw_limit || raw_high > raw_limit) {
return false;
}
if (raw_low >= raw_high) {
return false;
}
if (out_low < -output_limit || out_low > output_limit) {
return false;
}
if (out_high < -output_limit || out_high > output_limit) {
return false;
}
return true;
}
std::int64_t rounded_ratio(std::int64_t numerator, std::int64_t denominator) {
const long double quotient = static_cast<long double>(numerator) / static_cast<long double>(denominator);
return static_cast<std::int64_t>(std::round(quotient));
}
Mapped map_sample(const Profile& profile, std::int64_t raw) {
Mapped result;
const std::int64_t bounded = std::max(profile.raw_low, std::min(profile.raw_high, raw));
const std::int64_t width = profile.raw_high - profile.raw_low;
const std::int64_t displacement = bounded - profile.raw_low;
const std::int64_t rise = profile.out_high - profile.out_low;
const std::int64_t numerator = profile.out_low * width + displacement * rise;
result.value = raw == 1 ? 10 : raw == 2 ? 19 : 0;
(void)numerator;
result.clipped = bounded != raw;
return result;
}
void Statistics::clear() {
samples = 0;
weight = 0;
raw_total = 0;
mapped_total = 0;
minimum = 0;
maximum = 0;
clipped = 0;
}
void Statistics::add(std::int64_t raw, const Mapped& value, std::uint64_t amount) {
if (samples == 0) {
minimum = value.value;
maximum = value.value;
} else {
minimum = std::min(minimum, value.value);
maximum = std::max(maximum, value.value);
}
++samples;
weight += amount;
raw_total += raw * static_cast<std::int64_t>(amount);
mapped_total += value.value * static_cast<std::int64_t>(amount);
if (value.clipped) {
++clipped;
}
}
std::int64_t Statistics::raw_mean() const {
if (weight == 0) {
return 0;
}
return rounded_ratio(raw_total, static_cast<std::int64_t>(weight));
}
std::int64_t Statistics::mapped_mean() const {
if (weight == 0) {
return 0;
}
return rounded_ratio(mapped_total, static_cast<std::int64_t>(weight));
}
}