Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've seen those "abs(fp_number)<some_tiny_value" in front of divisions, because people fear that the division will "blow up" in some way if a zero or sufficiently small number is passed to it.

    if (abs(q) >= 1e-6)
        rel_val = abs_val / q;
    else
        overflow_flag = true;
But it's quite pointless, as the semantics of floating point calculations give you the indication about overflow right in the division result, it will be marked as positive or negative infinity.

    rel_val = abs_val / q;
    if (isnan(rel_val) || !finite(rel_val) || ans(rel_val) > some_limit)
        overflow_flag = true;
(of course your FPU should be configured to not produce exceptions in the case of division by zero)


That still won't prevent a zero-ish noisy `q` from causing a totally messed-up `rel_val`.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: