Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix array with float
  • Loading branch information
qingshi163 committed Oct 27, 2020
commit eaf4bad2d1ec8cea39c1089b8db50a8b2a66d906
9 changes: 3 additions & 6 deletions vm/src/stdlib/array.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::builtins::bytes::PyBytesRef;
use crate::builtins::float::try_float;
use crate::builtins::float::IntoPyFloat;
use crate::builtins::list::PyList;
use crate::builtins::memory::{Buffer, BufferOptions, ResizeGuard};
use crate::builtins::pystr::PyStrRef;
Expand Down Expand Up @@ -449,14 +449,11 @@ fn f64_swap_bytes(x: f64) -> f64 {
}

fn f32_try_into_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<f32> {
try_float(&obj, vm)?
.map(|x| x as f32)
.ok_or_else(|| vm.new_type_error(format!("must be real number, not {}", obj.class().name)))
IntoPyFloat::try_from_object(vm, obj).map(|x| x.to_f64() as f32)
}

fn f64_try_into_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<f64> {
try_float(&obj, vm)?
.ok_or_else(|| vm.new_type_error(format!("must be real number, not {}", obj.class().name)))
IntoPyFloat::try_from_object(vm, obj).map(|x| x.to_f64())
}

#[pyclass(module = "array", name = "array")]
Expand Down