Skip to content

Commit 6f01285

Browse files
committed
opus wrote the content
1 parent b266dc6 commit 6f01285

20 files changed

Lines changed: 2618 additions & 9 deletions
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Constants Reference
2+
3+
Pre-defined mathematical constants with quad precision accuracy.
4+
5+
## Mathematical Constants
6+
7+
```{eval-rst}
8+
.. data:: numpy_quaddtype.pi
9+
10+
The mathematical constant π (pi).
11+
12+
Value: 3.14159265358979323846264338327950288...
13+
14+
:type: QuadPrecision
15+
16+
.. data:: numpy_quaddtype.e
17+
18+
Euler's number, the base of natural logarithms.
19+
20+
Value: 2.71828182845904523536028747135266249...
21+
22+
:type: QuadPrecision
23+
24+
.. data:: numpy_quaddtype.log2e
25+
26+
The base-2 logarithm of e: log₂(e).
27+
28+
Value: 1.44269504088896340735992468100189213...
29+
30+
:type: QuadPrecision
31+
32+
.. data:: numpy_quaddtype.log10e
33+
34+
The base-10 logarithm of e: log₁₀(e).
35+
36+
Value: 0.43429448190325182765112891891660508...
37+
38+
:type: QuadPrecision
39+
40+
.. data:: numpy_quaddtype.ln2
41+
42+
The natural logarithm of 2: ln(2).
43+
44+
Value: 0.69314718055994530941723212145817656...
45+
46+
:type: QuadPrecision
47+
48+
.. data:: numpy_quaddtype.ln10
49+
50+
The natural logarithm of 10: ln(10).
51+
52+
Value: 2.30258509299404568401799145468436420...
53+
54+
:type: QuadPrecision
55+
```
56+
57+
## Type Limits
58+
59+
```{eval-rst}
60+
.. data:: numpy_quaddtype.epsilon
61+
62+
Machine epsilon: the smallest positive number such that 1.0 + epsilon ≠ 1.0.
63+
64+
Approximately 1.93 × 10⁻³⁴.
65+
66+
:type: QuadPrecision
67+
68+
.. data:: numpy_quaddtype.max_value
69+
70+
The largest representable finite quad-precision value.
71+
72+
Approximately 1.19 × 10⁴⁹³².
73+
74+
:type: QuadPrecision
75+
76+
.. data:: numpy_quaddtype.smallest_normal
77+
78+
The smallest positive normalized quad-precision value.
79+
80+
Approximately 3.36 × 10⁻⁴⁹³².
81+
82+
:type: QuadPrecision
83+
84+
.. data:: numpy_quaddtype.smallest_subnormal
85+
86+
The smallest positive subnormal (denormalized) quad-precision value.
87+
88+
:type: QuadPrecision
89+
90+
.. data:: numpy_quaddtype.resolution
91+
92+
The approximate decimal resolution of quad precision.
93+
94+
:type: QuadPrecision
95+
```
96+
97+
## Type Information
98+
99+
```{eval-rst}
100+
.. data:: numpy_quaddtype.bits
101+
102+
Total number of bits in quad precision representation.
103+
104+
:value: 128
105+
:type: int
106+
107+
.. data:: numpy_quaddtype.precision
108+
109+
Approximate number of significant decimal digits.
110+
111+
:value: 33
112+
:type: int
113+
```
114+
115+
## Example Usage
116+
117+
```python
118+
from numpy_quaddtype import (
119+
pi, e, log2e, log10e, ln2, ln10,
120+
epsilon, max_value, smallest_normal,
121+
bits, precision
122+
)
123+
124+
# Mathematical constants
125+
print(f"π = {pi}")
126+
print(f"e = {e}")
127+
128+
# Verify relationships
129+
import numpy as np
130+
from numpy_quaddtype import QuadPrecDType
131+
132+
# e^(ln2) should equal 2
133+
two = np.exp(np.array([ln2]))[0]
134+
print(f"e^(ln2) = {two}")
135+
136+
# log2(e) * ln(2) should equal 1
137+
one = log2e * ln2
138+
print(f"log2(e) × ln(2) = {one}")
139+
140+
# Type limits
141+
print(f"\nQuad precision uses {bits} bits")
142+
print(f"Approximately {precision} decimal digits of precision")
143+
print(f"Machine epsilon: {epsilon}")
144+
```

