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

    # Step 3: Preemptively check for catastrophic magnitude differences
    if abs(a) > sys.float_info.max / 2:
        logging.warning("Value of a might cause overflow. Returning infinity just to be sure")
        return math.copysign (float('inf'), a)
    if abs(b) < sys.float_info.epsilon:
        logging.warning("Value of b dangerously close to zero. Returning NaN defensively.")
        return math.nan

Does the above code make any sense? I've not worked with this sort of stuff before, but it seems entirely unreasonable to me to check them individually. E.g. if 1 < b < a, then it seems insane to me to return float('inf') for a large but finite a.


It also uses float epsilon and I don't think I have ever seen code where using it was appropriate.


It’s parody


Ignoring the sign of b for big a can't be right.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: