Skip to content

Commit 456a0b1

Browse files
committed
Update README with Classification, Comparison, and Constants documentation
Added documentation for three new high-value features: - Classification Functions (Section 7.12.3) - Comparison Macros (Section 7.12.14) - Mathematical Constants Updated both authoritative and ergonomic API usage examples.
1 parent 0a4c513 commit 456a0b1

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ This package provides Swift access to mathematical functions defined in **ISO/IE
1717

1818
This package provides **complete coverage** of all mathematical functions defined in ISO/IEC 9899:2018 Section 7.12.
1919

20+
### Classification Functions (Section 7.12.3)
21+
- `fpclassify(_:)` - Classify floating-point value (normal, zero, subnormal, infinite, NaN)
22+
- `isfinite(_:)` - Test for finite value
23+
- `isinf(_:)` - Test for infinity
24+
- `isnan(_:)` - Test for NaN
25+
- `isnormal(_:)` - Test for normal value
26+
- `signbit(_:)` - Test sign bit
27+
2028
### Trigonometric Functions (Section 7.12.4)
2129
- `sin(_:)`, `cos(_:)`, `tan(_:)` - Basic trigonometric functions
2230
- `asin(_:)`, `acos(_:)`, `atan(_:)` - Inverse trigonometric functions
@@ -65,6 +73,23 @@ This package provides **complete coverage** of all mathematical functions define
6573
### Floating Multiply-Add (Section 7.12.13)
6674
- `fma(_:_:_:)` - Fused multiply-add with single rounding
6775

76+
### Comparison Macros (Section 7.12.14)
77+
- `isgreater(_:_:)` - Quiet > comparison (no exception on NaN)
78+
- `isgreaterequal(_:_:)` - Quiet >= comparison
79+
- `isless(_:_:)` - Quiet < comparison
80+
- `islessequal(_:_:)` - Quiet <= comparison
81+
- `islessgreater(_:_:)` - Quiet != comparison
82+
- `isunordered(_:_:)` - Test for unordered (NaN) arguments
83+
84+
### Mathematical Constants
85+
- Fundamental: π, e, τ
86+
- Square roots: √2, √3, √5, 1/√2
87+
- Logarithms: ln(2), ln(10), log₂(e), log₁₀(e), log₂(10)
88+
- Golden ratio: φ
89+
- Angular conversions: degrees ↔ radians
90+
- Common π fractions: π/2, π/3, π/4, π/6, 2π
91+
- Euler-Mascheroni: γ
92+
6893
All functions implement IEEE 754 semantics per Annex F.
6994

7095
## Usage
@@ -101,6 +126,23 @@ let floored = ISO_9899.Math.floor(2.7) // 2.0
101126
let nearest = ISO_9899.Math.round(2.5) // 3.0 (ties away from zero)
102127
let truncated = ISO_9899.Math.trunc(-2.7) // -2.0
103128

129+
// Classification functions
130+
let classification = ISO_9899.Math.fpclassify(1.0) // .normal
131+
let isFinite = ISO_9899.Math.isfinite(.infinity) // false
132+
let isNaN = ISO_9899.Math.isnan(.nan) // true
133+
let signBit = ISO_9899.Math.signbit(-0.0) // true
134+
135+
// Comparison functions (quiet - no exception on NaN)
136+
let greater = ISO_9899.Math.isgreater(5.0, 3.0) // true
137+
let lessOrGreater = ISO_9899.Math.islessgreater(.nan, 5.0) // false
138+
let unordered = ISO_9899.Math.isunordered(.nan, 5.0) // true
139+
140+
// Mathematical constants
141+
let circumference = 2 * ISO_9899.Math.Constants.pi * radius
142+
let radians = degrees * ISO_9899.Math.Constants.degreesToRadians
143+
let sqrt2 = ISO_9899.Math.Constants.sqrt2
144+
let goldenRatio = ISO_9899.Math.Constants.phi
145+
104146
// Works with Float too
105147
let f: Float = ISO_9899.Math.sin(Float.pi / 4)
106148
```
@@ -137,6 +179,17 @@ let floor = (2.7).c.floor // 2.0
137179
let round = (2.5).c.round // 3.0
138180
let trunc = (-2.7).c.trunc // -2.0
139181

182+
// Classification functions
183+
let classification = (1.0).c.fpclassify // .normal
184+
let isFinite = Double.infinity.c.isfinite // false
185+
let isNaN = Double.nan.c.isnan // true
186+
let signBit = (-0.0).c.signbit // true
187+
188+
// Comparison functions (quiet - no exception on NaN)
189+
let greater = (5.0).c.isgreater(3.0) // true
190+
let lessOrGreater = Double.nan.c.islessgreater(5.0) // false
191+
let unordered = Double.nan.c.isunordered(5.0) // true
192+
140193
// Works with Float too
141194
let y: Float = 1.5
142195
let result = y.c.sqrt // 1.22474487

0 commit comments

Comments
 (0)