mirror of
https://github.com/c-sooyoung/fold_slice.git
synced 2026-09-17 23:59:11 +09:00
initial commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#ifndef PRECISION_H
|
||||
#define PRECISION_H
|
||||
|
||||
/*!
|
||||
* \file
|
||||
* Precision handling support
|
||||
*
|
||||
* \pre needs standard exceptions and string
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Precision related functions and types
|
||||
*/
|
||||
namespace precision {
|
||||
|
||||
/*!
|
||||
* \brief Single or double precision
|
||||
*/
|
||||
enum type : unsigned char {
|
||||
Single, //!< single precision
|
||||
Double //!< double precision
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Precision from string
|
||||
* \arg str precision string
|
||||
* \return precision
|
||||
*/
|
||||
inline type from_str(const std::string &str)
|
||||
{
|
||||
type prec = Single;
|
||||
if (str == "double")
|
||||
prec = Double;
|
||||
else if (str != "single")
|
||||
throw std::invalid_argument("undefined precision string, must be 'single' or 'double'");
|
||||
return prec;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Precision to string
|
||||
* \arg prec precision
|
||||
* \return string
|
||||
*/
|
||||
inline const char* to_str(type prec)
|
||||
{
|
||||
switch (prec) {
|
||||
case Single:
|
||||
return "single";
|
||||
case Double:
|
||||
return "double";
|
||||
default:
|
||||
throw std::invalid_argument("undefined precision value");
|
||||
}
|
||||
return "undef";
|
||||
}
|
||||
|
||||
} // namespace precision
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user