Repository: nushell/nushell
File: crates/nu-command/src/math/round.rs (Rust)

Code before:
                        Value::test_int(120),
                        Value::test_int(-120),
                    ],
                    Span::test_data(),
                )),
            },
        ]
    }
}

fn operate(value: Value, head: Span, precision: Option<i64>) -> Value {
    // We treat int values as float values in order to avoid code repetition in the match closure
    let span = value.span();
    let value = if let Value::Int { val, .. } = value {
        Value::float(val as f64, span)
    } else {
        value
    };

    match value {
        Value::Float { val, .. } => {
            if !val.is_finite() {
                return Value::error(
                    ShellError::UnsupportedInput {
                        msg: "cannot round non-finite number".into(),
                        input: " ".into(),
                        msg_span: span,
                        input_span: span,
                    },
                    span,
                );
            }

            match precision {
                Some(precision_number) => Value::float(
                    (val * ((10_f64).powf(precision_number as f64))).round()
                        / (10_f64).powf(precision_number as f64),
                    span,
                ),
                None => Value::int(val.round() as i64, span),
            }
        }
        Value::Error { .. } => value,
        other => Value::error(
            ShellError::OnlySupportsThisInputType {
                exp_input_type: "numeric".into(),
                wrong_type: other.get_type().to_string(),
                dst_span: head,
                src_span: other.span(),
            },
            head,

Review comment (suggestion):
```suggestion
                        input: "value originates from here".into(),
```

Code after:
                        Value::test_int(120),
                        Value::test_int(-120),
                    ],
                    Span::test_data(),
                )),
            },
        ]
    }
}

fn operate(value: Value, head: Span, precision: Option<i64>) -> Value {
    // We treat int values as float values in order to avoid code repetition in the match closure
    let span = value.span();
    let value = if let Value::Int { val, .. } = value {
        Value::float(val as f64, span)
    } else {
        value
    };

    match value {
        Value::Float { val, .. } => {
            if !val.is_finite() {
                return Value::error(
                    ShellError::UnsupportedInput {
                        msg: "cannot round non-finite number".into(),
                        input: "value originates from here".into(),
                        msg_span: span,
                        input_span: span,
                    },
                    span,
                );
            }

            match precision {
                Some(precision_number) => Value::float(
                    (val * ((10_f64).powf(precision_number as f64))).round()
                        / (10_f64).powf(precision_number as f64),
                    span,
                ),
                None => Value::int(val.round() as i64, span),
            }
        }
        Value::Error { .. } => value,
        other => Value::error(
            ShellError::OnlySupportsThisInputType {
                exp_input_type: "numeric".into(),
                wrong_type: other.get_type().to_string(),
                dst_span: head,
                src_span: other.span(),
            },
            head,