|
| 1 | +//===--- BinaryFloatingPointProperties.swift ------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +import Foundation |
| 14 | +import TestsUtils |
| 15 | + |
| 16 | +public let BinaryFloatingPointPropertiesBinade = BenchmarkInfo( |
| 17 | + name: "BinaryFloatingPointPropertiesBinade", |
| 18 | + runFunction: run_BinaryFloatingPointPropertiesBinade, |
| 19 | + tags: [.validation, .algorithm] |
| 20 | +) |
| 21 | + |
| 22 | +public let BinaryFloatingPointPropertiesNextUp = BenchmarkInfo( |
| 23 | + name: "BinaryFloatingPointPropertiesNextUp", |
| 24 | + runFunction: run_BinaryFloatingPointPropertiesNextUp, |
| 25 | + tags: [.validation, .algorithm] |
| 26 | +) |
| 27 | + |
| 28 | +public let BinaryFloatingPointPropertiesUlp = BenchmarkInfo( |
| 29 | + name: "BinaryFloatingPointPropertiesUlp", |
| 30 | + runFunction: run_BinaryFloatingPointPropertiesUlp, |
| 31 | + tags: [.validation, .algorithm] |
| 32 | +) |
| 33 | + |
| 34 | +@inline(never) |
| 35 | +public func run_BinaryFloatingPointPropertiesBinade(_ N: Int) { |
| 36 | + var xs = [Double]() |
| 37 | + xs.reserveCapacity(N) |
| 38 | + for _ in 1...N { |
| 39 | + var x = 0 as Double |
| 40 | + for i in 0..<10000 { |
| 41 | + x += Double(getInt(i)).binade |
| 42 | + } |
| 43 | + xs.append(x) |
| 44 | + } |
| 45 | + CheckResults(xs[getInt(0)] == 37180757) |
| 46 | +} |
| 47 | + |
| 48 | +@inline(never) |
| 49 | +public func run_BinaryFloatingPointPropertiesNextUp(_ N: Int) { |
| 50 | + var xs = [Int]() |
| 51 | + xs.reserveCapacity(N) |
| 52 | + for _ in 1...N { |
| 53 | + var x = 0 as Int |
| 54 | + for i in 0..<10000 { |
| 55 | + x += Int(Double(getInt(i)).nextUp) |
| 56 | + } |
| 57 | + xs.append(x) |
| 58 | + } |
| 59 | + CheckResults(xs[getInt(0)] == 49995000) |
| 60 | +} |
| 61 | + |
| 62 | +@inline(never) |
| 63 | +public func run_BinaryFloatingPointPropertiesUlp(_ N: Int) { |
| 64 | + var xs = [Int]() |
| 65 | + xs.reserveCapacity(N) |
| 66 | + for _ in 1...N { |
| 67 | + var x = 0 as Int |
| 68 | + for i in 0..<10000 { |
| 69 | + x += Int(Double(getInt(i)).ulp) |
| 70 | + } |
| 71 | + xs.append(x) |
| 72 | + } |
| 73 | + CheckResults(xs[getInt(0)] == 0) |
| 74 | +} |
0 commit comments