mirror of
https://github.com/nushell/nushell
synced 2024-12-26 04:53:09 +00:00
Suggest using float on Value::Int
overflow (#7253)
# Description Suggest that floats support a larger range of values but warn about the loss in precision. ![image](https://user-images.githubusercontent.com/15833959/204114339-c987cd47-f035-4c01-853f-e9a00441bf49.png) (Doesn't apply to the types with associated units) # Tests + Formatting (-)
This commit is contained in:
parent
bdc4bf97a7
commit
fa97e819eb
2 changed files with 13 additions and 2 deletions
|
@ -34,8 +34,8 @@ pub enum ShellError {
|
||||||
/// Check the inputs to the operation and add guards for their sizes.
|
/// Check the inputs to the operation and add guards for their sizes.
|
||||||
/// Integers are generally of size i64, floats are generally f64.
|
/// Integers are generally of size i64, floats are generally f64.
|
||||||
#[error("Operator overflow.")]
|
#[error("Operator overflow.")]
|
||||||
#[diagnostic(code(nu::shell::operator_overflow), url(docsrs))]
|
#[diagnostic(code(nu::shell::operator_overflow), url(docsrs), help("{2}"))]
|
||||||
OperatorOverflow(String, #[label = "{0}"] Span),
|
OperatorOverflow(String, #[label = "{0}"] Span, String),
|
||||||
|
|
||||||
/// The pipelined input into a command was not of the expected type. For example, it might
|
/// The pipelined input into a command was not of the expected type. For example, it might
|
||||||
/// expect a string input, but received a table instead.
|
/// expect a string input, but received a table instead.
|
||||||
|
|
|
@ -1762,6 +1762,7 @@ impl Value {
|
||||||
Err(ShellError::OperatorOverflow(
|
Err(ShellError::OperatorOverflow(
|
||||||
"add operation overflowed".into(),
|
"add operation overflowed".into(),
|
||||||
span,
|
span,
|
||||||
|
"Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into()
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1787,6 +1788,7 @@ impl Value {
|
||||||
_ => Err(ShellError::OperatorOverflow(
|
_ => Err(ShellError::OperatorOverflow(
|
||||||
"addition operation overflowed".into(),
|
"addition operation overflowed".into(),
|
||||||
span,
|
span,
|
||||||
|
"".into(),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1797,6 +1799,7 @@ impl Value {
|
||||||
Err(ShellError::OperatorOverflow(
|
Err(ShellError::OperatorOverflow(
|
||||||
"add operation overflowed".into(),
|
"add operation overflowed".into(),
|
||||||
span,
|
span,
|
||||||
|
"".into(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1807,6 +1810,7 @@ impl Value {
|
||||||
Err(ShellError::OperatorOverflow(
|
Err(ShellError::OperatorOverflow(
|
||||||
"add operation overflowed".into(),
|
"add operation overflowed".into(),
|
||||||
span,
|
span,
|
||||||
|
"".into(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1862,6 +1866,7 @@ impl Value {
|
||||||
Err(ShellError::OperatorOverflow(
|
Err(ShellError::OperatorOverflow(
|
||||||
"subtraction operation overflowed".into(),
|
"subtraction operation overflowed".into(),
|
||||||
span,
|
span,
|
||||||
|
"Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into()
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1885,6 +1890,7 @@ impl Value {
|
||||||
None => Err(ShellError::OperatorOverflow(
|
None => Err(ShellError::OperatorOverflow(
|
||||||
"subtraction operation overflowed".into(),
|
"subtraction operation overflowed".into(),
|
||||||
span,
|
span,
|
||||||
|
"".into(),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1894,6 +1900,7 @@ impl Value {
|
||||||
_ => Err(ShellError::OperatorOverflow(
|
_ => Err(ShellError::OperatorOverflow(
|
||||||
"subtraction operation overflowed".into(),
|
"subtraction operation overflowed".into(),
|
||||||
span,
|
span,
|
||||||
|
"".into(),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1904,6 +1911,7 @@ impl Value {
|
||||||
Err(ShellError::OperatorOverflow(
|
Err(ShellError::OperatorOverflow(
|
||||||
"subtraction operation overflowed".into(),
|
"subtraction operation overflowed".into(),
|
||||||
span,
|
span,
|
||||||
|
"".into(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1914,6 +1922,7 @@ impl Value {
|
||||||
Err(ShellError::OperatorOverflow(
|
Err(ShellError::OperatorOverflow(
|
||||||
"add operation overflowed".into(),
|
"add operation overflowed".into(),
|
||||||
span,
|
span,
|
||||||
|
"".into(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1941,6 +1950,7 @@ impl Value {
|
||||||
Err(ShellError::OperatorOverflow(
|
Err(ShellError::OperatorOverflow(
|
||||||
"multiply operation overflowed".into(),
|
"multiply operation overflowed".into(),
|
||||||
span,
|
span,
|
||||||
|
"Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into()
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2893,6 +2903,7 @@ impl Value {
|
||||||
Err(ShellError::OperatorOverflow(
|
Err(ShellError::OperatorOverflow(
|
||||||
"pow operation overflowed".into(),
|
"pow operation overflowed".into(),
|
||||||
span,
|
span,
|
||||||
|
"Consider using floating point values for increased range by promoting operand with 'into decimal'. Note: float has reduced precision!".into()
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue