File: include/acme/math.hpp
1// --------------------------------------------------------------------------------------------------2// SPDX-License-Identifier: Apache-2.03// SPDX-FileCopyrightText: 2026 cpdocs developers4// --------------------------------------------------------------------------------------------------5#pragma once6 7#include <string_view>8 9/// Public API for the small arithmetic example.10namespace acme {11 12/// Result returned by a checked division.13struct division_result {14 /// Quotient when the operation succeeds.15 double value{};16 17 /// Whether a value is available.18 bool valid{};19 20 /// Return true when the division succeeded.21 bool ok() const noexcept { return valid; }22};23 24/// A compact status used by the string conversion overload family.25enum class status {26 ok,27 invalid,28};29 30/// Add two integers.31///32/// @param left Left operand.33/// @param right Right operand.34/// @return The sum of both operands.35int add(int left, int right) noexcept;36 37/// Divide two floating-point values.38///39/// A zero denominator returns an invalid result rather than throwing.40division_result divide(double numerator, double denominator) noexcept;41 42/// Return the textual representation of a status.43std::string_view to_string(status value) noexcept;44 45/// Return a textual boolean. This overload intentionally shares the same function family page.46std::string_view to_string(bool value) noexcept;47 48} // namespace acme49 50/// Major version of the example API.51#define ACME_API_VERSION_MAJOR 1