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 {
|
||||
struct Integer: ParseComponent {
|
||||
long double value;
|
||||
Integer(const string& value): value(stold(value)) {}
|
||||
typedef uint_fast8_t precision_type;
|
||||
const long double value;
|
||||
const precision_type precision;
|
||||
Integer(const long double& value, const precision_type& precision): value(value), precision(precision) {}
|
||||
};
|
||||
struct String: ParseComponent {
|
||||
const string content;
|
||||
|
|
|
@ -44,13 +44,16 @@ namespace Parser {
|
|||
|
||||
switch (current.toktype) {
|
||||
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})) {
|
||||
i += 2;
|
||||
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;
|
||||
}
|
||||
case STRING: parseTree << types::String(current.toktext.data()); break;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
#include <typeindex>
|
||||
#include <limits>
|
||||
#ifdef __GNUC__
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
@ -133,7 +134,7 @@ public:
|
|||
separate_transpileTree(parseComponent, ", ");
|
||||
output << ')';
|
||||
),
|
||||
make_task(StandardComponents::types::Integer, output << parseComponent.value;)
|
||||
make_task(StandardComponents::types::Integer, output << setprecision(parseComponent.precision) << fixed << parseComponent.value;)
|
||||
}));
|
||||
return staticMap;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue