Wrong result of nalgebra::base::Matrix::min() and ::max()
- Dominant language
- Rust
- Stars
- 4.8k
- Forks
- 565
- PR merge metrics
- No merged PRs in 30d
Description
The methods `nalgebra::base::Matrix::min()` and `nalgebra::base::Matrix::max()` are documented as
> Returns the component with the smallest value.
and
> Returns the component with the largest value.
However, `A.min()` actually returns `N::zero().min(A[..])` (if this was a valid expression) and `A.max()` returns `N::zero().max(A[..])`. For example, this corresponds to
- `na::Vector3::new(-1.0, -2.0, -3.0).max()` returning 0.0
- `na::Vector3::new(1.0, 2.0, 3.0).min()` returning 0.0
This is due to the fact that both rely on [`xcmp`](https://github.com/rustsim/nalgebra/blob/0384268bd4c757b5b0125d63bb0599695b961c48/src/base/ops.rs#L871) which always initializes the comparison value with `N::zero()` instead of e.g. the first value of the matrix. This is either a bug in the code or in the documentation.
Currently I have to use `A[A.imin()]` instead of `A.min()`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.