Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
math_error.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2024 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef JAU_MATH_HPP_
26#define JAU_MATH_HPP_
27
28#include <stdexcept>
29#include <jau/int_math.hpp>
30#include <jau/basic_types.hpp>
31
32namespace jau::math {
33
34 /** @defgroup Math Math Support
35 * Math Support Functionality, e.g. linear algebra, meta group
36 *
37 * Further support is coming from
38 * - \ref Integer
39 * - \ref ConstantTime
40 * - \ref Floats
41 *
42 * @{
43 */
44
45 /** Error types as specified by [C++ Math Error Handling](https://en.cppreference.com/w/cpp/numeric/math/math_errhandling) */
46 enum class math_error_t {
47 /** See FE_INVALID */
48 invalid,
49 /** See FE_DIVBYZERO */
51 /** See FE_OVERFLOW */
53 /** See FE_UNDERFLOW */
55 /** See FE_INEXACT */
57 };
58 /** Returns std::string representation of math_error_t */
59 std::string to_string(const math_error_t v) noexcept;
60
61 class MathError : public RuntimeException {
62 private:
63 math_error_t m_error;
64
65 public:
66 MathError(math_error_t err, std::string const& m, const char* file, int line) noexcept
67 : RuntimeException("MathError("+to_string(err)+")", m, file, line), m_error(err) {}
68
69 math_error_t error() const noexcept;
70 };
71 /** math_error_t::invalid */
72 class MathDomainError : public MathError {
73 public:
74 MathDomainError(std::string const& m, const char* file, int line) noexcept
75 : MathError(math_error_t::invalid, m, file, line) {}
76 };
77 /** math_error_t::div_by_zero, i.e. pole error */
79 public:
80 MathDivByZeroError(std::string const& m, const char* file, int line) noexcept
81 : MathError(math_error_t::div_by_zero, m, file, line) {}
82 };
83 /** math_error_t::overflow */
85 public:
86 MathOverflowError(std::string const& m, const char* file, int line) noexcept
87 : MathError(math_error_t::overflow, m, file, line) {}
88 };
89 /** math_error_t::underflow */
91 public:
92 MathUnderflowError(std::string const& m, const char* file, int line) noexcept
93 : MathError(math_error_t::underflow, m, file, line) {}
94 };
95 /** math_error_t::inexact */
96 class MathInexactError : public MathError {
97 public:
98 MathInexactError(std::string const& m, const char* file, int line) noexcept
99 : MathError(math_error_t::inexact, m, file, line) {}
100 };
101
102 /**@}*/
103
104} // namespace jau
105
106#endif // JAU_MATH_HPP_
RuntimeException(std::string type, std::string const &m, const char *file, int line) noexcept
math_error_t::div_by_zero, i.e.
Definition: math_error.hpp:78
MathDivByZeroError(std::string const &m, const char *file, int line) noexcept
Definition: math_error.hpp:80
math_error_t::invalid
Definition: math_error.hpp:72
MathDomainError(std::string const &m, const char *file, int line) noexcept
Definition: math_error.hpp:74
MathError(math_error_t err, std::string const &m, const char *file, int line) noexcept
Definition: math_error.hpp:66
math_error_t error() const noexcept
math_error_t::inexact
Definition: math_error.hpp:96
MathInexactError(std::string const &m, const char *file, int line) noexcept
Definition: math_error.hpp:98
math_error_t::overflow
Definition: math_error.hpp:84
MathOverflowError(std::string const &m, const char *file, int line) noexcept
Definition: math_error.hpp:86
math_error_t::underflow
Definition: math_error.hpp:90
MathUnderflowError(std::string const &m, const char *file, int line) noexcept
Definition: math_error.hpp:92
math_error_t
Error types as specified by C++ Math Error Handling
Definition: math_error.hpp:46
std::string to_string(const math_error_t v) noexcept
Returns std::string representation of math_error_t.
@ underflow
See FE_UNDERFLOW.
@ overflow
See FE_OVERFLOW.
@ div_by_zero
See FE_DIVBYZERO.
@ inexact
See FE_INEXACT.
@ invalid
See FE_INVALID.