def format_duration(secs):
    """
    >>> format_duration(0)
    '00:00'
    >>> format_duration(1)
    '00:01'
    >>> format_duration(100)
    '01:40'
    >>> format_duration(10000)
    '02:46:40'
    >>> format_duration(1000000)
    '277:46:40'
    >>> format_duration(0.0)
    '00:00.000'
    >>> format_duration(0.5)
    '00:00.500'
    >>> format_duration(12345.6789)
    '03:25:45.679'
    >>> format_duration(-1)
    '-00:01'
    >>> format_duration(-10000)
    '-02:46:40'
    """
    if secs < 0:
        return '-' + format_duration(-secs)
    else:
        s = int(secs) % 60
        m = int(secs) // 60 % 60
        h = int(secs) // 60 // 60
        res = ':'.join('%02.0f' % x for x in (
            [m, s] if h == 0 else [h, m, s]
        ))
        if isinstance(secs, float):
            ms = round(secs % 1, 3)
            res += ('%.3f' % ms)[1:]
        return res