Skip to content

Commit

Permalink
Fix Python to JavaScript int conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Dec 22, 2023
1 parent 622d918 commit 4304abe
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/type_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,13 @@ pub fn py_to_any(value: &PyAny) -> Any {
let v: bool = value.extract().unwrap();
Any::Bool(v)
} else if value.is_instance_of::<PyLong>() {
const MAX_JS_NUMBER: i64 = 2_i64.pow(53) - 1;
let v: i64 = value.extract().unwrap();
Any::BigInt(v)
if v > MAX_JS_NUMBER {
Any::BigInt(v)
} else {
Any::Number(v as f64)
}
} else if value.is_instance_of::<PyFloat>() {
let v: f64 = value.extract().unwrap();
Any::Number(v)
Expand Down

0 comments on commit 4304abe

Please sign in to comment.