in Sources/CoreMetrics/Metrics.swift [594:627]
func increment(by amount: Double) {
// Drop illegal values
// - cannot increment by NaN
guard !amount.isNaN else { return }
// - cannot increment by infinite quantities
guard !amount.isInfinite else { return }
// - cannot increment by negative values
guard amount.sign == .plus else { return }
// - cannot increment by zero
guard !amount.isZero else { return }
if amount.exponent >= 63 {
// If amount is in Int64.max..<+Inf, ceil to Int64.max
self.lock.withLockVoid {
self.counterHandler.increment(by: .max)
}
} else {
// Split amount into integer and fraction components
var (increment, fraction) = self.integerAndFractionComponents(of: amount)
self.lock.withLockVoid {
// Add the fractional component to the accumulated fraction.
self.fraction += fraction
// self.fraction may have cross an integer boundary, Split it
// and add any integer component.
let (integer, fraction) = integerAndFractionComponents(of: self.fraction)
increment += integer
self.fraction = fraction
// Increment the handler by the total integer component.
if increment > 0 {
self.counterHandler.increment(by: increment)
}
}
}
}