add getformat (#3774)

This commit is contained in:
Miragecore
2022-06-12 15:38:32 +09:00
committed by GitHub
parent ce546f6183
commit fafd8434ac

View File

@@ -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()