third_party/inchi/INCHI_BASE/src/ichicano.c
long InchiTimeMsecDiff( INCHI_CLOCK *ic, inchiTime *TickEnd, inchiTime *TickStart )
{
    if (FullMaxClock > 0)
    {
        clock_t delta;
        if (!TickEnd || !TickStart)
            return 0;
        /* clock_t is unsigned */
        if (TickEnd->clockTime > TickStart->clockTime)
        {
            if (TickEnd->clockTime > HalfMaxClock &&
                 TickEnd->clockTime - TickStart->clockTime > HalfMaxClock)
            {
                /* overflow in TickStart->clockTime, actually TickStart->clockTime was later */
                delta = ( FullMaxClock - TickEnd->clockTime ) + TickStart->clockTime;
                return -INCHI_MSEC( delta );
            }
            delta = TickEnd->clockTime - TickStart->clockTime;
            return INCHI_MSEC( delta );
        }
        else if (TickEnd->clockTime < TickStart->clockTime)
        {
            if (TickStart->clockTime > HalfMaxClock &&
                 TickStart->clockTime - TickEnd->clockTime > HalfMaxClock)
            {
                /* overflow in TickEnd->clockTime, actually TickEnd->clockTime was later */
                delta = ( FullMaxClock - TickStart->clockTime ) + TickEnd->clockTime;
                return INCHI_MSEC( delta );
            }
            delta = TickStart->clockTime - TickEnd->clockTime;
            return -INCHI_MSEC( delta );
        }
        return 0; /* TickEnd->clockTime == TickStart->clockTime */
    }
    else
    {
        /* may happen under Win32 only where clock_t is SIGNED long */
        clock_t delta;
        FillMaxMinClock( ic );
        if (!TickEnd || !TickStart)
            return 0;
        if (TickEnd->clockTime >= 0 && TickStart->clockTime >= 0 ||
             TickEnd->clockTime <= 0 && TickStart->clockTime <= 0)
        {
            delta = TickEnd->clockTime - TickStart->clockTime;
        }
        else
            if (TickEnd->clockTime >= ic->m_HalfMaxPositiveClock &&
                 TickStart->clockTime <= ic->m_HalfMinNegativeClock)
            {
/* end is earlier than start */
                delta = ( ic->m_MaxPositiveClock - TickEnd->clockTime ) + ( TickStart->clockTime - ic->m_MinNegativeClock );
                delta = -delta;
            }
            else
                if (TickEnd->clockTime <= ic->m_HalfMinNegativeClock &&
                     TickStart->clockTime >= ic->m_HalfMaxPositiveClock)
                {
/* start was earlier than end */
                    delta = ( ic->m_MaxPositiveClock - TickStart->clockTime ) + ( TickEnd->clockTime - ic->m_MinNegativeClock );
                }
                else
                {
                     /* there was no overflow, clock passed zero */
                    delta = TickEnd->clockTime - TickStart->clockTime;
                }
        return INCHI_MSEC( delta );
    }
}
/******** returns difference TickEnd - TickStart in milliseconds **********/
returns difference TickEnd - TickStart in milliseconds
returns difference TickEnd - TickStart in milliseconds
long InchiTimeMsecDiff( INCHI_CLOCK *ic, inchiTime *TickEnd, inchiTime *TickStart )
{
    if (FullMaxClock > 0)
    {
        clock_t delta;
        if (!TickEnd || !TickStart)
            return 0;
        if (TickEnd->clockTime > TickStart->clockTime)
        {
            if (TickEnd->clockTime > HalfMaxClock &&
                 TickEnd->clockTime - TickStart->clockTime > HalfMaxClock)
            {
                delta = ( FullMaxClock - TickEnd->clockTime ) + TickStart->clockTime;
                return -INCHI_MSEC( delta );
            }
            delta = TickEnd->clockTime - TickStart->clockTime;
            return INCHI_MSEC( delta );
        }
        else if (TickEnd->clockTime < TickStart->clockTime)
        {
            if (TickStart->clockTime > HalfMaxClock &&
                 TickStart->clockTime - TickEnd->clockTime > HalfMaxClock)
            {
                delta = ( FullMaxClock - TickStart->clockTime ) + TickEnd->clockTime;
                return INCHI_MSEC( delta );
            }
            delta = TickStart->clockTime - TickEnd->clockTime;
            return -INCHI_MSEC( delta );
        }
        return 0; 
    }
    else
    {
        clock_t delta;
        FillMaxMinClock( ic );
        if (!TickEnd || !TickStart)
            return 0;
        if (TickEnd->clockTime >= 0 && TickStart->clockTime >= 0 ||
             TickEnd->clockTime <= 0 && TickStart->clockTime <= 0)
        {
            delta = TickEnd->clockTime - TickStart->clockTime;
        }
        else
            if (TickEnd->clockTime >= ic->m_HalfMaxPositiveClock &&
                 TickStart->clockTime <= ic->m_HalfMinNegativeClock)
            {
                delta = ( ic->m_MaxPositiveClock - TickEnd->clockTime ) + ( TickStart->clockTime - ic->m_MinNegativeClock );
                delta = -delta;
            }
            else
                if (TickEnd->clockTime <= ic->m_HalfMinNegativeClock &&
                     TickStart->clockTime >= ic->m_HalfMaxPositiveClock)
                {
                    delta = ( ic->m_MaxPositiveClock - TickStart->clockTime ) + ( TickEnd->clockTime - ic->m_MinNegativeClock );
                }
                else
                {
                    delta = TickEnd->clockTime - TickStart->clockTime;
                }
        return INCHI_MSEC( delta );
    }
}
long InchiTimeMsecDiff ( INCHI_CLOCK * ic , inchiTime * TickEnd , inchiTime * TickStart ) { if ( FullMaxClock > 0 ) { clock_t delta ; if ( ! TickEnd || ! TickStart ) return 0 ; if ( TickEnd -> clockTime > TickStart -> clockTime ) { if ( TickEnd -> clockTime > HalfMaxClock && TickEnd -> clockTime - TickStart -> clockTime > HalfMaxClock ) { delta = ( FullMaxClock - TickEnd -> clockTime ) + TickStart -> clockTime ; return - INCHI_MSEC ( delta ) ; } delta = TickEnd -> clockTime - TickStart -> clockTime ; return INCHI_MSEC ( delta ) ; } else if ( TickEnd -> clockTime < TickStart -> clockTime ) { if ( TickStart -> clockTime > HalfMaxClock && TickStart -> clockTime - TickEnd -> clockTime > HalfMaxClock ) { delta = ( FullMaxClock - TickStart -> clockTime ) + TickEnd -> clockTime ; return INCHI_MSEC ( delta ) ; } delta = TickStart -> clockTime - TickEnd -> clockTime ; return - INCHI_MSEC ( delta ) ; } return 0 ; } else { clock_t delta ; FillMaxMinClock ( ic ) ; if ( ! TickEnd || ! TickStart ) return 0 ; if ( TickEnd -> clockTime >= 0 && TickStart -> clockTime >= 0 || TickEnd -> clockTime <= 0 && TickStart -> clockTime <= 0 ) { delta = TickEnd -> clockTime - TickStart -> clockTime ; } else if ( TickEnd -> clockTime >= ic -> m_HalfMaxPositiveClock && TickStart -> clockTime <= ic -> m_HalfMinNegativeClock ) { delta = ( ic -> m_MaxPositiveClock - TickEnd -> clockTime ) + ( TickStart -> clockTime - ic -> m_MinNegativeClock ) ; delta = - delta ; } else if ( TickEnd -> clockTime <= ic -> m_HalfMinNegativeClock && TickStart -> clockTime >= ic -> m_HalfMaxPositiveClock ) { delta = ( ic -> m_MaxPositiveClock - TickStart -> clockTime ) + ( TickEnd -> clockTime - ic -> m_MinNegativeClock ) ; } else { delta = TickEnd -> clockTime - TickStart -> clockTime ; } return INCHI_MSEC ( delta ) ; } }
returns difference TickEnd - TickStart in milliseconds
returns difference TickEnd - TickStart in milliseconds
/* clock_t is unsigned */ /* overflow in TickStart->clockTime, actually TickStart->clockTime was later */ /* overflow in TickEnd->clockTime, actually TickEnd->clockTime was later */ /* TickEnd->clockTime == TickStart->clockTime */ /* may happen under Win32 only where clock_t is SIGNED long */ /* end is earlier than start */ /* start was earlier than end */ /* there was no overflow, clock passed zero */