MCPcopy Index your code
hub / github.com/endbasic/endbasic / double_to_integer

Function double_to_integer

std/src/numerics.rs:37–44  ·  view source on GitHub ↗

Converts the double `d` to an integer and fails if the conversion is not possible.

(d: f64)

Source from the content-addressed store, hash-verified

35
36/// Converts the double `d` to an integer and fails if the conversion is not possible.
37pub fn double_to_integer(d: f64) -> Result<i32, String> {
38 let d = d.round();
39 if d.is_finite() && d >= (i32::MIN as f64) && (d <= i32::MAX as f64) {
40 Ok(d as i32)
41 } else {
42 Err(format!("Cannot cast {} to integer due to overflow", d))
43 }
44}
45
46/// Indicates the calculation mode for trigonometric functions.
47pub enum AngleMode {

Callers 2

assign_datumMethod · 0.85
execMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected