Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions docs/api/constants_api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Constants Reference

Pre-defined mathematical constants with quad precision accuracy.

## Mathematical Constants

```{eval-rst}
.. data:: numpy_quaddtype.pi

The mathematical constant :math:`\pi` (pi).

:value: 3.14159265358979323846264338327950288...

:type: QuadPrecision

.. data:: numpy_quaddtype.e

Euler's number :math:`e`, the base of natural logarithms.

:value: 2.71828182845904523536028747135266249...

:type: QuadPrecision

.. data:: numpy_quaddtype.log2e

The base-2 logarithm of :math:`e`: :math:`\log_{2}{e}`.

:value: 1.44269504088896340735992468100189213...

:type: QuadPrecision

.. data:: numpy_quaddtype.log10e

The base-10 logarithm of :math:`e`: :math:`\log_{10}{e}`.

:value: 0.43429448190325182765112891891660508...

:type: QuadPrecision

.. data:: numpy_quaddtype.ln2

The natural logarithm of 2: :math:`\log_{e}{2}`.

:value: 0.69314718055994530941723212145817656...

:type: QuadPrecision

.. data:: numpy_quaddtype.ln10

The natural logarithm of 10: :math:`\log_{e}{10}`.

:value: 2.30258509299404568401799145468436420...

:type: QuadPrecision
```

## Type Limits

```{eval-rst}
.. data:: numpy_quaddtype.epsilon

Machine epsilon: the smallest positive number such that :math:`1.0 + \epsilon \neq 1.0`.

:value: :math:`2^{-112}` or approximately :math:`1.93 \cdot 10^{-34}`

:type: QuadPrecision

.. data:: numpy_quaddtype.max_value

The largest representable finite quad-precision value.

The largest negative representable finite quad-precision value is ``-numpy_quaddtype.max_value``.

:value: :math:`216383 \cdot (2 - 2^{-112})` or approximately :math:`1.19 \cdot 10^{4932}`

:type: QuadPrecision

.. data:: numpy_quaddtype.smallest_normal

The smallest positive normal (normalized, mantissa has a leading 1 bit) quad-precision value.

:value: :math:`2^{-16382} \cdot (1 - 2^{-112})` or approximately :math:`3.36 \cdot 10^{-4932}`

:type: QuadPrecision

.. data:: numpy_quaddtype.smallest_subnormal

The smallest positive subnormal (denormalized, mantissa has a leading 0 bit) quad-precision value.

:value: :math:`2^{-16494}` or approximately :math:`6.48 \cdot 10^{-4966}`

:type: QuadPrecision

.. data:: numpy_quaddtype.resolution

The approximate decimal resolution of quad precision, i.e. `10 ** (-precision)`.

:value: :math:`10^{-33}`

:type: QuadPrecision
```

## Type Information

```{eval-rst}
.. data:: numpy_quaddtype.bits

The total number of bits in quad precision representation.

:value: 128
:type: int

.. data:: numpy_quaddtype.precision

The approximate number of significant decimal digits.

:value: 33
:type: int
```

## Example Usage

```python
from numpy_quaddtype import (
pi, e, log2e, log10e, ln2, ln10,
epsilon, max_value, smallest_normal,
bits, precision
)

# Mathematical constants
print(f"π = {pi}")
print(f"e = {e}")

# Verify relationships
import numpy as np
from numpy_quaddtype import QuadPrecDType

# e^(ln2) should equal 2
two = np.exp(np.array(ln2))
print(f"e^(ln2) = {two}")

# log2(e) * ln(2) should equal 1
one = log2e * ln2
print(f"log2(e) × ln(2) = {one}")

# Type limits
print(f"\nQuad precision uses {bits} bits")
print(f"Approximately {precision} decimal digits of precision")
print(f"Machine epsilon: {epsilon}")
```
185 changes: 185 additions & 0 deletions docs/api/core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# Core Types

The fundamental types provided by NumPy QuadDType.

## Quad Precision Value

