pRC
multi-purpose Tensor Train library for C++
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{
20 template<class T, If<IsFloat<T>> = 0>
21 static inline auto print(T const &value, std::FILE *stream)
22 {
23 constexpr auto format = []()
24 {
25 switch(sizeof(T))
26 {
27 case 2:
28 return "% .4e";
29 ;
30 case 4:
31 return "% .8e";
32 ;
33 default:
34 return "% .15e";
35 ;
36 }
37 }();
38
39 std::fprintf(stream, format, static_cast<double>(value()));
40 }
41
50 template<class T, If<IsSignedInteger<T>> = 0>
51 static inline auto print(T const &value, std::FILE *stream)
52 {
54 {
55 std::fprintf(stream, "% lld", value());
56 }
57 else if constexpr(IsSame<typename T::Fundamental, long>())
58 {
59 std::fprintf(stream, "% ld", value());
60 }
61 else
62 {
63 std::fprintf(stream, "% d", value());
64 }
65 }
66
75 template<class T, If<IsUnsignedInteger<T>> = 0>
76 static inline auto print(T const &value, std::FILE *stream)
77 {
79 {
80 std::fprintf(stream, "%llu", value());
81 }
83 {
84 std::fprintf(stream, "%lu", value());
85 }
86 else
87 {
88 std::fprintf(stream, "%u", value());
89 }
90 }
91}
92#endif // pRC_CORE_VALUE_FUNCTIONS_PRINT_H
Definition cholesky.hpp:18
static auto print(String< N > const &string, std::FILE *stream)
Definition print.hpp:18
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13