Commit Graph

48 Commits

Author SHA1 Message Date
Alex Martini
57657c6d3e Clarify what "schoolbook" rounding means (#77903) 2025-01-06 16:27:47 -08:00
Nate Cook
6c29d2f64a Fix the doc formatting for FloatingPoint comparison methods (#78443)
In the documentation for the `isLess(than:)` and `isLessThanOrEqualTo(_:)`
methods, a code sample isn't being formatted correctly due to it directly
following an unordered list. This change adds an additional message that
introduces the code sample, separating it from the list and allowing
the correct formatting to be applied.
2025-01-06 15:13:42 -08:00
Max Desiatov
633d5bc45a Enable x86_64 and i686 ELF triples for embedded Swift (#70642)
This is just as useful for x86 bare metal as the already enabled `arm*-none-none-eabi` triples.
2024-01-26 21:39:17 +00:00
Alex Martini
4d53ce470e Make pseudocode look less like real code.
Generalizes the change in aac6d97f3f.
2022-08-25 15:48:36 -07:00
Alex Martini
c0abd3a3e8 Remove unused link destination.
See also commit 93c350dff7
2022-07-21 11:31:36 -07:00
Alex Martini
93c350dff7 Reference style doesn't allow links in abstracts.
Fixes <rdar://93208475>
2022-06-30 12:34:40 -07:00
André Mello
af461ec5a4 Improve description of the pi constant (#41585) 2022-03-08 11:21:14 -05:00
Alex Martini
d4109704dd Make pseudocode look less like real code.
There isn't actually an ** operator in Swift, so making the formula that
includes ** for exponentiation look like Swift can lead to confusion.

Fixes rdar://56184186
2022-01-20 15:07:23 -08:00
Karoy Lorentey
1dbcf23515 [stdlib] Availability macros don't work in inlinable code 😩 2021-10-31 15:00:59 -07:00
Karoy Lorentey
8ed81ae063 [stdlib] Adopt availability macros 2021-10-31 15:00:58 -07:00
Alex Martini
1c5c111aab Merge pull request #36709 from amartini51/main
Doc comment corrections
2021-04-05 15:46:31 -07:00
Alex Martini
1bfce98e8d Revise finite/infinite note for NaN.
Incorporates PR feedback from @tbkka.
2021-04-01 16:05:48 -07:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Alex Martini
db9fc0beed Fix a few contractions, per reference style guide. 2021-02-17 15:16:34 -08:00
Doug Gregor
1a1f79c0de Introduce safety checkin for ConcurrentValue conformance.
Introduce checking of ConcurrentValue conformances:
- For structs, check that each stored property conforms to ConcurrentValue
- For enums, check that each associated value conforms to ConcurrentValue
- For classes, check that each stored property is immutable and conforms
  to ConcurrentValue

Because all of the stored properties / associated values need to be
visible for this check to work, limit ConcurrentValue conformances to
be in the same source file as the type definition.

This checking can be disabled by conforming to a new marker protocol,
UnsafeConcurrentValue, that refines ConcurrentValue.
UnsafeConcurrentValue otherwise his no specific meaning. This allows
both "I know what I'm doing" for types that manage concurrent access
themselves as well as enabling retroactive conformance, both of which
are fundamentally unsafe but also quite necessary.

The bulk of this change ended up being to the standard library, because
all conformances of standard library types to the ConcurrentValue
protocol needed to be sunk down into the standard library so they
would benefit from the checking above. There were numerous little
mistakes in the initial pass through the stsandard library types that
have now been corrected.
2021-02-04 03:45:09 -08:00
Stephen Canon
95309e1dce Fixup Float16 availability for macCatalyst/x86_64 2020-12-09 13:51:51 -05:00
Xiaodi Wu
23dc001364 Merge pull request #33910 from xwu/exactness-in-little-things-a-wonderful-source-of-cheerfulness
[stdlib] Simplify 'BinaryFloatingPoint.init?<T: BinaryFloatingPoint>(exactly: T)'
2020-10-05 12:14:27 -04:00
Xiaodi Wu
7898f0b7ad [stdlib] Silence signaling NaN in generic conversions (#33902) 2020-09-15 15:05:29 -04:00
Xiaodi Wu
26cda274ca [stdlib] Simplify 'BinaryFloatingPoint.init?<T: BinaryFloatingPoint>(exactly: T)' 2020-09-11 09:56:58 -04:00
Xiaodi Wu
643834e7f5 [stdlib] Simplify generic floating-point conversion fast paths 2020-09-08 12:08:08 -04:00
Xiaodi Wu
45d69d58d0 [stdlib] Use 'truncatingIfNeeded:' in floating-point conversion fast paths 2020-09-08 11:32:09 -04:00
Xiaodi Wu
9a6900ad3a [stdlib] Refactor generic floating-point conversion fast paths 2020-09-07 18:47:01 -04:00
Xiaodi Wu
f40fd369cd [stdlib] Add another fast path for generic floating-point conversion 2020-09-07 18:47:01 -04:00
Xiaodi Wu
b6046352de 🤮 2020-09-04 17:51:39 -04:00
Xiaodi Wu
70b68d6ba9 [stdlib] Include Float16 among source types recognized for generic conversion 2020-09-04 16:16:10 -04:00
Xiaodi Wu
42f79b0e87 [stdlib] Make use of protocol requirements to convert from concrete types 2020-09-04 14:23:53 -04:00
NevinBR
a62bf48e68 [stdlib] [NFC] FloatingPointRandom.swift created (#33463)
* Moved `random` methods out of FloatingPoint.swift

* Added `random` methods to FloatingPointRandom.swift

* Added FloatingPointRandom.swift to CMakeLists.txt

* Added FloatingPointRandom.swift to GroupInfo.json

* Moved filename within CMakeLists.txt
2020-08-18 18:12:35 -04:00
Stephen Canon
7985896949 Provide an implementation of init?<T:BinaryInteger>(exactly:T) on each stdlib FP type. (#32632)
Previously these always went through the FloatingPoint-provided default implementation, which is not particularly efficient. Also try removing inlinable from the generic _convert hooks, since we probably never want to actually inline them.
2020-06-30 20:59:31 -04:00
Valeriy Van
d6b2d06420 Fixes snippet 2020-05-12 13:51:54 +02:00
Valeriy Van
b59e689b95 Fixes example snippets in FloatingPoint.swift
In terms of Swift [-9.5, 2.5, 3.0, 21.25, .nan] != [-9.5, 2.5, 3.0, 21.25, .nan] because Double.nan != Double.nan
2020-05-12 13:47:03 +02:00
Valeriy Van
9f2e196db0 Fixes example snippets in FloatingPoint.swift 2020-05-05 23:19:09 +02:00
Xiaodi Wu
03903ae1ea [stdlib] Fix generic floating-point conversion when two representable values are equally close 2020-03-03 18:22:47 -05:00
Stephen Canon
fb2128b33b Remove doc comments from concrete floating-point types (#26399)
* Remove doc comments from concrete floating-point types

... when they are already present on the protocol. I don't *think* that we need them anymore for xcode documentation purposes. There are reasonable arguments both ways on this:
1. when you're editing the concrete implementations, it's sometimes nice to have the doc comment right there.
2. but it needlessly repetitive, and introduces the opportunity for comments to get out of sync.
3. it also adds noise; it would be nice for information density if the implementation only had implementation notes.

* Add examples to documentation for FloatingPoint.isCanonical

In particular, document that subnormal encodings are treated as non-canonical zeros on platforms that flush to zero.

* Additional fixes by @xwu and @natecook1000 .
2019-08-06 18:17:37 -04:00
Xiaodi Wu
a078c33ceb [stdlib] Change documented behavior of FloatingPoint.significand (#26390) 2019-07-29 11:08:04 -04:00
Paul Hudson
06f82a53b5 Replaced the majority of ' : ' with ': '. 2019-07-18 20:46:07 +01:00
Stephen Canon
166d0fa961 FloatingPoint.radix should be transparent. (#25789)
* FloatingPoint.radix should be inlinable.

* Switch transparent to inlinable+inline(__always).
2019-06-26 18:20:27 -04:00
Vlad Gorlov
6370681656 Android cross-compile on macOS: Fix for compile error addressed Float80 data type. (#25502)
* Fixes issue addressed Float80 data type. Float80 is disabled for Intel architectures (i.e. Android Simulator).

* More precise condition check.
2019-06-17 13:40:44 -04:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Stephen Canon
57a4553832 SE-0246: Protocols and static functions (#23824)
This implements the protocols and static functions proposed in SE-0246, plus some initial test coverage. It also has some rough accompanying cleanup of tgmath. It does not include the globals (on scalars or SIMD types) nor does it deprecate much in tgmath.h.
2019-04-17 23:57:33 +02:00
Stephen Canon
c5e3f85378 Revert SE-0246 (#23800)
* Revert "Merge pull request #23791 from compnerd/you-know-nothing-clang"

This reverts commit 5150981150, reversing
changes made to 8fc305c03e.

* Revert "Merge pull request #23780 from compnerd/math-is-terrible"

This reverts commit 2d7fedd25f, reversing
changes made to 0205150b8f.

* Revert "Merge pull request #23140 from stephentyrone/mafs"

This reverts commit 777750dc51, reversing
changes made to 0c8920e747.
2019-04-04 19:35:25 -04:00
Steve (Numerics) Canon
3fda509805 Implementation of ElementaryFunctions / Real protocols.
This commit implements SE-0246, by adding conformance to Real to the Float, CGFloat, Double, and Float80 types, implemented either in terms of the system's C math library, existing standard library functionality, or LLVM intrinsics. It includes basic test coverage for these new functions, and deprecates and obsoletes *some* existing functionality in the Platform overlay. We still need to make a decision about how to handle the remaining "tgmath" functions, because obsoleting them is technically a source-breaking change (if users have unqualified names like "exp(1)", it's fine, but it would break users who have used qualified names like "Darwin.exp(1)".)
2019-04-02 18:49:31 -04:00
Stephen Canon
60fc39e72a Improve codegen for init(signOf: magnitudeOf:) (#23727)
This can map straight to the LLVM copysign intrinsic for builtin types, which both gets us better codgen and lets the compiler plug this operation into other LLVM-level optimizations.
2019-04-02 09:49:18 -04:00
Stephen Canon
20a1781842 Minor improvement for the documentation of ulp and ulpOfOne. (#23211)
1. Move discussion of `DBL_EPSILON` etc. onto `ulpOfOne` instead of `ulp`.
2. Add text explaining that `ulpOfOne` is a poor value to use for approximate comparison.
2019-03-11 13:06:41 -04:00
Karoy Lorentey
545fa5e640 [stdlib] Re-add previously synthesized hashing definitions 2018-11-22 17:15:36 +00:00
Maxim Moiseev
cbf83ac04f [NFC][stdlib] Add FIXME markers to simplify audit 2018-11-14 11:58:42 -08:00
Slava Pestov
f6c2caf64b stdlib: Add @inlinable to @inline(__always) declarations
These should be audited since some might not actually need to be
@inlinable, but for now:

- Anything public and @inline(__always) is now also @inlinable
- Anything @usableFromInline and @inline(__always) is now @inlinable
2018-11-13 15:15:07 -05:00
Maxim Moiseev
a54c53580c [stdlib] Audit use of @_transparent in FP code
<rdar://problem/45140678>
2018-10-10 17:00:39 -07:00
Stephen Canon
0707ca6dac Remove concrete floating-point inits from integer types (#19624)
Also removes .gyb from FloatingPoint.swift, since we barely are using it after this change.

Rework Self._convert from integer, by making it require RawSignificand: FixedWidthInteger. This requirement should have always been there, and the existing implementaiton wouldn't have actually worked correctly without it. Making it explcit makes the implementation quite a bit simpler, which is nice.

Additionally add a  fast-path conversion that will catch all concrete integer types without needing to be a concrete implementation itself. Room for further improvement, but good start. See RandomDouble performance improvements, for example.
2018-09-30 11:57:49 -04:00