|
| 1 | +# Core Types |
| 2 | + |
| 3 | +The fundamental types provided by NumPy QuadDType. |
| 4 | + |
| 5 | +## Quad Precision Value |
| 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. It 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 | + :type value: float, int, str, bytes, numpy scalar, or QuadPrecision |
| 24 | +
|
| 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 (always self for QuadPrecision). |
| 59 | +
|
| 60 | + .. attribute:: imag |
| 61 | + :type: QuadPrecision |
| 62 | +
|
| 63 | + The imaginary part (always zero for QuadPrecision). |
| 64 | +``` |
| 65 | + |
| 66 | +## Quad Precision DType |
| 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 the 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 | + The size of each element in bytes (always 16). |
| 101 | +
|
| 102 | + .. attribute:: alignment |
| 103 | + :type: int |
| 104 | +
|
| 105 | + The memory alignment in bytes (always 16). |
| 106 | +
|
| 107 | + .. attribute:: name |
| 108 | + :type: str |
| 109 | +
|
| 110 | + The string name of the dtype (``"QuadPrecDType128"``). |
| 111 | +``` |
| 112 | + |
| 113 | +```{eval-rst} |
| 114 | +.. class:: numpy_quaddtype.QuadBackend |
| 115 | +
|
| 116 | + Enumeration of available computation backends. |
| 117 | +
|
| 118 | + .. attribute:: SLEEF |
| 119 | + :value: 0 |
| 120 | +
|
| 121 | + SLEEF library backend (default). Provides true IEEE 754 binary128 |
| 122 | + quad precision with SIMD optimization. |
| 123 | +
|
| 124 | + .. attribute:: LONGDOUBLE |
| 125 | + :value: 1 |
| 126 | +
|
| 127 | + The platform's native long double backend. The precision varies by platform. |
| 128 | +
|
| 129 | + **Example** |
| 130 | +
|
| 131 | + :: |
| 132 | +
|
| 133 | + >>> from numpy_quaddtype import QuadPrecDType, QuadBackend |
| 134 | + >>> dtype = QuadPrecDType() |
| 135 | + >>> dtype.backend == QuadBackend.SLEEF |
| 136 | + True |
| 137 | +``` |
| 138 | + |
| 139 | +## Convenience Functions |
| 140 | + |
| 141 | +```{eval-rst} |
| 142 | +.. function:: numpy_quaddtype.SleefQuadPrecision(value) |
| 143 | +
|
| 144 | + Create a QuadPrecision scalar using the SLEEF backend. |
| 145 | +
|
| 146 | + Equivalent to ``QuadPrecision(value, backend="sleef")``. |
| 147 | +
|
| 148 | + :param value: Value to convert to quad precision. |
| 149 | + :return: Quad precision scalar using SLEEF backend. |
| 150 | + :rtype: QuadPrecision |
| 151 | +``` |
| 152 | + |
| 153 | +```{eval-rst} |
| 154 | +.. function:: numpy_quaddtype.LongDoubleQuadPrecision(value) |
| 155 | +
|
| 156 | + Create a QuadPrecision scalar using the longdouble backend. |
| 157 | +
|
| 158 | + Equivalent to ``QuadPrecision(value, backend="longdouble")``. |
| 159 | +
|
| 160 | + :param value: Value to convert to quad precision. |
| 161 | + :return: Quad precision scalar using longdouble backend. |
| 162 | + :rtype: QuadPrecision |
| 163 | +``` |
| 164 | + |
| 165 | +```{eval-rst} |
| 166 | +.. function:: numpy_quaddtype.SleefQuadPrecDType() |
| 167 | +
|
| 168 | + Create a QuadPrecDType using the SLEEF backend. |
| 169 | +
|
| 170 | + Equivalent to ``QuadPrecDType(backend="sleef")``. |
| 171 | +
|
| 172 | + :return: Dtype for SLEEF-backed quad precision arrays. |
| 173 | + :rtype: QuadPrecDType |
| 174 | +``` |
| 175 | + |
| 176 | +```{eval-rst} |
| 177 | +.. function:: numpy_quaddtype.LongDoubleQuadPrecDType() |
| 178 | +
|
| 179 | + Create a QuadPrecDType using the longdouble backend. |
| 180 | +
|
| 181 | + Equivalent to ``QuadPrecDType(backend="longdouble")``. |
| 182 | +
|
| 183 | + :return: Dtype for longdouble-backed quad precision arrays. |
| 184 | + :rtype: QuadPrecDType |
| 185 | +``` |
0 commit comments