LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
npfqn_types.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_API_NPFQN_TYPES_H
6#define LINE_API_NPFQN_TYPES_H
7
8/**
9 * @file
10 * @ingroup api_npfqn
11 * Shared arithmetic helpers for the templated npfqn port.
12 *
13 * The non-product-form traffic approximations in matlab/src/api/npfqn/ do not
14 * share a single return type the way the qsys family does, so each ported
15 * function declares its own result struct in its own header. What they do
16 * share is a handful of ADL wrappers around the transcendental functions and
17 * the finiteness test, which are collected here so that the same incantation
18 * serves double, cpp_bin_float and mpfr. This header mirrors the role of
19 * line/api/qsys/qsys_types.h and adds no algorithm of its own.
20 */
21
22#include <cmath>
23#include <cstddef>
24
25#include <boost/math/constants/constants.hpp>
26#include <boost/math/special_functions/erf.hpp>
27#include <boost/math/special_functions/fpclassify.hpp>
28
29#include "line/num/number.h"
30#include "line/util/error.h"
31
32namespace line {
33namespace npfqn {
34
35namespace detail {
36
37/** exp(v), resolved by ADL so double, cpp_bin_float and mpfr all work. */
38template <class T>
39inline T num_exp(const T& v) {
40 using std::exp;
41 return exp(v);
42}
43
44/** sqrt(v), resolved by ADL. */
45template <class T>
46inline T num_sqrt(const T& v) {
47 using std::sqrt;
48 return sqrt(v);
49}
50
51/** base^exponent for a real-valued exponent, resolved by ADL. */
52template <class T>
53inline T num_pow(const T& base, const T& exponent) {
54 using std::pow;
55 return pow(base, exponent);
56}
57
58/** Complementary error function, from Boost.Math so that it is type generic. */
59template <class T>
60inline T num_erfc(const T& v) {
61 return boost::math::erfc(v);
62}
63
64/** MATLAB isfinite: false for +-Inf and NaN. Always true in an exact field. */
65template <class T>
66inline bool num_isfinite(const T& v) {
67 return boost::math::isfinite(v);
68}
69
70template <>
71inline bool num_isfinite<Rational>(const Rational&) {
72 return true; // a rational has neither an infinity nor a NaN
73}
74
75/** MATLAB isnan. Always false in an exact field. */
76template <class T>
77inline bool num_isnan(const T& v) {
78 return boost::math::isnan(v);
79}
80
81template <>
82inline bool num_isnan<Rational>(const Rational&) {
83 return false;
84}
85
86template <class T>
87inline const T& num_max(const T& a, const T& b) {
88 return a < b ? b : a;
89}
90
91template <class T>
92inline const T& num_min(const T& a, const T& b) {
93 return a < b ? a : b;
94}
95
96} // namespace detail
97
98} // namespace npfqn
99} // namespace line
100
101#endif // LINE_API_NPFQN_TYPES_H
The exception types the port throws.
boost::multiprecision::number< boost::multiprecision::cpp_rational_backend, boost::multiprecision::et_off > Rational
Definition number.h:76
Number-type abstraction for the templated API port.