http://www.perlmonks.org?node_id=11127707


in reply to Re: Comparing a value to a list of numbers
in thread Comparing a value to a list of numbers

Other monks have suggested a binary search solution, but did not provide an example.

Set::IntSpan uses a binary search.

  • Comment on Re^2: Comparing a value to a list of numbers

Replies are listed 'Best First'.
Re^3: Comparing a value to a list of numbers
by LanX (Saint) on Jan 31, 2021 at 20:06 UTC
      Interesting, so why is it restricted to Integers?

      Likely because that's simply its purpose, plus I imagine certain set operations would be problematic due to floating-point inaccuracies.

        > plus I imagine certain set operations would be problematic due to floating-point inaccuracies.

        I doubt this, rounding errors happen only after arithmetic operations

        as long as two floats are different, comparisons will show a strict order:

        DB<95> $one = 1-1e-16 DB<96> printf '%.17f', $one 0.99999999999999989 DB<97> p 1 > $one 1 DB<98> $one = 1-1e-16 DB<99> p $one 1 DB<100>

        FWIW 0.1e-1 and 1e-2 are the same float in my books.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery