Src/MicrosecondDelta.c

/*                                  MicrosecondDelta.c                              */
/*
 * MicrosecondDelta.c
 * Copyright © 1994 Apple Computer Inc. All rights reserved.
 */
#include "MicrosecondTrap.h"
 
/*
 * Convert an epoch to microseconds (use floating-point operations).
 * Note that 4294967296.0 is 2^32, which is represented accurately
 * in double-precision floating point. Note that this can loose
 * low-order bits.
 */
#define kTwoPower32 (4294967296.0)
 
double
MicrosecondToDouble(
        register const UnsignedWide *epochPtr
    )
{
        register double         result;
        
        result = (((double) epochPtr->hi) * kTwoPower32) + epochPtr->lo;
        return (result);
}
 
/*
 * Return the difference between two Microsecond Trap values.
 * Integer subtraction is used to preserve accuracy.
 */
void
MicrosecondDelta(
        register const UnsignedWide *startPtr,
        register const UnsignedWide *endPtr,
        register UnsignedWide       *result
    )
{
        if (endPtr->lo >= startPtr->lo)
            result->hi = endPtr->hi - startPtr->hi;
        else {
            result->hi = (endPtr->hi - 1) - startPtr->hi;
        }
        result->lo = endPtr->lo - startPtr->lo;
}