```{eval-rst}
.. class:: numpy_quaddtype.QuadPrecision(value, backend="sleef")

A quad-precision (128-bit) floating-point scalar.

QuadPrecision is a NumPy scalar type that provides IEEE 754 binary128
floating-point arithmetic. It can be used standalone or as elements
of NumPy arrays.

:param value: The value to convert to quad precision. It can be:

- ``float`` or ``int``: Python numeric types
- ``str``: String representation for maximum precision
- ``bytes``: Raw 16-byte representation
- ``numpy.floating`` or ``numpy.integer``: NumPy numeric types
- ``QuadPrecision``: Another QuadPrecision value
:type value: float, int, str, bytes, numpy scalar, or QuadPrecision

:param backend: Computation backend to use. Either ``"sleef"`` (default)
or ``"longdouble"``.
:type backend: str, optional

**Examples**

Create from different input types::

>>> from numpy_quaddtype import QuadPrecision
>>> QuadPrecision(3.14)
QuadPrecision('3.14000000000000012434...')
>>> QuadPrecision("3.14159265358979323846264338327950288")
QuadPrecision('3.14159265358979323846264338327950288')
>>> QuadPrecision(42)
QuadPrecision('42.0')

Arithmetic operations::

>>> x = QuadPrecision("1.5")
>>> y = QuadPrecision("2.5")
>>> x + y
QuadPrecision('4.0')
>>> x * y
QuadPrecision('3.75')

.. attribute:: dtype
:type: QuadPrecDType

The NumPy dtype for this scalar.

.. attribute:: real
:type: QuadPrecision

The real part (always self for QuadPrecision).

.. attribute:: imag
:type: QuadPrecision

The imaginary part (always zero for QuadPrecision).
```

## Quad Precision DType

```{eval-rst}
.. class:: numpy_quaddtype.QuadPrecDType(backend="sleef")

NumPy dtype for quad-precision floating-point arrays.

QuadPrecDType is a custom NumPy dtype that enables the creation and
manipulation of arrays containing quad-precision values.

:param backend: Computation backend. Either ``"sleef"`` (default) or
``"longdouble"``.
:type backend: str, optional

**Examples**

Create arrays with QuadPrecDType::

>>> import numpy as np
>>> from numpy_quaddtype import QuadPrecDType
>>> arr = np.array([1, 2, 3], dtype=QuadPrecDType())
>>> arr.dtype
QuadPrecDType128
>>> np.zeros(5, dtype=QuadPrecDType())
array([0.0, 0.0, 0.0, 0.0, 0.0], dtype=QuadPrecDType128)

.. attribute:: backend
:type: QuadBackend

The computation backend (``SLEEF`` or ``LONGDOUBLE``).

.. attribute:: itemsize
:type: int

The size of each element in bytes (always 16).

.. attribute:: alignment
:type: int

The memory alignment in bytes (always 16).

.. attribute:: name
:type: str

The string name of the dtype (``"QuadPrecDType128"``).
```

```{eval-rst}
.. class:: numpy_quaddtype.QuadBackend

Enumeration of available computation backends.

.. attribute:: SLEEF
:value: 0

SLEEF library backend (default). Provides true IEEE 754 binary128
quad precision with SIMD optimization.

.. attribute:: LONGDOUBLE
:value: 1

The platform's native long double backend. The precision varies by platform.

**Example**

::

>>> from numpy_quaddtype import QuadPrecDType, QuadBackend
>>> dtype = QuadPrecDType()
>>> dtype.backend == QuadBackend.SLEEF
True
```

## Convenience Functions

```{eval-rst}
.. function:: numpy_quaddtype.SleefQuadPrecision(value)

Create a QuadPrecision scalar using the SLEEF backend.

Equivalent to ``QuadPrecision(value, backend="sleef")``.

:param value: Value to convert to quad precision.
:return: Quad precision scalar using SLEEF backend.
:rtype: QuadPrecision
```

```{eval-rst}
.. function:: numpy_quaddtype.LongDoubleQuadPrecision(value)

Create a QuadPrecision scalar using the longdouble backend.

Equivalent to ``QuadPrecision(value, backend="longdouble")``.

:param value: Value to convert to quad precision.
:return: Quad precision scalar using longdouble backend.
:rtype: QuadPrecision
```

```{eval-rst}
.. function:: numpy_quaddtype.SleefQuadPrecDType()

Create a QuadPrecDType using the SLEEF backend.

Equivalent to ``QuadPrecDType(backend="sleef")``.

:return: Dtype for SLEEF-backed quad precision arrays.
:rtype: QuadPrecDType
```

```{eval-rst}
.. function:: numpy_quaddtype.LongDoubleQuadPrecDType()

Create a QuadPrecDType using the longdouble backend.

Equivalent to ``QuadPrecDType(backend="longdouble")``.

:return: Dtype for longdouble-backed quad precision arrays.
:rtype: QuadPrecDType
```
Loading
Loading