@@ -3306,16 +3306,16 @@ inline RVec<Ret_t> Linspace(T start, T end, unsigned long long n = 128, const bo
3306
3306
}
3307
3307
3308
3308
long double step = std::is_floating_point_v<Ret_t> ?
3309
- (static_cast <Ret_t>( end) - static_cast <Ret_t>( start)) / static_cast <Ret_t >(n - endpoint) :
3310
- static_cast <long double >(end - start) / (n - endpoint);
3309
+ (end - start) / static_cast <long double >(n - endpoint) :
3310
+ (end >= start ? static_cast <long double >(end - start) / (n - endpoint) : ( static_cast < long double >(end) - start) / (n - endpoint) );
3311
3311
3312
3312
RVec<Ret_t> temp (n);
3313
- temp[0 ] = static_cast <Ret_t>(start);
3313
+ temp[0 ] = std::is_floating_point_v<Ret_t> ? static_cast <Ret_t>(start) : std::floor (start);
3314
3314
if (std::is_floating_point_v<Ret_t>)
3315
3315
{
3316
3316
for (unsigned long long i = 1 ; i < n; i++)
3317
3317
{
3318
- temp[i] = static_cast <Ret_t>(start) + static_cast <Ret_t>(i) * step;
3318
+ temp[i] = static_cast <Ret_t>(start + i * step) ;
3319
3319
}
3320
3320
}
3321
3321
else
@@ -3397,25 +3397,27 @@ inline RVec<Ret_t> Logspace(T start, T end, unsigned long long n = 128, const bo
3397
3397
Ret_t base_c = static_cast <Ret_t>(base);
3398
3398
3399
3399
long double step = std::is_floating_point_v<Ret_t> ?
3400
- (static_cast <Ret_t>(end_c - start_c) / static_cast <Ret_t>(n - endpoint)) :
3401
- static_cast <long double >(end - start) / (n - endpoint);
3402
-
3403
- temp[0 ] = static_cast <Ret_t>(std::pow (base_c, start_c));
3400
+ (end_c - start_c) / static_cast <long double >(n - endpoint) :
3401
+ (end >= start ? static_cast <long double >(end - start) / (n - endpoint) : (static_cast <long double >(end) - start) / (n - endpoint));
3402
+
3403
+ temp[0 ] = std::is_floating_point_v<Ret_t> ?
3404
+ static_cast <Ret_t>(std::pow (base_c, start_c)) :
3405
+ std::floor (std::pow (base_c, start_c));
3404
3406
3405
3407
if (std::is_floating_point_v<Ret_t>)
3406
3408
{
3407
3409
for (unsigned long long i = 1 ; i < n; i++)
3408
3410
{
3409
3411
Ret_t exponent = start_c + i * step;
3410
- temp[i] = static_cast <Ret_t>( std::pow (base_c, exponent) );
3412
+ temp[i] = std::pow (base_c, exponent);
3411
3413
}
3412
3414
}
3413
3415
else
3414
3416
{
3415
3417
for (unsigned long long i = 1 ; i < n; i++)
3416
3418
{
3417
3419
Ret_t exponent = start_c + i * step;
3418
- temp[i] = static_cast <Ret_t>( std::floor (std::pow (base_c, exponent) ));
3420
+ temp[i] = std::floor (std::pow (base_c, exponent));
3419
3421
}
3420
3422
}
3421
3423
@@ -3480,7 +3482,7 @@ inline RVec<Ret_t> Logspace(T start, T end, unsigned long long n = 128, const bo
3480
3482
template <typename T = double , typename Ret_t = std::conditional_t <std::is_floating_point_v<T>, T, double >>
3481
3483
inline RVec<Ret_t> Arange (T start, T end, T step)
3482
3484
{
3483
- unsigned long long n = std::ceil (static_cast <Ret_t>(end-start)/static_cast <Ret_t >(step)); // Ensure floating-point division.
3485
+ unsigned long long n = std::ceil (static_cast <Ret_t>(end-start)/static_cast <long double >(step)); // Ensure floating-point division.
3484
3486
3485
3487
if (!n || (n > std::numeric_limits<long long >::max ())) // Check for invalid or absurd n.
3486
3488
{
@@ -3489,11 +3491,9 @@ inline RVec<Ret_t> Arange(T start, T end, T step)
3489
3491
3490
3492
RVec<Ret_t> temp (n);
3491
3493
3492
- Ret_t start_c = static_cast <Ret_t>(start);
3493
-
3494
- long double step_c = std::is_floating_point_v<Ret_t> ?
3495
- static_cast <Ret_t>(step) :
3496
- static_cast <long double >(step);
3494
+ Ret_t start_c = std::is_floating_point_v<Ret_t> ? static_cast <Ret_t>(start) : std::floor (start);
3495
+
3496
+ long double step_c = step;
3497
3497
3498
3498
temp[0 ] = start_c;
3499
3499
if (std::is_floating_point_v<Ret_t>)
0 commit comments