I need to implement experience filter like this
- 0 to 2 years
- 2+ to 4 years
How to express it in swift range?
Problem is I can't express more than 2 to 4 years. While I can do less than upper bounds. e.g. like this
let underTen = 0.0..<10.0
I need something like this (greater than lower bound)
let uptoTwo = 0.0...2.0
let twoPlus = 2.0>..4.0 // compiler error
Currently I am doing
let twoPlus = 2.1...4.0
But this is not perfect.
nextUpfrom theFloatingPointprotocolYou can make use of the
nextUpproperty ofDouble, as blueprinted in theFloatingPointprotocol to whichDoubleconformsI.e.:
The property
ulp, also blueprinted in theFloatingPointprotocol, has been mentioned in the comments to your question. For most numbers, this is the difference betweenselfand the next greater representable number:nextUpdoes, in essence, return the value ofselfwith the addition ofulp. So for your example above, the following is equivalent (whereas, imo,nextupshould be preferred in this use case).You might also want to consider replacing the lower bound literal in
twoPluswith theupperBoundproperty of the precedinguptoTworange: