Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change sdk enabled logic to mimic android and backend #141

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,21 @@ extension RemoteConfig {
/// Determine the max value for the probability `space` by using the number of `digits` (16 ^ `n`)
/// If the `hexValue` is within the `threshold`
/// ```
/// space = 16^numDigits
/// result = (hexValue / space) * 100.0 < threshold
/// space = 16^numDigits - 1
/// result = (hexValue / space) * 100.0 <= threshold
/// ```
/// - Parameters:
/// - hexValue: The value to test
/// - digits: The number of digits used to calculate the total space. Must match the number of digits used to determine the hexValue
/// - threshold: The percentage threshold to test against. Values between 0.0 and 100.0
static func isEnabled(hexValue: UInt64, digits: UInt, threshold: Float) -> Bool {
let space = powf(16, Float(digits))
if threshold <= 0 || threshold > 100 {
return false
}

let space = powf(16, Float(digits)) - 1
let result = (Float(hexValue) / space) * 100

return result < threshold
return result <= threshold
}
}
Loading