MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / to_int

Function to_int

std/math/src/main/float.rs:212–221  ·  view source on GitHub ↗

`floor`/`ceil`/`trunc` return an int; reject non-finite or out-of-i128 values like CPython int conversion.

(x: f64)

Source from the content-addressed store, hash-verified

210
211// `floor`/`ceil`/`trunc` return an int; reject non-finite or out-of-i128 values like CPython int conversion.
212fn to_int(x: f64) -> Result<i128> {
213 if !x.is_finite() {
214 return Err(Error::Value(String::from("cannot convert float NaN or infinity to integer")));
215 }
216 // Values at or beyond 2^127 saturate on cast; reject so the result is never silently clamped.
217 if x.abs() >= 170141183460469231731687303715884105728.0 {
218 return Err(Error::Value(String::from("int too large to convert")));
219 }
220 Ok(x as i128)
221}
222
223#[plugin_fn]
224fn floor(x: f64) -> Result<i128> { to_int(libm::floor(x)) }

Callers 3

floorFunction · 0.85
ceilFunction · 0.85
truncFunction · 0.85

Calls 1

ValueEnum · 0.50

Tested by

no test coverage detected