Fix float.__repr__() method
@@ -416,11 +416,23 @@ impl PyFloat {
#[pymethod(name = "__repr__")]
fn repr(&self, vm: &VirtualMachine) -> String {
+ let value = format!("{:e}", self.value);
+ if let Some(position) = value.find('e') {
+ let significand = &value[..position];
+ let exponent = &value[position + 1..];
+ let exponent = exponent.parse::<i32>().unwrap();
+ if exponent < 16 && exponent > -5 {
if self.is_integer(vm) {
format!("{:.1?}", self.value)
} else {
self.value.to_string()
}
+ } else {
+ format!("{}e{:+#03}", significand, exponent)
+ }
+ } else {
+ self.value.to_string()
+ }
}
#[pymethod(name = "__truediv__")]
