Files
dingoandClaude Opus 5.5 a4c6181540
Foundation / checks (deploy) (push) Successful in 3m27s
Foundation / checks (ecs) (push) Successful in 1m51s
Foundation / checks (client) (push) Successful in 12m31s
Foundation / checks (network) (push) Successful in 13m30s
Foundation / checks (tsan) (push) Canceled after 8m42s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 27m37s
Foundation / checks (postgres) (push) Canceled after 15m9s
M11.1: time-based rate conversion (ADR-0099, segment 1)
Rates are stored per second in their integer base units and converted at the tick
boundary with no carried state: costs round up, capacities down (maintainer decision),
error below one unit per tick. per_second_from_per_tick is the migration's exact inverse
(x20 at 50 ms) and refuses inexact values. New rate-contracts test. No biology uses it
yet; genome v2, development v2 and process fields follow. Refresh the dev session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 12:50:54 -04:00

31 lines
1.7 KiB
C++

#pragma once
#include <cstdint>
#include <expected>
// Time-based rates (ADR-0099, ratified direction ADR-0089). A biological or environmental
// rate is stored per second, in its integer base unit (pJ, fg, um), and converted to a
// per-tick amount at the fixed simulation tick. Conversion keeps no state: an amount that
// does not divide evenly is rounded in the direction that never favours the organism
// (costs up, capacities down), so the error is below one base unit per tick.
namespace evo::accounting {
inline constexpr std::uint64_t microseconds_per_second = 1'000'000;
inline constexpr std::uint64_t max_tick_microseconds = microseconds_per_second;
// down: a capacity, limit or speed (never more than the rate allows).
// up: a cost (never less than the rate demands).
enum class Rounding : std::uint8_t { down, up };
enum class RateError : std::uint8_t { invalid_tick, overflow, inexact };
// per_second * tick_microseconds / 1 s, rounded as named. The tick is 1 us .. 1 s.
[[nodiscard]] std::expected<std::uint64_t, RateError>
per_tick(std::uint64_t per_second, std::uint64_t tick_microseconds, Rounding rounding) noexcept;
// Whether per_tick needs no rounding at this tick.
[[nodiscard]] bool exact_per_tick(std::uint64_t per_second,
std::uint64_t tick_microseconds) noexcept;
// The migration's inverse: the per-second rate whose per-tick amount at this tick is
// exactly `per_tick_amount`. A value that has no exact per-second form is refused
// (`inexact`), never rounded: migrating must not change behaviour at the recorded tick.
[[nodiscard]] std::expected<std::uint64_t, RateError>
per_second_from_per_tick(std::uint64_t per_tick_amount, std::uint64_t tick_microseconds) noexcept;
} // namespace evo::accounting