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