Fix the precision of StandardComponents::types::Integer
Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
ca3b030fed
commit
88d0774d30
|
@ -106,8 +106,10 @@ namespace StandardComponents {
|
||||||
};
|
};
|
||||||
namespace types {
|
namespace types {
|
||||||
struct Integer: ParseComponent {
|
struct Integer: ParseComponent {
|
||||||
long double value;
|
typedef uint_fast8_t precision_type;
|
||||||
Integer(const string& value): value(stold(value)) {}
|
const long double value;
|
||||||
|
const precision_type precision;
|
||||||
|
Integer(const long double& value, const precision_type& precision): value(value), precision(precision) {}
|
||||||
};
|
};
|
||||||
struct String: ParseComponent {
|
struct String: ParseComponent {
|
||||||
const string content;
|
const string content;
|
||||||
|
|
|
@ -44,13 +44,16 @@ namespace Parser {
|
||||||
|
|
||||||
switch (current.toktype) {
|
switch (current.toktype) {
|
||||||
case NUMBER: {
|
case NUMBER: {
|
||||||
types::Integer Int = current.toktext;
|
long double v = stoul(current.toktext);
|
||||||
|
if (i > 0 && lexed[i - 1].toktype == HYPHEN) v = -v;
|
||||||
|
types::Integer::precision_type p = 0;
|
||||||
if (nextAre({DOT, NUMBER})) {
|
if (nextAre({DOT, NUMBER})) {
|
||||||
i += 2;
|
i += 2;
|
||||||
const string& right = lexed[i].toktext;
|
const string& right = lexed[i].toktext;
|
||||||
Int.value += stold(right) / powl(10, right.size());
|
p = min(static_cast<int>(right.size()), numeric_limits<long double>::digits10);
|
||||||
|
v += copysign(stold(right.substr(0, p)) / powl(10, p), v);
|
||||||
}
|
}
|
||||||
parseTree << Int;
|
parseTree << types::Integer(v, p);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STRING: parseTree << types::String(current.toktext.data()); break;
|
case STRING: parseTree << types::String(current.toktext.data()); break;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <typeindex>
|
#include <typeindex>
|
||||||
|
#include <limits>
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#include <cxxabi.h>
|
#include <cxxabi.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -133,7 +134,7 @@ public:
|
||||||
separate_transpileTree(parseComponent, ", ");
|
separate_transpileTree(parseComponent, ", ");
|
||||||
output << ')';
|
output << ')';
|
||||||
),
|
),
|
||||||
make_task(StandardComponents::types::Integer, output << parseComponent.value;)
|
make_task(StandardComponents::types::Integer, output << setprecision(parseComponent.precision) << fixed << parseComponent.value;)
|
||||||
}));
|
}));
|
||||||
return staticMap;
|
return staticMap;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue