Remove lossy casting in logspace

Currently `logspace` does a lossy cast from `F::Int` to `usize`. This
could be problematic in the rare cases that this is called with a step
count exceeding what is representable in `usize`.

Resolve this by instead adding bounds so the float's integer type itself
can be iterated.
This commit is contained in:
Trevor Gross
2024-12-30 05:55:41 +00:00
committed by Trevor Gross
parent e8c501861a
commit cf58a7ce90
2 changed files with 10 additions and 3 deletions

View File

@@ -1,5 +1,7 @@
//! A generator that produces logarithmically spaced values within domain bounds.
use std::ops::RangeInclusive;
use libm::support::{IntTy, MinInt};
use crate::domain::HasDomain;
@@ -34,6 +36,7 @@ pub fn get_test_cases<Op>(_ctx: &CheckCtx) -> impl Iterator<Item = (Op::FTy,)>
where
Op: MathOp + HasDomain<Op::FTy>,
IntTy<Op::FTy>: TryFrom<usize>,
RangeInclusive<IntTy<Op::FTy>>: Iterator,
{
let domain = Op::DOMAIN;
let start = domain.range_start();