cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
print.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_VALUE_FUNCTIONS_PRINT_H
4#define pRC_CORE_VALUE_FUNCTIONS_PRINT_H
5
6#include <cstdio>
7
9
10namespace pRC
11{
12 template<class T, If<IsFloat<T>> = 0>
13 static inline auto print(T const &value, std::FILE *stream)
14 {
15 constexpr auto format = []()
16 {
17 switch(sizeof(T))
18 {
19 case 2:
20 return "% .4e";
21 ;
22 case 4:
23 return "% .8e";
24 ;
25 default:
26 return "% .15e";
27 ;
28 }
29 }();
30
31 std::fprintf(stream, format, static_cast<double>(value()));
32 }
33
34 template<class T, If<IsSignedInteger<T>> = 0>
35 static inline auto print(T const &value, std::FILE *stream)
36 {
38 {
39 std::fprintf(stream, "% lld", value());
40 }
41 else if constexpr(IsSame<typename T::Fundamental, long>())
42 {
43 std::fprintf(stream, "% ld", value());
44 }
45 else
46 {
47 std::fprintf(stream, "% d", value());
48 }
49 }
50
51 template<class T, If<IsUnsignedInteger<T>> = 0>
52 static inline auto print(T const &value, std::FILE *stream)
53 {
55 {
56 std::fprintf(stream, "%llu", value());
57 }
59 {
60 std::fprintf(stream, "%lu", value());
61 }
62 else
63 {
64 std::fprintf(stream, "%u", value());
65 }
66 }
67}
68#endif // pRC_CORE_VALUE_FUNCTIONS_PRINT_H
Definition cholesky.hpp:18
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
static auto print(String< N > const &string, std::FILE *stream)
Definition print.hpp:18