-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite BinaryInteger+Logarithm.swift tests (#110).
- Loading branch information
Showing
5 changed files
with
151 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//=----------------------------------------------------------------------------= | ||
// This source file is part of the Ultimathnum open source project. | ||
// | ||
// Copyright (c) 2023 Oscar Byström Ericsson | ||
// Licensed under Apache License, Version 2.0 | ||
// | ||
// See http://www.apache.org/licenses/LICENSE-2.0 for license information. | ||
//=----------------------------------------------------------------------------= | ||
|
||
import CoreKit | ||
|
||
//*============================================================================* | ||
// MARK: * Expect x Logarithm | ||
//*============================================================================* | ||
|
||
@inlinable public func Ɣexpect<T>( | ||
_ value: T, | ||
ilog2 expectation: Count, | ||
at location: SourceLocation = #_sourceLocation | ||
) throws where T: BinaryInteger { | ||
|
||
let ilog2 = try #require(value.ilog2()) | ||
#expect(ilog2 == expectation, sourceLocation: location) | ||
#expect(ilog2 < T.size, sourceLocation: location) | ||
#expect(ilog2.isInfinite == value.isInfinite, sourceLocation: location) | ||
|
||
if !ilog2.isInfinite { | ||
let low = T.lsb.up(ilog2) | ||
#expect(value >= low, sourceLocation: location) | ||
|
||
if let high = low.times(2).optional() { | ||
#expect(value < high, sourceLocation: location) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters