Kumar Ujjawal fc813af4c8
Better error handling for negative integer exponents in ** operator (#15882)
**Title**: Better error handling for negative integer exponents in `**`
operator

---

### Bug Fix

This PR addresses an issue where attempting to raise an integer to a
negative power (e.g. `10 ** -1`) incorrectly triggered an
`OperatorOverflow` error. This behavior was misleading since the
overflow isn't actually the root problem — it's the unsupported
operation of raising integers to negative powers.

---

###  Fix Summary

* Updated `Value::pow` to:

  * Check for negative exponents when both operands are integers.
* Return a `ShellError::IncorrectValue` with a helpful message guiding
users to use floating point values instead.

#### Example:

```bash
> 10 ** -1
Error: nu:🐚:incorrect_value

  × Incorrect value.
   ╝─[entry #2:1:4]
 1 │ 10 ** -1
   ·    ─┬┬
   ·     │╰── encountered here
   ·     ╰── Negative exponent for integer power is unsupported; use floats instead.
```

---

### Testing

Manual testing:

* `10 ** -1` → now returns a clear and appropriate `IncorrectValue`
error.
* `10.0 ** -1`, `10 ** -1.0`, etc. continue to work as expected.

---

### Related

Fixes #15860



---------

Co-authored-by: Kumar Ujjawal <kumar.ujjawal@greenpista.com>
2025-06-04 10:06:41 +02:00
..
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00