Skip to content
  • Damien George's avatar
    py/modbuiltins: For round() builtin use nearbyint instead of round. · 125eae1b
    Damien George authored
    The C nearbyint function has exactly the semantics that Python's round()
    requires, whereas C's round() requires extra steps to handle rounding of
    numbers half way between integers.  So using nearbyint reduces code size
    and potentially eliminates any source of errors in the handling of half-way
    numbers.
    
    Also, bare-metal implementations of nearbyint can be more efficient than
    round, so further code size is saved (and efficiency improved).
    
    nearbyint is provided in the C99 standard so it should be available on all
    supported platforms.
    125eae1b