mirror of https://github.com/exaloop/codon.git
Update float parsing
parent
9769e20d1a
commit
54f0e209c1
|
@ -68,4 +68,3 @@ jit/codon/version.py
|
||||||
temp/
|
temp/
|
||||||
playground/
|
playground/
|
||||||
scratch*.*
|
scratch*.*
|
||||||
/_*
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "expr.h"
|
#include "expr.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -149,10 +151,11 @@ FloatExpr::FloatExpr(double floatValue)
|
||||||
this->floatValue = std::make_unique<double>(floatValue);
|
this->floatValue = std::make_unique<double>(floatValue);
|
||||||
}
|
}
|
||||||
FloatExpr::FloatExpr(const std::string &value, std::string suffix)
|
FloatExpr::FloatExpr(const std::string &value, std::string suffix)
|
||||||
: Expr(), suffix(std::move(suffix)) {
|
: Expr(), value(), suffix(std::move(suffix)) {
|
||||||
for (auto c : value)
|
this->value.reserve(value.size());
|
||||||
if (c != '_')
|
std::copy_if(value.begin(), value.end(), std::back_inserter(this->value),
|
||||||
this->value += c;
|
[](char c) { return c != '_'; });
|
||||||
|
|
||||||
double result;
|
double result;
|
||||||
auto r = fast_float::from_chars(this->value.data(),
|
auto r = fast_float::from_chars(this->value.data(),
|
||||||
this->value.data() + this->value.size(), result);
|
this->value.data() + this->value.size(), result);
|
||||||
|
|
Loading…
Reference in New Issue