mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
add getformat (#3774)
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user