135 Commits
Author SHA1 Message Date
Stephen Canon 8a65bea94b Merge pull request #336 from kkebo/fix-freebsd-tests
Skip Float80 overflow/underflow tests on FreeBSD
2026-10-08 11:15:15 -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
Kenta Kubo 1f6c508c58 Skip Float80 overflow/underflow tests on FreeBSD
This is a workaround for FreeBSD's bug.
2026-02-07 20:30:49 +09: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
Stephen Canon 9b36b1ce46 s/sanity check/basic check/ 2025-03-11 10:08:58 -04:00
Mishal Shah 0d774a5bc3 Update RelaxedArithmeticTests.swift to include ignore-unacceptable-language 2025-03-07 16:40:28 -08:00
Stephen Canon 7b1e0db437 Fix-up availability for Float16 in tests for tvOS and watchOS. 2025-03-04 10:18:08 -05: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
Stephen Canon c69fea9be8 Remove Int128 tests for now
Most people are not yet using a toolchain with support for Int128; we'll re-enable these when we bump the baseline to Swift 6.0
2024-07-19 16:15:50 -04:00
Stephen Canon 3ee07816b2 Add new rounding modes: toNearestOr[Down,Up,Zero,Away]
These were omitted in the first pass over integer rounding rules, but are generally useful and make good sense to have available. In particular, toNearestOrUp is the natural mode for a lot of fixed-point arithmetic, and frequently has HW support on SIMD units, so it makes good sense to have a name for that. Once you add that, having nearestOrDown also makes sense, and then nearestOrZero should exist by analogy to nearestOrAway. Also beefed up testing and refactored the division rounding code somewhat.
2024-07-19 16:12:55 -04:00
Stephen Canon 1043e9ed38 Improvements and bugfixes for DoubleWidth prototype
These are used only in TestSupport, but it's still nice to get them right. Signed types had a long-standing bug in how overflow was computed for multiplication, and masking shifts would do the wrong thing when the bitwdith was not a power of two and the shift count was negative. I also added implementations of &*, &+, and &-.
2024-07-12 13:30:13 -04:00
Stephen Canon da661919b9 Fixup some file headers that had the Swift.org text instead of Swift Numerics
These are a copy-pasto from introduced when I originally imported approximate equality (which was originally proposed for the standard library).
2024-07-01 12:46:42 -04:00
Stephen Canon 262cbea1f2 review feedback. 2024-05-16 22:12:24 -04:00
Stephen Canon a883d95a4d Fixup guard on Float16 Complex divide tests. 2024-05-16 15:50:32 -04:00
Stephen Canon 3d6de9f3ef Reworked complex divide scaling. 2024-05-16 15:44:11 -04:00
Stephen Canon 3fa18ae9b5 Test improvements
Improved how tolerance is applied close to infinity for complex division
(this still could use a more principled approach, but at least we're in
the right ballpark now). Tightened up the tolerance for semi-exhaustive
testing too, since that can be done now.
2024-05-16 08:39:12 -04:00
Stephen Canon 1ba2178227 Further progress on complex division 2024-05-14 17:22:50 -04:00
Steve Canon 97bab250eb WIP 2024-05-14 10:24:31 -04:00
Stephen Canon 347f1e31fe Drop support for Swift < 5.4 on main
5.4 will continue to be supported on 1.0.x if needed.
2024-04-19 21:07:58 -04:00
Max Desiatov 43e0f5b026 Delete Tests/CMakeLists.txt 2024-03-04 15:49:07 +00:00
Max Desiatov 0599b610d9 Delete Tests/LinuxMain.swift 2024-03-04 14:24:44 +00:00
Max Desiatov 2fae6a86e3 Remove unused LinuxMain.swift and WindowsMain.swift
These files are no longer needed, as `swift test` enables test discovery by default.
2024-03-04 14:24:17 +00:00
Xiaodi Wu a7e27e16e1 [_TestSupport] Fix DoubleWidth think-os harder 2023-11-13 15:42:07 -05:00
Xiaodi Wu a0d66e1537 [_TestSupport] Fix DoubleWidth think-os 2023-11-13 15:41:52 -05:00
Stephen Canon d59ec36291 Only run benchmarks in Release, they're meaningless in Debug. 2023-04-28 14:36:40 -04:00
Stephen Canon fe151134b0 Further saturating arithmetic test and implementation cleanups 2023-04-27 16:19:40 -04:00
Stephen Canon f00824e9fa More tests for saturating arithmetic -- exhaustive sampling of [U]Int8 arguments. 2023-04-26 21:50:23 -04:00
Stephen Canon 4779aef990 Test coverage for saturating shift + fix the bug that it turned up. 2023-04-26 21:20:57 -04:00
Stephen Canon 740cc5012f Some cleanups to relaxed arithmetic. 2023-04-26 09:05:28 -04:00
Stephen Canon 9a23fdf1c9 Fewer iterations for debug; more for release. 2023-04-26 08:56:43 -04:00
Stephen Canon 79390164f5 CMake support for newer tests. 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 60a3edbaa9 Further improvement to Complex.pow(_:Self,_:Self) edge cases.
Bring pow(zero, w) in line with the behavior of pow for the underlying real type.
2022-09-17 14:56:29 -04:00
Stephen Canon 2baff8fc30 Also fixup real edge cases for pow(0,0). 2022-09-15 16:10:17 -04:00
Stephen Canon b9e8b970f2 Fixup indentation. 2022-09-15 15:39:34 -04:00
Stephen Canon d34f5636c4 Fix the edge-case handling of Complex.pow(.zero, <int>) 2022-09-15 15:07:06 -04:00
Stephen Canon 027bcc5b8e Remove conformance of Complex to Differentiable
The conformance was breaking CI testing, because the CI bots use a macOS version that predates availability of the _Differentiation module, and the compiler-generated differentation operations have neither availability attributes nor checks, so any reference to those operations simply crashes in dyld because the library is not present. We can add availability, but that's not really accurate either, because these operations are not actually binary-stable, so while we wouldn't crash in dyld, we also might not work correctly in the future. We could mark them unavailable on Apple platforms, but that's also not quite right (and further means that they're not going to get a lot of attention). The best solution seems to be to remove the conformance (which was never source-stable).
2022-04-06 14:41:04 -04:00
Stephen Canon 27f8192a63 Attempt to work around CI misconfiguration by removing Complex Differentiable conformance. 2022-04-06 09:58:40 -04:00
Stephen Canon c4f8886a11 Move baseline supported tools version to 5.4. 2022-03-05 10:18:13 -05:00
Stephen Canon 47a233758d Use DoubleWidth in stochastic rounding right-shift tests.
This lets us get rid of Double here, and get more meaningful test coverage for 64b values. Also test 128b to cover double-width itself somewhat.
2021-11-24 11:35:40 -05:00
Stephen Canon b501ca406c Merge pull request #197 from benrimmington/experimental
Add the `DoubleWidth` type
2021-10-27 15:48:29 -04:00
be0534a3e3 Add the DoubleWidth type
Co-authored-by: Nate Cook <natecook@apple.com>
Co-authored-by: Max Moiseev <moiseev@users.noreply.github.com>
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2021-10-27 18:14:10 +01:00
Stephen Canon c74d817e8d Merge pull request #208 from markuswntr/two-sum
Add `Augmented.sum(_:_:)` aka "twoSum"
2021-10-27 12:27:16 -04:00
Markus Winter d4a440fd05 Update range of random values in test cases 2021-10-26 16:27:04 +02:00
Markus Winter f6e5563514 Fix argument ordering in twoSum and add test cases 2021-10-26 15:57:30 +02:00
Stephen Canon 24d8f51bb3 Add tests for remainder(dividingBy: -1). 2021-10-14 10:39:39 -04:00
Stephen Canon 3eaa0b3b77 Additional documentation for division/shift with rounding
Also simplifies check logic for divide with rounding, which is a modest speedup for testing.
2021-10-13 16:44:52 -04:00
Stephen Canon 710ca088d5 Renamed shifted(right:) to shifted(rightBy:). 2021-10-13 11:08:09 -04:00
Stephen Canon 501f58252a Added division with rounding operations. 2021-10-12 17:16:57 -04:00