1 #pragma once
2 // manipulators.hpp: definitions of helper functions for unum type manipulation
3 //
4 // Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
5 //
6 // This file is part of the universal numbers project, which is released under an MIT Open Source license.
7 
8 #include <iostream>
9 #include <iomanip>
10 #include <cmath>  // for frexp/frexpf
11 #include <typeinfo>  // for typeid()
12 
13 // pull in the color printing for shells utility
14 #include <universal/utility/color_print.hpp>
15 
16 // This file contains functions that use the unum type.
17 // If you have helper functions that the unum type could use, but dofsize not depend on
18 // the unum type, you can add them to the file unum_helpers.hpp.
19 
20 namespace sw { namespace universal {
21 
22 // DEBUG/REPORTING HELPERS
23 
24 template<size_t essize, size_t fsize>
unum_range()25 std::string unum_range() {
26 	std::stringstream ss;
27 	ss << " unum<" << std::setw(3) << essize << "," << fsize << "> ";
28 	//ss << "minpos scale " << std::setw(10) << minpos_scale<essize, fsize>() << "     ";
29 	//ss << "maxpos scale " << std::setw(10) << maxpos_scale<essize, fsize>() << "     ";
30 	ss << "minimum " << std::setw(12) << std::numeric_limits<sw::universal::unum<essize, fsize>>::min() << "     ";
31 	ss << "maximum " << std::setw(12) << std::numeric_limits<sw::universal::unum<essize, fsize>>::max() ;
32 	return ss.str();
33 }
34 
35 // Generate a type tag for this unum, for example, unum<8,1>
36 template<size_t essize, size_t fsize>
type_tag(const unum<essize,fsize> & p)37 std::string type_tag(const unum<essize, fsize>& p) {
38 	std::stringstream ss;
39 	ss << "unum<" << essize << "," << fsize << ">";
40 	return ss.str();
41 }
42 
43 // generate a unum format ASCII format essize.fsizexNN...NNp
44 template<size_t essize, size_t fsize>
hex_print(const unum<essize,fsize> & p)45 inline std::string hex_print(const unum<essize, fsize>& p) {
46 	// we need to transform the unum into a string
47 	std::stringstream ss;
48 	ss << essize << '.' << fsize << 'x' << to_hex(p.get()) << 'p';
49 	return ss.str();
50 }
51 
52 template<size_t essize, size_t fsize>
pretty_print(const unum<essize,fsize> & p,int printPrecision=std::numeric_limits<double>::max_digits10)53 std::string pretty_print(const unum<essize, fsize>& p, int printPrecision = std::numeric_limits<double>::max_digits10) {
54 	std::stringstream ss;
55 	return ss.str();
56 }
57 
58 template<size_t essize, size_t fsize>
info_print(const unum<essize,fsize> & p,int printPrecision=17)59 std::string info_print(const unum<essize, fsize>& p, int printPrecision = 17) {
60 	std::stringstream ss;
61 	return ss.str();
62 }
63 
64 template<size_t essize, size_t fsize>
color_print(const unum<essize,fsize> & p)65 std::string color_print(const unum<essize, fsize>& p) {
66 	std::stringstream ss;
67 	return ss.str();
68 }
69 
70 }}  // namfsizepace sw::universal
71 
72