diff --git a/vm/src/builtins/float.rs b/vm/src/builtins/float.rs index d83439b5e..1aefdf937 100644 --- a/vm/src/builtins/float.rs +++ b/vm/src/builtins/float.rs @@ -204,6 +204,24 @@ impl PyFloat { } } + #[pymethod(magic)] + fn getformat(&self, spec: PyStrRef, vm: &VirtualMachine) -> PyResult { + if !matches!(spec.as_str(), "double" | "float") { + return Err(vm.new_value_error( + "__getformat__() argument 1 must be 'double' or 'float'".to_owned(), + )); + } + + const BIG_ENDIAN: bool = cfg!(target_endian = "big"); + + Ok(if BIG_ENDIAN { + "IEEE, big-endian" + } else { + "IEEE, little-endian" + } + .to_owned()) + } + #[pymethod(magic)] fn abs(&self) -> f64 { self.value.abs()