Fix default format(float) result when the number is too big
Before this change, format(1e16) returns '10000000000000000.0' in RustPython while CPython 3.7 returns '1e+16'.
After this change, format(1e16) returns '1e+16' in RustPython too.
use crate::builtins::pystr;
+use crate::common::float_ops;
use crate::exceptions::{IntoPyException, PyBaseExceptionRef};
use crate::function::FuncArgs;
use crate::pyobject::{ItemProtocol, PyObjectRef, PyResult, TypeProtocol};
@@ -405,7 +406,7 @@ impl FormatSpec {
magnitude if magnitude.is_infinite() => Ok("inf".to_owned()),
// Using the Debug format here to prevent the automatic conversion of floats
// ending in .0 to their integer representation (e.g., 1.0 -> 1)
- _ => Ok(format!("{:?}", magnitude)),
+ _ => Ok(float_ops::to_string(magnitude)),
}
}
};
