mirror of
https://github.com/apple/swift-numerics
synced 2026-11-24 04:38:11 +00:00
These significantly improve on the state of the art for arguments close to the circle where the result vanishes, producing good componentwise relative accuracy as well as relative accuracy in the complex norm. Also drops the argument parser dependency, which is desirable to avoid possible circular dependencies in the future with algorithms.
30 lines
901 B
Swift
30 lines
901 B
Swift
//===--- AugmentedArithmetic.swift ----------------------------*- swift -*-===//
|
|
//
|
|
// This source file is part of the Swift Numerics open source project
|
|
//
|
|
// Copyright (c) 2020 Apple Inc. and the Swift Numerics project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
public enum Augmented { }
|
|
|
|
extension Augmented {
|
|
@_transparent
|
|
public static func twoProdFMA<T:Real>(_ a: T, _ b: T) -> (head: T, tail: T) {
|
|
let head = a*b
|
|
let tail = (-head).addingProduct(a, b)
|
|
return (head, tail)
|
|
}
|
|
|
|
@_transparent
|
|
public static func fastTwoSum<T:Real>(_ a: T, _ b: T) -> (head: T, tail: T) {
|
|
assert(!(b.magnitude > a.magnitude))
|
|
let head = a + b
|
|
let tail = a - head + b
|
|
return (head, tail)
|
|
}
|
|
}
|