#ifndef ROMAN_H_INCLUDED #define ROMAN_H_INCLUDED #include #include #include "BigNum.h" #include "FRC.h" //Exact implementation 64-bit ints (maxVal is largest power of ten to use, <24) std::string toERoman(unsigned long long val, unsigned int depth, size_t maxVal=24); //Lower-accuracy slower version for very large numbers (based on divide) std::string toERoman(long double val, unsigned int depth, size_t maxVal=24); //Exact implementation for text input std::string toERoman(std::string val, unsigned int depth, size_t maxVal=24); //Exact implementation for "Vanilla" numerals std::string toSRoman(unsigned short val, size_t maxVal=6); //Exact implementation for lowercase-extended numerals std::string toLRoman(unsigned long long val); //Floating-point implementation for lowercase-extended numerals std::string toLRoman(long double val); //Text implementation for lowercase-extended numerals std::string toLRoman(std::string val); //Convert from roman numerals to integer unsigned long long fromERomanTI(std::string val, size_t maxVal=24); //Convert from roman numerals to floating-point type long double fromERomanTF(std::string val, size_t maxVal=24); //Convert from roman numerals to string (NYI) std::string fromERomanTS(std::string val, size_t maxVal); //Sanitize decimal string std::string sanitizeNumeric(std::string); //Sanitize roman numeral string std::string sanitizeNumeral(std::string); namespace Roman { //For text-based functions //Unsigned integer type in decimal string form class textNumeric { public: textNumeric(unsigned long long val) : m_val(reverseStr(toStr(val))) {;} textNumeric(long double val) : m_val(reverseStr(toStr(val))) {;} textNumeric(std::string val) : m_val(reverseStr(sanitizeNumeric(val))) {;} textNumeric(const textNumeric&); inline operator std::string() {return reverseStr(m_val);} //0 -> ones; 1 -> tens; etc char digit(size_t i) {return m_val[i];} unsigned long long toI(); long double toF(); //operator==() private: //Stored in little-endian form std::string m_val; }; class ConversionContext { public: enum class Numerals {Extended, Compatible, Lowercase, Standard, }; constexpr ConversionContext(Numerals type=Numerals::Extended) : m_context(type) {;} unsigned long long toI(std::string val) {return operator()(val).toI();} long double toF(std::string val) {return operator()(val).toF();} textNumeric toT(std::string val) {return operator()(val);} //"Canonicize" RN input std::string reduce(std::string val); std::string toR(unsigned long long val); std::string toR(long double val); std::string toR(textNumeric val); //Assume string is RN and textNumeric is decimal textNumeric operator()(std::string val); std::string operator()(textNumeric val) {return toR(val);} private: Numerals m_context; }; constexpr ConversionContext E(ConversionContext::Numerals::Extended), C(ConversionContext::Numerals::Compatible), L(ConversionContext::Numerals::Lowercase), S(ConversionContext::Numerals::Standard); } #endif //ROMAN_H_INCLUDED