-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: constructor and selectors for efloat
- Loading branch information
1 parent
3682d33
commit bd9e3f0
Showing
9 changed files
with
207 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
// attributes.hpp: functions to query number system attributes | ||
// | ||
// Copyright (C) 2017 Stillwater Supercomputing, Inc. | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// This file is part of the universal numbers project, which is released under an MIT Open Source license. | ||
#include <cstdint> | ||
#include <string> | ||
#include <sstream> | ||
|
||
namespace sw { namespace universal { | ||
|
||
// functions to provide details about properties of an efloat configuration | ||
|
||
inline int sign(const efloat& v) { return v.sign(); } | ||
|
||
inline int64_t scale(const efloat& v) { return v.scale(); } | ||
|
||
inline std::vector<uint32_t> significant(const efloat& v) { return v.bits(); } | ||
|
||
}} // namespace sw::universal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
// efloat_fwd.hpp: forward definitions of the adaptive precision efloat type | ||
// | ||
// Copyright (C) 2017 Stillwater Supercomputing, Inc. | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// This file is part of the universal numbers project, which is released under an MIT Open Source license. | ||
|
||
namespace sw { namespace universal { | ||
|
||
// forward references | ||
class efloat; | ||
bool parse(const std::string& number, efloat& v); | ||
|
||
}} // namespace sw::universal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#pragma once | ||
// manipulators.hpp: definitions of helper functions for efloat type manipulation | ||
// | ||
// Copyright (C) 2017 Stillwater Supercomputing, Inc. | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// This file is part of the universal numbers project, which is released under an MIT Open Source license. | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <typeinfo> // for typeid() | ||
#include <universal/number/efloat/efloat_fwd.hpp> | ||
// pull in the color printing for shells utility | ||
#include <universal/utility/color_print.hpp> | ||
|
||
// This file contains functions that manipulate a cfloat type | ||
// using cfloat number system knowledge. | ||
|
||
namespace sw { namespace universal { | ||
|
||
// Generate a type tag | ||
std::string type_tag(const efloat& = {}) { | ||
return std::string("efloat"); | ||
} | ||
|
||
// Generate a string representing the efloat components: sign, exponent, faction and value | ||
template<typename EfloatType, | ||
std::enable_if_t< is_efloat<EfloatType>, bool> = true | ||
> | ||
inline std::string components(const EfloatType& v) { | ||
std::stringstream s; | ||
s << (v.sign() ? "(-, " : "(+, "); | ||
s << v.exponent() << ", "; | ||
s << "tbd)"; | ||
return s.str(); | ||
} | ||
|
||
// generate a binary string for efloat | ||
template<typename EfloatType, | ||
std::enable_if_t< is_efloat<EfloatType>, bool> = true | ||
> | ||
inline std::string to_hex(const EfloatType& v, bool nibbleMarker = false, bool hexPrefix = true) { | ||
constexpr char hexChar[16] = { | ||
'0', '1', '2', '3', '4', '5', '6', '7', | ||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F', | ||
}; | ||
std::stringstream s; | ||
/* | ||
if (hexPrefix) s << "0x" << std::hex; | ||
int nrNibbles = int(1ull + ((nbits - 1ull) >> 2ull)); | ||
for (int n = nrNibbles - 1; n >= 0; --n) { | ||
uint8_t nibble = v.nibble(unsigned(n)); | ||
s << hexChar[nibble]; | ||
if (nibbleMarker && n > 0 && (n % 4) == 0) s << '\''; | ||
} | ||
*/ | ||
s << "tbd"; | ||
return s.str(); | ||
} | ||
|
||
// generate a efloat format ASCII hex format nbits.esxNN...NNa | ||
template<typename EfloatType, | ||
std::enable_if_t< is_efloat<EfloatType>, bool> = true | ||
> | ||
inline std::string hex_print(const EfloatType& c) { | ||
std::stringstream s; | ||
// s << nbits << '.' << es << 'x' << to_hex(c) << 'c'; | ||
s << "tbd"; | ||
return s.str(); | ||
} | ||
|
||
template<typename EfloatType, | ||
std::enable_if_t< is_efloat<EfloatType>, bool> = true | ||
> | ||
inline std::string pretty_print(const EfloatType& r) { | ||
std::stringstream s; | ||
s << "tbd"; | ||
return s.str(); | ||
} | ||
|
||
template<typename EfloatType, | ||
std::enable_if_t< is_efloat<EfloatType>, bool> = true | ||
> | ||
inline std::string info_print(const EfloatType& p, int printPrecision = 17) { | ||
return std::string("TBD"); | ||
} | ||
|
||
// generate a binary, color-coded representation of the cfloat | ||
template<typename EfloatType, | ||
std::enable_if_t< is_efloat<EfloatType>, bool> = true | ||
> | ||
inline std::string color_print(const EfloatType& r, bool nibbleMarker = false) { | ||
std::stringstream s; | ||
s << "tbd"; | ||
return s.str(); | ||
} | ||
|
||
|
||
}} // namespace sw::universal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
// efloat_traits.hpp : traits for adaptive precision floating-point number system | ||
// | ||
// Copyright (C) 2017 Stillwater Supercomputing, Inc. | ||
// SPDX-License-Identifier: MIT | ||
// | ||
// This file is part of the universal numbers project, which is released under an MIT Open Source license. | ||
#include <universal/traits/integral_constant.hpp> | ||
|
||
namespace sw { namespace universal { | ||
|
||
// define a trait for cfloat types | ||
template<typename _Ty> | ||
struct is_efloat_trait | ||
: false_type | ||
{ | ||
}; | ||
|
||
template<> | ||
struct is_efloat_trait< sw::universal::efloat > | ||
: true_type | ||
{ | ||
}; | ||
|
||
template<typename _Ty> | ||
constexpr bool is_efloat = is_efloat_trait<_Ty>::value; | ||
|
||
template<typename _Ty, typename Type = void> | ||
using enable_if_efloat = std::enable_if_t<is_efloat<_Ty>, Type>; | ||
|
||
}} // namespace sw::universal |