add ability to do into int on floats using a radix (#6033)

This commit is contained in:
Darren Schroeder 2022-07-12 20:37:57 -05:00 committed by GitHub
parent c2f8f4bd9b
commit ad9449bf00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -169,7 +169,32 @@ pub fn action(input: &Value, span: Span, radix: u32, little_endian: bool) -> Val
}
Value::Filesize { val, .. } => Value::Int { val: *val, span },
Value::Float { val, .. } => Value::Int {
val: *val as i64,
val: {
if radix == 10 {
*val as i64
} else {
match convert_int(
&Value::Int {
val: *val as i64,
span,
},
span,
radix,
)
.as_i64()
{
Ok(v) => v,
_ => {
return Value::Error {
error: ShellError::UnsupportedInput(
"Could not convert float to integer".to_string(),
span,
),
}
}
}
}
},
span,
},
Value::String { val, .. } => {