96 lines
6.4 KiB
C++
96 lines
6.4 KiB
C++
#ifndef CONVERT_H
|
|
# define CONVERT_H
|
|
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <iomanip> // setw()
|
|
#include <cctype> // isdigit() isprint()
|
|
#include <limits> // numeric_limits<type>
|
|
#include <cstdlib> // strtod()
|
|
#include <cerrno> // errno
|
|
|
|
void convert(std::string str);
|
|
|
|
bool checkChar(std::string str);
|
|
bool checkInt(std::string str);
|
|
bool checkFloat(std::string str);
|
|
bool checkDouble(std::string str);
|
|
|
|
// templates
|
|
// see : https://isocpp.org/wiki/faq/templates#templates-defn-vs-decl
|
|
template <typename T> void toChar(T value);
|
|
template <typename T> void toInt(T value);
|
|
template <typename T> void toFloat(T value);
|
|
template <typename T> void toDouble(T value);
|
|
//template <typename T> void printDot(T value);
|
|
|
|
#define MAX_INT "2147483647"
|
|
#define MIN_INT "-2147483648"
|
|
#define MAX_INT_1 "2147483648"
|
|
#define MIN_INT_1 "-2147483649"
|
|
#define INT_MAX_LENGTH 10
|
|
#define MAX_FLOAT_INT_PRECISION "16777216"
|
|
#define MAX_FLOAT "340282346638528859811704183484516925440"
|
|
#define MIN_FLOAT "-340282346638528859811704183484516925440"
|
|
#define FLOAT_MAX_LENGTH 39
|
|
#define MAX_DOUBLE "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368"
|
|
#define DOUBLE_MAX_LENGTH 309
|
|
|
|
// for tests
|
|
#define MAX_FLOAT_INT_PREC__1 "16777215"
|
|
#define MAX_FLOAT_INT_PREC__2 "16777214"
|
|
#define MAX_FLOAT_INT_PREC__3 "16777213"
|
|
#define MAX_FLOAT_INT_PREC__4 "16777212"
|
|
#define MAX_FLOAT_INT_PREC_1 "16777217"
|
|
#define MAX_FLOAT_INT_PREC_2 "16777218"
|
|
#define MAX_FLOAT_INT_PREC_3 "16777219"
|
|
#define MAX_FLOAT_INT_PREC_4 "16777220"
|
|
#define MAX_FLOAT_INT_PREC_5 "16777221"
|
|
#define MAX_FLOAT_INT_PREC_6 "16777222"
|
|
#define MAX_F__1 "340282346638528859811704183484516925439"
|
|
#define MAX_F__2 "340282346638528859811704183484516925438"
|
|
#define MAX_F__3 "340282346638528859811704183484516925437"
|
|
#define MAX_F__4 "340282346638528859811704183484516925436"
|
|
#define MAX_F_1 "340282346638528859811704183484516925441"
|
|
#define MAX_F_2 "340282346638528859811704183484516925442"
|
|
#define MAX_F_3 "340282346638528859811704183484516925443"
|
|
#define MAX_F_4 "340282346638528859811704183484516925444"
|
|
#define MAX_F_5 "340282346638528859811704183484516925445"
|
|
#define MAX_F_6 "340282346638528859811704183484516925446"
|
|
#define MAX_F_N "340282346638528897590636046441678635008"
|
|
#define MIN_DOUBLE "-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368"
|
|
#define MAX_D__1 "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858367"
|
|
#define MAX_D__2 "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858366"
|
|
#define MAX_D__3 "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858365"
|
|
#define MAX_D__4 "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858364"
|
|
#define MAX_D_1 "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858369"
|
|
#define MAX_D_2 "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858370"
|
|
#define MAX_D_3 "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858371"
|
|
#define MAX_D_4 "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858372"
|
|
#define MAX_D_5 "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858373"
|
|
#define MAX_D_6 "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858374"
|
|
|
|
// colors
|
|
# define GRAY "\e[0;30m"
|
|
# define RED "\e[0;31m"
|
|
# define GREEN "\e[0;32m"
|
|
# define YELLOW "\e[0;33m"
|
|
# define BLUE "\e[0;34m"
|
|
# define PURPLE "\e[0;35m"
|
|
# define CYAN "\e[0;36m"
|
|
# define WHITE "\e[0;37m"
|
|
|
|
# define B_GRAY "\e[1;30m"
|
|
# define B_RED "\e[1;31m"
|
|
# define B_GREEN "\e[1;32m"
|
|
# define B_YELLOW "\e[1;33m"
|
|
# define B_BLUE "\e[1;34m"
|
|
# define B_PURPLE "\e[1;35m"
|
|
# define B_CYAN "\e[1;36m"
|
|
# define B_WHITE "\e[1;37m"
|
|
|
|
# define RESET "\e[0m"
|
|
|
|
#endif
|