Converts the double `d` to an integer and fails if the conversion is not possible.
(d: f64)
| 35 | |
| 36 | /// Converts the double `d` to an integer and fails if the conversion is not possible. |
| 37 | pub 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. |
| 47 | pub enum AngleMode { |
no outgoing calls
no test coverage detected