It's easy enough to write open-interval and half-open interval tests, either using s/and with s/double-in, or just by defining a function from scratch. However, if Clojure is going to provide double-in, why make us do that? Why not have a common interface that adds two optional keywords to specify whether the bounds are open or closed? This is not a request to add the kitchen sink; it's a natural extension to deal with a common use case. The alternative would be to define three additional versions of double-in, and people will do that on their own, or define a new more flexible double-in if there's no built-in spec function that does it.
I'd suggest a new keyword with one of the following forms:
:min-open, :min-greater, :min-greater-than, :min-strict, :greater-min, :strict-min, etc.,
and a corresponding keyword for the max side.
Default values should be false, for compatibility with the current definition of double-in.
I
can add a JIRA ticket if this seems worthwhile. I wanted to see what
people think first. (I'd have to sign up with the JIRA system, but I
assume I'm allowed to do that.) My apologies if there's already a JIRA ticket for this. I don't seem to be able to find anything on double-in, but I'm not sure I understand the search syntax.
You can file a jira if you like, I'm not sure Rich's thoughts on this.
Also, keep in mind that you can also compose preds and get this with slightly more effort now:(s/and (s/double-in :min 0.0 :max 1.0) #(not= 0.0 %))
Thanks.
You can already get open intervals by just omitting :min or :max.
With a little help from Java, you can make equivalent open intervals for the desired bounds. For example,
Also, you can use java.lang.Math/nextUp and nextAfter to get adjacent doubles for your bounds.
(java.lang.Math/nextUp 1.1)
;=> 1.1000000000000003
(java.lang.Math/nextAfter 1.1 Double/NEGATIVE_INFINITY)
;=> 1.0999999999999999
There are a few tricky situations around the zeroes and infinities so you should read the doc on nextAfter, especially if you’re dealing with extreme doubles.