78 Commits
Author SHA1 Message Date
Stephen Canon 673c0f6c3d Enable and include Builtin module to pickup fadd/fmul_relaxed. 2026-10-11 17:00:36 -04:00
Stephen Canon 69890e3639 Use BuiltinRelaxedFP ops instead of C shims when they're available.
There used to not be any way to attach reassociate or contract flags to fadd/fmul from Swift, which meant that we had to use inline C shims to accomplish this. But I added some Builtins to Swift, so now we don't need C to do this any longer.
2026-10-08 11:24:58 -04:00
reginaldalfret 8630961065 docs(ApproximateEquality): address maintainer review feedback on abstraction and tolerances
Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
2026-10-08 17:46:40 +05:30
reginaldalfret 0d1ccaf0d3 docs: add dedicated documentation for ApproximateEquality (#153)
Add a comprehensive DocC guide for ApproximateEquality covering:
- Background and motivation for approximate equality in floating-point math
- Relative and absolute tolerance guidelines and formulas
- Special value handling (NaN, infinities, signed zeroes)
- Custom norms with AdditiveArithmetic
- Mathematical properties (non-transitivity and why not to use for Equatable)

Also update RealModule.md to link to the DocC article and restore the
Approximate equality section with a link in Sources/RealModule/README.md.

Resolves #153.

Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
2026-10-01 18:56:12 +05:30
Stephen Canon 5bfe9e16ce Remove relaxed add/mul for Float16 on wasm, as they cannot be defined. 2025-08-14 09:45:04 -04:00
Stephen Canon 1e94d23860 Cleanup further doc comment typos. 2025-08-13 14:37:51 -04:00
Stephen Canon b3fe4357f8 Fix typo. 2025-08-13 13:50:49 -04:00
Stephen Canon aa901641d1 Further docc improvements for RealModule.
This commit _also_ relaxes the constraint on Augmented algorithms from Real to FloatingPoint. It's worth calling out that fastTwoSum does not work with decimal floating-point types, so the unordered `Augemented.sum(_:_:)` now has a radix check and calls into the ordered twoSum function instead for Decimal. This makes more sense that a `BinaryFloatingPoint` constraint, as otherwise generic code written against Real or FloatingPoint would have to do the check at every call site.
2025-08-13 12:38:56 -04:00
Stephen Canon b43c10c1e3 Merge branch 'main' into docc-stuff 2025-08-12 13:23:02 -04:00
Stephen Canon 61a8b91b3e Some formatting cleanup around code blocks. 2025-08-12 13:20:29 -04:00
Stephen Canon 8c4747f116 Merge pull request #321 from stephentyrone/remove-2sum-assert
Remove precondition assert from Augmented.sum(large:small:)
2025-08-11 19:34:53 -04:00
Stephen Canon c3757dc266 Fix typo. (Thanks, Guillaume) 2025-08-11 19:33:27 -04:00
Stephen Canon d86286fc8b Remove precondition assert from Augmented.sum(large:small:)
This is potentially useful to identify some bugs, but there are also algorithms (notably Kahan summation) that can be written in terms of fast2sum but would fail this check. Rework documentation to account for the change.
2025-08-11 18:14:41 -04:00
Stephen Canon 9c548804c8 Massage docc files to make the Documentation check happier 2025-08-11 18:11:44 -04:00
Stephen Canon acbf4257ca Remove precondition assert from Augmented.sum(large:small:)
This is potentially useful to identify some bugs, but there are also algorithms (notably Kahan summation) that can be written in terms of fast2sum but would fail this check. Rework documentation to account for the change.
2025-08-11 18:09:22 -04:00
LamTrinh.Dev e79692fab1 Correct typo issue from occured to occurred at ApproximateEquality.swift 2025-08-10 01:15:04 +07:00
Stephen Canon c1e6972eeb Merge pull request #315 from stephentyrone/algebraic-field-magnitude
Constrain AlgebraicField to required Magnitude:AlgebraicField
2025-08-08 17:17:28 -04:00
Stephen Canon da6c765795 Constrain AlgebraicField to required Magnitude:AlgebraicField
This is formally a source-breaking change. However it is expected to not be source-breaking in practice, because any conforming type either has a real magnitude (in the case of real or complex types), which would necessarily have to support all the AF operations to implement the type, or is perhaps a finite field with a bogus stand-in Magnitude.
2025-08-08 13:45:33 -04:00
Stephen Canon 2361b4959b Add overview for RealModule documentation. 2025-08-08 13:43:30 -04:00
Stephen Canon 5cc83cc00a WIP 2025-08-08 09:56:01 -04:00
Stephen Canon d2f6811b87 More docc changes. 2025-08-08 09:55:47 -04:00
Stephen Canon 5d8425644a Initial work on docc setup. 2025-08-08 09:55:42 -04:00
Stephen Canon cd967fa90f Restore relaxed mul/add bindings for Float16 on x86
The ABI is stable, so these operations can be turned on.
2025-08-08 09:52:30 -04:00
Mishal Shah d0ffe3c0e0 Update RealModule README.md to use new swift-evolution link 2025-03-07 16:32:30 -08:00
Stephen Canon f6b0aeb607 Remove _mulAdd in favor of Relaxed.multiplyAdd. 2023-04-26 08:56:43 -04:00
Steve (Numerics) Canon 30c01a9fc5 Possible spelling: Relaxed.sum/product. 2023-04-26 08:56:43 -04:00
Stephen Canon b750c890b7 Don't use reassociate(on) on older clang toolchains. 2023-04-26 08:56:43 -04:00
Stephen Canon 0fff91683a Disable _Float16 shims for relaxed operations on Intel.
The C type isn't available yet in clang on i386 or x86_64; once the calling conventions are stabilized in clang, we can reenable this.
2023-04-26 08:56:43 -04:00
Stephen Canon 9c0332d570 Initial pass at "relaxed" multiply and add operations.
This commit adds the following to the RealFunctions protocol:

    static func _relaxedAdd(_:Self, _:Self) -> Self
    static func _relaxedMul(_:Self, _:Self) -> Self

These are equivalent to + and *, but have "relaxed semantics"; specifically, they license the compiler to reassociate them and to form FMA nodes, which are both significant optimizations that can easily make many common loops 8-10x faster. These transformation perturb results slightly, so they should not be enabled without care, but the results with the relaxed operations are--for most purposes--"just as good as" (and often better than) what strict operations produce. The main thing to beware of is that they are no longer portable; different compiler versions and different targets and optimization flags will result in different results.

They are underscored because they are not stable API. In particular:
- `RealFunctions` is not really the right protocol for these (and neither is `Real`). I need to do some thinking about where to attach them.
- Even if it were the right protocol, these are more like implementation hooks than the API I really want people to use (TBD).
- I like "relaxed" more than other commonly used idioms ("fast"), but I'm not sure it's the name I ultimately want.
2023-04-26 08:56:43 -04:00
Stephen Canon 2baff8fc30 Also fixup real edge cases for pow(0,0). 2022-09-15 16:10:17 -04:00
Stephen Canon 270972dd8a Minor documentation formatting cleanup. 2022-04-06 11:50:25 -04:00
Stephen Canon c4f8886a11 Move baseline supported tools version to 5.4. 2022-03-05 10:18:13 -05:00
Markus Winter 05366d7f4a Revert names of temporary variables 2021-10-27 08:48:54 +02:00
Markus WinterandXiaodi Wu 6ec74ec80e Fix source code formatting
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-10-27 08:28:25 +02:00
Markus Winter f6e5563514 Fix argument ordering in twoSum and add test cases 2021-10-26 15:57:30 +02:00
Markus Winter 8b05d1c8e0 Update comments on the difference of sum(_:_:) and sum(large:small:) 2021-10-21 10:55:24 +02:00
Markus Winter 1e724835bd Add twoSum to augmented arithmetic 2021-10-20 23:47:27 +02:00
Jeremy Saklad ae38370107 Fix typo in AlgebraicField documentation
“distributitve” should be spelled “distributive”.
2021-09-17 14:21:34 -05:00
Stephen CanonandXiaodi Wu 12148ffa66 Update Sources/RealModule/Real.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-08-20 09:06:44 -04:00
Stephen CanonandXiaodi Wu 3a5c73964b Update Sources/RealModule/Real.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-08-20 09:06:36 -04:00
Stephen CanonandXiaodi Wu 32f48e6b73 Update Sources/RealModule/Real.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-08-20 09:06:27 -04:00
Stephen CanonandXiaodi Wu 342d38eb3b Update Sources/RealModule/AlgebraicField.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-08-20 09:05:56 -04:00
Stephen Canon 10e75aa392 Further expand documentation of reciprocal with some example use. 2021-08-19 20:47:36 -04:00
Stephen Canon faf13772af Add some documentation for AlgebraicField ops, minor fix for Augmented. 2021-08-19 14:50:24 -04:00
Stephen Canon 702c6fc1d8 Document the Augmented enum in RealModule in advance of 1.0 2021-08-19 14:00:52 -04:00
Steve (Numerics) Canon 5827f9a943 80-column formatting for source doc comments
Tidying, plus a few small edits. This commit should not include any code changes.
2021-03-03 14:01:09 -05:00
Steve (Numerics) Canon 97852afaf5 Adjust Float16 availability for Swift 5.4 toolchains.
In older toolchains, Float16 is marked unavailable on all mac targets; starting with the 5.4 toolchain, it is available starting in macOS 11.0 when targeting Apple Silicon.
2021-02-19 15:53:15 -05:00
Saleem Abdulrasool 00c6183670 build: update file lists for RealModule and _TestSupport
Add new files to the list that were missed in the CMakeLists.txt
updates.
2020-11-09 11:23:48 -08:00
Stephen Canon 2b4c6701f2 log and log(onePlus:) implementations for Complex
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.
2020-11-05 15:14:25 -05:00
Stephen Canon e07b39453b Swap availability for #if check on Float16. 2020-09-18 16:01:51 -04:00