import math


def dec2sex(dec_hours, microsecond=False):
    """ Convert a time in decimal hours to sexagesimal.

    Parameters
    ----------
    dec_hours : float
        A time in decimal hours.

    microsecond : boolean
        If true, will output a 4-tuple (hour, minute, second, microsecond). If false,
        it will output a 3-tuple with a floating point 'second' term.

    Returns
    -------
        See 'microsecond' above.

    Notes
    -----
        This is accurate to 1 microsecond.

    """

    (hrRemainder, hours) = math.modf(dec_hours)
    (minRemainder, minutes) = math.modf(hrRemainder * 60.0)
    (secRemainder, seconds) = math.modf(minRemainder * 60.0)
    microseconds = int(secRemainder * 1E6)

    if microsecond:
        return (int(hours), int(minutes), int(seconds), microseconds)
    else:
        return (int(hours), int(minutes), seconds + secRemainder)