Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Comparing a value to a list of numbers

by haukex (Bishop)
on Jan 31, 2021 at 09:09 UTC ( #11127707=note: print w/replies, xml ) Need Help??


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 (Cardinal) 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11127707]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2021-06-13 12:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (55 votes). Check out past polls.

    Notices?