in reply to Re^6: Comparing a value to a list of numbers (updated)
in thread Comparing a value to a list of numbers

Does the lower range end at 0.9, 0.99, 0.999, 0.9999, ...?

Sounds like you would perhaps be looking for a "nextbelow" implementation (and "nextabove" at the other end of the range).
It's not implemented in core perl, and I'm unaware of any such implementations in any of the core modules, too.
My own Math::MPFR provides them, and I can also see them in Zefram's pure perl Data::Float module as (nextup/nextdown/nextafter).
use strict; use warnings; use Config; use Data::Float; # Set $prec to the required value # for "%.*e" formatting for the # nvtype that we have. my $prec = 35; # __float128 # Amend $prec's value as needed if( $Config{nvsize} == 8 ) { $prec = 16 } elsif( $Config{nvtype} eq 'long double' ) { $prec = 20 unless( $Config{longdblkind} == 1 || $Config{longdblkind} == 2 ); } my $val = 1.0; my $down = Data::Float::nextdown( $val ); my $up = Data::Float::nextup ( $val ); printf "%.${prec}e %a\n", $down, $down; printf "%.${prec}e %a\n", $val, $val; printf "%.${prec}e %a\n", $up, $up;
If nvtype is double, it outputs:
9.9999999999999989e-01 0x1.fffffffffffffp-1 1.0000000000000000e+00 0x1p+0 1.0000000000000002e+00 0x1.0000000000001p+0
Cheers,
Rob

Replies are listed 'Best First'.
Re^8: Comparing a value to a list of numbers
by haukex (Archbishop) on Feb 03, 2021 at 10:48 UTC
    My own Math::MPFR provides them, and I can also see them in Zefram's pure perl Data::Float module as (nextup/nextdown/nextafter).

    Very useful to know, thank you!