Function

CMTimeSubtract(_:_:)

Returns the difference of two CMTimes.

Declaration

func CMTimeSubtract(_ lhs: CMTime, _ rhs: CMTime) -> CMTime

Parameters

minuend

The CMTime from which the subtrahend will be subtracted.

subtrahend

The CMTime that will be subtracted from the minuend.

Return Value

The difference of the two CMTimes (minuend - subtrahend).

Discussion

If the operands both have the same timescale, the timescale of the result will be the same as the operands' timescale. If the operands have different timescales, the timescale of the result will be the least common multiple of the operands' timescales. If that LCM timescale is greater than kCMTimeMaxTimescale, the result timescale will be kCMTimeMaxTimescale, and default rounding will be applied when converting the result to this timescale.

If the result value overflows, the result timescale will be repeatedly halved until the result value no longer overflows. Again, default rounding will be applied when converting the result to this timescale. If the result value still overflows when timescale == 1, then the result will be either positive or negative infinity, depending on the direction of the overflow.

If any rounding occurs for any reason, the result's kCMTimeFlags_HasBeenRounded flag will be set. This flag will also be set if either of the operands has hasBeenRounded set. If either of the operands is invalid, the result will be invalid. If the operands are valid, but just one operand is infinite, the result will be similarly infinite. If the operands are valid, and both are infinite, the results will be as follows:

  • +infinity - +infinity == invalid

  • -infinity - -infinity == invalid

  • +infinity - -infinity == +infinity

  • -infinity - +infinity == -infinity

If the operands are valid, not infinite, and either or both is indefinite, the result will be indefinite. If the two operands are numeric (i.e.. valid, not infinite, not indefinite), but have different nonzero epochs, the result will be invalid. If they have the same nonzero epoch, the result will have epoch zero (a duration). Times in different epochs cannot be added or subtracted, because epoch length is unknown. Times in epoch zero are considered to be durations and can be subtracted from times in other epochs. Times in different epochs can be compared, however, because numerically greater epochs always occur after numerically lesser epochs.

See Also

Performing Common Operations

func CMTimeAdd(CMTime, CMTime) -> CMTime

Returns the sum of two CMTimes.

func CMTimeMultiply(CMTime, multiplier: Int32) -> CMTime

Returns the product of a CMTime and a 32-bit integer.

func CMTimeMultiplyByFloat64(CMTime, multiplier: Float64) -> CMTime

Returns the product of a CMTime and a 64-bit float.

func CMTimeMultiplyByRatio(CMTime, multiplier: Int32, divisor: Int32) -> CMTime

Returns the result of multiplying a CMTime by an integer, then dividing by another integer.

func CMTimeConvertScale(CMTime, timescale: Int32, method: CMTimeRoundingMethod) -> CMTime

Returns a new CMTime containing the source CMTime converted to a new timescale (rounding as requested).