On Fri, Jan 23, 2015 at 6:35 PM, Andrew Barnert <abarnert@yahoo.com> wrote:
Of course they can underflow. But I don't think that's a practical problem except in very rare cases. It means you're explicitly asking for better than +/- 2**min_exp, so it shouldn't be surprising that nothing but an exact match qualifies.

Take a concrete example: with a tol of
1e-5, it's only going to underflow if expected is around 1e-320 or below. But since the next smaller and larger numbers (9.95e-321 and 1.0005e-320) aren't within 1e-5, the test gives the right answer despite underflowing.

I'd have to think about it a bit to make sure there's no pathological case that doesn't work out that way--but really, if you're checking subnormal numbers for closeness with a general-purpose function, or checking for relative closeness pushing the bounds of 1 ulp without thinking about what that means, I suspect you're already doing something wrong at a much higher level.

So, just special-casing 0 should be sufficient.

cool, this may be fine then. And makes a lot of sense.

Maybe the answer there is to have an is_close_to_0 function, instead of a parameter that's only useful if expected is 0? But then you might have, say, a comprehension where some of the expected values are 0 and some aren't, so maybe not...

exactly -- maybe it's because I'm so used to numpy, but expect that folks would want to call this in a comprehension or something where you've got a wide range of numbers, but want to use the same function and parameters, and don't want it to blow up at zero.

I'll try adding this tomorrow, and see how it works out. with some tests, etc.

-Chris

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov