add getformat
@@ -204,6 +204,24 @@ impl PyFloat {
}
}
+ #[pymethod(magic)]
+ fn getformat(&self, spec: PyStrRef, vm: &VirtualMachine) -> PyResult<String> {
+ 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()
