<commit_before>// Sources/SwiftProtobuf/MathUtils.swift - Generally useful mathematical functions
//
// Copyright (c) 2014 - 2017 Apple Inc. and the project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See LICENSE.txt for license information:
// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt
//
// -----------------------------------------------------------------------------
///
/// Generally useful mathematical and arithmetic functions.
///
// -----------------------------------------------------------------------------

import Foundation

/// Remainder in standard modular arithmetic (modulo). This coincides with (%)
/// when a > 0.
///
/// - Parameters:
///   - a: The dividend. Can be positive, 0 or negative.
///   - b: The divisor. This must be positive, and is an error if 0 or negative.
/// - Returns: The unique value r such that 0 <= r < b and b * q + r = a for some q.
internal func mod<T : SignedInteger>(_ a: T, _ b: T) -> T {
    assert(b > 0)
    let r = a % b
    return r >= 0 ? r : r + b
}

/// Quotient in standard modular arithmetic (Euclidean division). This coincides
/// with (/) when a > 0.
///
/// - Parameters:
///   - a: The dividend. Can be positive, 0 or negative.
///   - b: The divisor. This must be positive, and is an error if 0 or negative.
/// - Returns: The unique value q such that for some 0 <= r < b, b * q + r = a.
internal func div<T : SignedInteger>(_ a: T, _ b: T) -> T {
    assert(b > 0)
    return a >= 0 ? a / b : (a + 1) / b - 1
}

#if !swift(>=4.0)
//
// Swift 3 called this initializer "truncatingBitPattern";
// Swift 4 (prerelease) changed this initializer to
// "truncatingIfNeeded".
//
extension UInt8 {
     internal init(truncatingIfNeeded value: UInt32) {
         self.init(truncatingBitPattern: value)
     }
     internal init(truncatingIfNeeded value: Int) {
         self.init(truncatingBitPattern: value)
     }
     internal init(truncatingIfNeeded value: UInt64) {
         self.init(truncatingBitPattern: value)
     }
}

extension UInt32 {
     internal init(truncatingIfNeeded value: UInt64) {
         self.init(truncatingBitPattern: value)
     }<commit_msg>Update comment<commit_after>// Sources/SwiftProtobuf/MathUtils.swift - Generally useful mathematical functions
//
// Copyright (c) 2014 - 2017 Apple Inc. and the project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See LICENSE.txt for license information:
// https://github.com/apple/swift-protobuf/blob/master/LICENSE.txt
//
// -----------------------------------------------------------------------------
///
/// Generally useful mathematical and arithmetic functions.
///
// -----------------------------------------------------------------------------

import Foundation

/// Remainder in standard modular arithmetic (modulo). This coincides with (%)
/// when a > 0.
///
/// - Parameters:
///   - a: The dividend. Can be positive, 0 or negative.
///   - b: The divisor. This must be positive, and is an error if 0 or negative.
/// - Returns: The unique value r such that 0 <= r < b and b * q + r = a for some q.
internal func mod<T : SignedInteger>(_ a: T, _ b: T) -> T {
    assert(b > 0)
    let r = a % b
    return r >= 0 ? r : r + b
}

/// Quotient in standard modular arithmetic (Euclidean division). This coincides
/// with (/) when a > 0.
///
/// - Parameters:
///   - a: The dividend. Can be positive, 0 or negative.
///   - b: The divisor. This must be positive, and is an error if 0 or negative.
/// - Returns: The unique value q such that for some 0 <= r < b, b * q + r = a.
internal func div<T : SignedInteger>(_ a: T, _ b: T) -> T {
    assert(b > 0)
    return a >= 0 ? a / b : (a + 1) / b - 1
}

#if !swift(>=4.0)
//
// Swift 3 called this initializer "truncatingBitPattern";
// Swift 4 changed this initializer to "truncatingIfNeeded".
//
extension UInt8 {
     internal init(truncatingIfNeeded value: UInt32) {
         self.init(truncatingBitPattern: value)
     }
     internal init(truncatingIfNeeded value: Int) {
         self.init(truncatingBitPattern: value)
     }
     internal init(truncatingIfNeeded value: UInt64) {
         self.init(truncatingBitPattern: value)
     }
}

extension UInt32 {
     internal init(truncatingIfNeeded value: UInt64) {
         self.init(truncatingBitPattern: value)
     }
{'fraction_non_alphanumeric': 0.19206967682787074, 'fraction_numerical': 0.016960806784322713, 'mean_word_length': 2.026352288488211, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '654869', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1234, 'n_words': 466}