The problem is that every floating point in a certain interval [low, -0.0] will print "-0.00".
So you should find low:
- so print (predecessor (low)) => "-0.01"
- so print (low) => "-0.00"
Then you can write something like (nano-separation ...)
double filter(double x) { double low = ... ; return (x < low) ? x : ((x > 0.0) ? x : 0.0) ; }
If you have correctly rounded printf and control your arithmetic strictly IEEE754, corresponding to the corresponding compiler flags, the exact value low is the closest double - 1/200, greater than -1/200 (I write 1/200, and not -0.005, therefore what I'm talking about decimal value, not double)
What we have with correctly rounded sscanf ("- 0.005", "% lf", d): a double result is less than -1/200. I checked this with exact arithmetic, for example in Pharo Smalltalk:
[-0.005 < (-1/200) and: [-0.005 successor > (-1/200)]] assert.
His successor is greater than -1/200 (required, higher verification is just protection).
So you can write (note the <= low):
double filter(double x) { double low = 0.005 ; return (x <= low) ? x : ((x > 0.0) ? x : 0.0) ; }
source share