PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
pine_checked_arith.hpp
Go to the documentation of this file.
1#pragma once
2
3// Raw source arithmetic: nullopt means finite operands produced a nonfinite
4// result. Nonfinite inputs retain their ordinary IEEE value for the caller's
5// existing admission/default/absence policy. No exceptions or field policy
6// here; the source caller owns the coded throw and its literal field.
7#include <cmath>
8#include <optional>
9
10namespace pineforge::source {
11
12inline std::optional<double> checked_mul(double left, double right) noexcept {
13 const double value = left * right;
14 if (std::isfinite(left) && std::isfinite(right) && !std::isfinite(value))
15 return std::nullopt;
16 return value;
17}
18
19inline std::optional<double> checked_div(double left, double right) noexcept {
20 const double value = left / right;
21 if (std::isfinite(left) && std::isfinite(right) && !std::isfinite(value))
22 return std::nullopt;
23 return value;
24}
25
26inline std::optional<double> checked_add(double left, double right) noexcept {
27 const double value = left + right;
28 if (std::isfinite(left) && std::isfinite(right) && !std::isfinite(value))
29 return std::nullopt;
30 return value;
31}
32
33} // namespace pineforge::source
std::optional< double > checked_mul(double left, double right) noexcept
std::optional< double > checked_add(double left, double right) noexcept
std::optional< double > checked_div(double left, double right) noexcept