quaddtype/docs/api/core.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Core Types
2+
3+
The fundamental types provided by NumPy QuadDType.
4+
5+
## QuadPrecision
6+
7+
```{eval-rst}
8+
.. class:: numpy_quaddtype.QuadPrecision(value, backend="sleef")
9+
10+
A quad-precision (128-bit) floating-point scalar.
11+
12+
QuadPrecision is a NumPy scalar type that provides IEEE 754 binary128
13+
floating-point arithmetic. It can be used standalone or as elements
14+
of NumPy arrays.
15+
16+
:param value: The value to convert to quad precision. Can be:
17+
18+
- ``float`` or ``int``: Python numeric types
19+
- ``str``: String representation for maximum precision
20+
- ``bytes``: Raw 16-byte representation
21+
- ``numpy.floating`` or ``numpy.integer``: NumPy numeric types
22+
- ``QuadPrecision``: Another QuadPrecision value
23+
24+
:type value: float, int, str, bytes, numpy scalar, or QuadPrecision
25+
:param backend: Computation backend to use. Either ``"sleef"`` (default)
26+
or ``"longdouble"``.
27+
:type backend: str, optional
28+
29+
**Examples**
30+
31+
Create from different input types::
32+
33+
>>> from numpy_quaddtype import QuadPrecision
34+
>>> QuadPrecision(3.14)
35+
QuadPrecision('3.14000000000000012434...')
36+
>>> QuadPrecision("3.14159265358979323846264338327950288")
37+
QuadPrecision('3.14159265358979323846264338327950288')
38+
>>> QuadPrecision(42)
39+
QuadPrecision('42.0')
40+
41+
Arithmetic operations::
42+
43+
>>> x = QuadPrecision("1.5")
44+
>>> y = QuadPrecision("2.5")
45+
>>> x + y
46+
QuadPrecision('4.0')
47+
>>> x * y
48+
QuadPrecision('3.75')
49+
50+
.. attribute:: dtype
51+
:type: QuadPrecDType
52+
53+
The NumPy dtype for this scalar.
54+
55+
.. attribute:: real
56+
:type: QuadPrecision
57+
58+
The real part (returns self for real numbers).
59+
60+
.. attribute:: imag
61+
:type: QuadPrecision
62+
63+
The imaginary part (always zero for QuadPrecision).
64+
```
65+
66+
## QuadPrecDType
67+
68+
```{eval-rst}
69+
.. class:: numpy_quaddtype.QuadPrecDType(backend="sleef")
70+
71+
NumPy dtype for quad-precision floating-point arrays.
72+
73+
QuadPrecDType is a custom NumPy dtype that enables creation and
74+
manipulation of arrays containing quad-precision values.
75+
76+
:param backend: Computation backend. Either ``"sleef"`` (default) or
77+
``"longdouble"``.
78+
:type backend: str, optional
79+
80+
**Examples**
81+
82+
Create arrays with QuadPrecDType::
83+
84+
>>> import numpy as np
85+
>>> from numpy_quaddtype import QuadPrecDType
86+
>>> arr = np.array([1, 2, 3], dtype=QuadPrecDType())
87+
>>> arr.dtype
88+
QuadPrecDType128
89+
>>> np.zeros(5, dtype=QuadPrecDType())
90+
array([0.0, 0.0, 0.0, 0.0, 0.0], dtype=QuadPrecDType128)
91+
92+
.. attribute:: backend
93+
:type: QuadBackend
94+
95+
The computation backend (SLEEF or LONGDOUBLE).
96+
97+
.. attribute:: itemsize
98+
:type: int
99+
100+
Size of each element in bytes (always 16).
101+
102+
.. attribute:: alignment
103+
:type: int
104+
105+
Memory alignment in bytes (always 16).
106+
107+
.. attribute:: name
108+
:type: str
109+
110+
String name of the dtype (``"QuadPrecDType128"``).
111+
```
112+
113+
## QuadBackend
114+
115+
```{eval-rst}
116+
.. class:: numpy_quaddtype.QuadBackend
117+
118+
Enumeration of available computation backends.
119+
120+
.. attribute:: SLEEF
121+
:value: 0
122+
123+
SLEEF library backend (default). Provides true IEEE 754 binary128
124+
quad precision with SIMD optimization.
125+
126+
.. attribute:: LONGDOUBLE
127+
:value: 1
128+
129+
Platform's native long double backend. Precision varies by platform.
130+
131+
**Example**
132+
133+
::
134+
135+
>>> from numpy_quaddtype import QuadPrecDType, QuadBackend
136+
>>> dtype = QuadPrecDType()
137+
>>> dtype.backend == QuadBackend.SLEEF
138+
True
139+
```
140+
141+
## Convenience Functions
142+
143+
### SleefQuadPrecision
144+
145+
```{eval-rst}
146+
.. function:: numpy_quaddtype.SleefQuadPrecision(value)
147+
148+
Create a QuadPrecision scalar using the SLEEF backend.
149+
150+
Equivalent to ``QuadPrecision(value, backend="sleef")``.
151+
152+
:param value: Value to convert to quad precision.
153+
:return: Quad precision scalar using SLEEF backend.
154+
:rtype: QuadPrecision
155+
```
156+
157+
### LongDoubleQuadPrecision
158+
159+
```{eval-rst}
160+
.. function:: numpy_quaddtype.LongDoubleQuadPrecision(value)
161+
162+
Create a QuadPrecision scalar using the longdouble backend.
163+
164+
Equivalent to ``QuadPrecision(value, backend="longdouble")``.
165+
166+
:param value: Value to convert to quad precision.
167+
:return: Quad precision scalar using longdouble backend.
168+
:rtype: QuadPrecision
169+
```
170+
171+
### SleefQuadPrecDType
172+
173+
```{eval-rst}
174+
.. function:: numpy_quaddtype.SleefQuadPrecDType()
175+
176+
Create a QuadPrecDType using the SLEEF backend.
177+
178+
Equivalent to ``QuadPrecDType(backend="sleef")``.
179+
180+
:return: Dtype for SLEEF-backed quad precision arrays.
181+
:rtype: QuadPrecDType
182+
```
183+
184+
### LongDoubleQuadPrecDType
185+
186+
```{eval-rst}
187+
.. function:: numpy_quaddtype.LongDoubleQuadPrecDType()
188+
189+
Create a QuadPrecDType using the longdouble backend.
190+
191+
Equivalent to ``QuadPrecDType(backend="longdouble")``.
192+
193+
:return: Dtype for longdouble-backed quad precision arrays.
194+
:rtype: QuadPrecDType
195+
```

0 commit comments

Comments
 (0)