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

@@ -1,6 +1,6 @@
#![cfg(not(feature = "no_std"))]
use super::{arithmetic::make_err as make_arithmetic_err, math_basic::MAX_INT};
use super::arithmetic::make_err as make_arithmetic_err;
use crate::plugin::*;
use crate::{def_package, Dynamic, EvalAltResult, RhaiResult, RhaiResultOf, INT};
@@ -42,7 +42,7 @@ mod time_functions {
{
let seconds = timestamp.elapsed().as_secs();
if cfg!(not(feature = "unchecked")) && seconds > (MAX_INT as u64) {
if cfg!(not(feature = "unchecked")) && seconds > (INT::MAX as u64) {
Err(make_arithmetic_err(format!(
"Integer overflow for timestamp.elapsed: {}",
seconds
@@ -69,7 +69,7 @@ mod time_functions {
if timestamp2 > timestamp1 {
let seconds = (timestamp2 - timestamp1).as_secs();
if cfg!(not(feature = "unchecked")) && seconds > (MAX_INT as u64) {
if cfg!(not(feature = "unchecked")) && seconds > (INT::MAX as u64) {
Err(make_arithmetic_err(format!(
"Integer overflow for timestamp duration: -{}",
seconds
@@ -80,7 +80,7 @@ mod time_functions {
} else {
let seconds = (timestamp1 - timestamp2).as_secs();
if cfg!(not(feature = "unchecked")) && seconds > (MAX_INT as u64) {
if cfg!(not(feature = "unchecked")) && seconds > (INT::MAX as u64) {
Err(make_arithmetic_err(format!(
"Integer overflow for timestamp duration: {}",
seconds
@@ -97,7 +97,7 @@ mod time_functions {
if seconds < 0.0 {
subtract_impl(timestamp, -seconds)
} else if cfg!(not(feature = "unchecked")) {
if seconds > (MAX_INT as FLOAT) {
if seconds > (INT::MAX as FLOAT) {
Err(make_arithmetic_err(format!(
"Integer overflow for timestamp add: {}",
seconds
@@ -120,7 +120,7 @@ mod time_functions {
if seconds < 0.0 {
add_impl(timestamp, -seconds)
} else if cfg!(not(feature = "unchecked")) {
if seconds > (MAX_INT as FLOAT) {
if seconds > (INT::MAX as FLOAT) {
Err(make_arithmetic_err(format!(
"Integer overflow for timestamp add: {}",
seconds