265 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 a7d826ead0 Merge pull request #352 from stephentyrone/fix-cosh-sinh-signs
Fix signs of cosh and sinh near the overflow boundary.
2026-09-10 10:53:41 -04:00
Stephen Canon c2d05532d3 Fix signs of cosh and sinh near the overflow boundary.
Resovles https://github.com/apple/swift-numerics/issues/347
2026-09-10 10:27:51 -04:00
Stephen Canon 3b272b08af a word. 2026-09-10 10:09:49 -04:00
Stephen Canon bb7b69501f Relax documented behavior of Complex.reciprocal
In cases of underflow, multiplication by reciprocal may not be the same as division. Document this, rather than tightening the behavior, because it's still about as good as multiplication by reciprocal would be for a Real type.
2026-09-10 10:07:01 -04:00
Stephen Canon 738b0cdb23 Merge pull request #345 from kadyrbekovhamit-cyber/fix-rounding-documentation-examples
Replace nonexistent stochastic-rounding examples
2026-09-10 09:45:04 -04:00
kadyrbekovhamit-cyber 15eab09844 Correct toNearestOrZero shift example
5 / 2 is exactly halfway between 2 and 3. The toNearestOrZero tie-breaking rule selects 2, the value with smaller magnitude.
2026-09-05 14:08:17 +05:00
kadyrbekovhamit-cyber 2d92c04e96 Leave existing tie-to-zero fix to PR 341 2026-09-04 22:37:41 +05:00
kadyrbekovhamit-cyber aa5684820a Correct rounding documentation examples 2026-09-04 21:30:38 +05:00
Stephen Canon 899af71c02 Merge pull request #328 from stephentyrone/complex-divide-docs
Added some notes on complex division.
2026-01-28 20:58:00 -05:00
Eric Bariaux 894008997c Ensure compatibility with Swift versions below 6 2025-09-25 12:41:14 +02:00
Eric Bariaux d46e20b4c5 String(reflecting:) not available in Embedded mode.
And Real does not conform to CustomDebugStringConvertible, so can't access debugDescription property directly on x and y
2025-09-18 07:21:15 +02:00
Eric Bariaux 6a7cf593bf Codable not available right-now in Embedded mode 2025-09-18 07:20:19 +02:00
Stephen Canon cbdb286797 Added some notes on complex division. 2025-08-20 19:18:41 -04:00
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 46619b49ec Attempt to turn on workflows testing for wasm. 2025-08-14 09:40:35 -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 2c19b7b8cd Last few review notes on complex. 2025-08-12 15:13:07 -04:00
Stephen Canon 221387985a Further review edits from Nate. 2025-08-12 15:04:11 -04:00
Stephen Canon 8b2fd7bbde Provide transliteration of Чебышёв. 2025-08-12 14:52:42 -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
Stephen Canon af0352e8b1 Some additional organization for Complex docc. 2025-08-09 14:29:05 -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 5b34639450 Further documentation work for Complex. 2025-08-08 09:55:59 -04:00
Stephen Canon 450691764d typo. 2025-08-08 09:55:56 -04:00
Stephen Canon 95e9441f8c Changes from review feedback. 2025-08-08 09:55:54 -04:00
Stephen Canon d2f6811b87 More docc changes. 2025-08-08 09:55:47 -04:00
Stephen Canon 129e496ef1 Further docc work. 2025-08-08 09:55:46 -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
John Hui 1be6eb5b47 Add extern "C" to shim header file
Adding this allows this package to be used with C++ interop enabled.
Otherwise, building a package that depends on this leads to linker
errors

rdar://113756245
2025-05-22 18:09:11 -07:00
Stephen Canon 31fe14d084 Remove stochastic rounding mode
It's a useful operation, but it deserves its own API to allow the use of a custom random source.
Also, the existing API blocks some constant-folding operations because the call to the system random source is an opaque optimization barrier, so removing it allows us to produce better codegen for the other rounding modes.

We're also bumping required Swift version to 5.9, and removing the executable test targets for log/log1p, as they're really only useful for development of those algorithms.
2025-04-10 10:39:51 -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 ddc8ce302b Make all rounding rules (from IntegerUtilities) available on FloatingPoint
IntegerUtilities has RoundingRule that is a superset of FloatingPointRoundingRule; many of these are also useful when working with floating-point. This change provides a `rounding(_:)` function similar to the standard libraries `rounded(_:)` that makes all of them available. It has a different name instead of being a shadow because otherwise existing use sites like `rounded(.down)` would become ambiguous.
2024-08-15 11:58:38 -04:00
Stephen Canon 683c8f210a Cleanup and bug fix for wide stochastic rounding path. 2024-07-19 21:42:54 -04:00