mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-24 13:30:18 +00:00
...
This commit is contained in:
parent
5f6c7f3f23
commit
e8b1449979
@ -183,6 +183,16 @@ struct SStream{
|
||||
|
||||
template<typename T>
|
||||
SStream& operator<<(T val){
|
||||
if constexpr(std::is_floating_point_v<T>){
|
||||
if(std::isinf(val) || std::isnan(val)){
|
||||
return (*this) << std::to_string(val);
|
||||
}
|
||||
std::stringstream ss; // float
|
||||
ss << std::setprecision(std::numeric_limits<f64>::max_digits10-1) << val;
|
||||
std::string s = ss.str();
|
||||
if(std::all_of(s.begin()+1, s.end(), isdigit)) s += ".0";
|
||||
return (*this) << s;
|
||||
}
|
||||
(*this) << std::to_string(val);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -541,12 +541,9 @@ void init_builtins(VM* _vm) {
|
||||
|
||||
_vm->bind__repr__(_vm->tp_float, [](VM* vm, PyObject* obj) {
|
||||
f64 val = _CAST(f64, obj);
|
||||
if(std::isinf(val) || std::isnan(val)) return VAR(std::to_string(val));
|
||||
std::stringstream ss; // float
|
||||
ss << std::setprecision(std::numeric_limits<f64>::max_digits10-1) << val;
|
||||
std::string s = ss.str();
|
||||
if(std::all_of(s.begin()+1, s.end(), isdigit)) s += ".0";
|
||||
return VAR(s);
|
||||
SStream ss;
|
||||
ss << val;
|
||||
return VAR(ss.str());
|
||||
});
|
||||
|
||||
/************ str ************/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user