Minor refactor.

This commit is contained in:
Stephen Chung
2022-01-03 23:16:47 +08:00
parent d60f14ec27
commit 1d1e473ac4
8 changed files with 34 additions and 47 deletions

View File

@@ -18,13 +18,6 @@ use rust_decimal::Decimal;
#[cfg(feature = "decimal")]
use super::arithmetic::make_err;
#[allow(dead_code)]
#[cfg(feature = "only_i32")]
pub const MAX_INT: INT = i32::MAX;
#[allow(dead_code)]
#[cfg(not(feature = "only_i32"))]
pub const MAX_INT: INT = i64::MAX;
macro_rules! gen_conversion_as_functions {
($root:ident => $func_name:ident ( $($arg_type:ident),+ ) -> $result_type:ty) => {
pub mod $root { $(pub mod $arg_type {
@@ -264,7 +257,7 @@ mod float_functions {
}
#[rhai_fn(name = "to_int", return_raw)]
pub fn f32_to_int(x: f32) -> RhaiResultOf<INT> {
if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f32) {
if cfg!(not(feature = "unchecked")) && x > (INT::MAX as f32) {
Err(
ERR::ErrorArithmetic(format!("Integer overflow: to_int({})", x), Position::NONE)
.into(),
@@ -275,7 +268,7 @@ mod float_functions {
}
#[rhai_fn(name = "to_int", return_raw)]
pub fn f64_to_int(x: f64) -> RhaiResultOf<INT> {
if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f64) {
if cfg!(not(feature = "unchecked")) && x > (INT::MAX as f64) {
Err(
ERR::ErrorArithmetic(format!("Integer overflow: to_int({})", x), Position::NONE)
.into(),