> ## Documentation Index
> Fetch the complete documentation index at: https://numpyts.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Floating-Point Operations

> Low-level floating-point inspection and manipulation: sign copying, sign-bit testing, ULP stepping, and dtype promotion.

### copysign

Return element-wise values of `x1` with the sign of `x2`. Inputs are broadcast together.

```typescript theme={null}
function copysign(x1: NDArray, x2: NDArray | number): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | -- | Values whose magnitudes are used. |
| `x2` | `NDArray` | -- | Values whose signs are copied. |

**Returns:** `NDArray` -- Array with magnitudes from `x1` and signs from `x2`.

```typescript theme={null}
import * as np from 'numpy-ts';

np.copysign(np.array([1, -2, 3]), np.array([-1, 1, -1]));
// array([-1, 2, -3])

// Broadcasting with a scalar
np.copysign(np.array([1, 2, 3]), -1);
// array([-1, -2, -3])
```

***

### signbit

Return element-wise `true` where the sign bit is set (i.e., the value is negative). This correctly detects `-0.0`.

```typescript theme={null}
function signbit(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |

**Returns:** `NDArray` -- Boolean array, `true` where the sign bit is set.

```typescript theme={null}
import * as np from 'numpy-ts';

np.signbit(np.array([-1, 0, 1, -0.0]));
// array([true, false, false, true])

np.signbit(np.array([-Infinity, Infinity]));
// array([true, false])
```

***

### nextafter

Return the next representable floating-point value after `x1` towards `x2`, element-wise. Inputs are broadcast together.

```typescript theme={null}
function nextafter(x1: NDArray, x2: NDArray | number): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x1` | `NDArray` | -- | Starting values. |
| `x2` | `NDArray` | -- | Direction values. |

**Returns:** `NDArray` -- The next representable float after each `x1[i]` in the direction of `x2[i]`.

```typescript theme={null}
import * as np from 'numpy-ts';

// Smallest float greater than 1.0
const eps = np.nextafter(np.array([1.0]), np.array([2.0]));
// array([1.0000000000000002])

// Largest float less than 1.0
const before = np.nextafter(np.array([1.0]), np.array([0.0]));
// array([0.9999999999999998])
```

***

### spacing

Return the distance between each element and the nearest adjacent representable floating-point number. This is the ULP (unit in the last place) of each value.

```typescript theme={null}
function spacing(x: NDArray): NDArray
```

| Name | Type | Default | Description |
| - | - | - | - |
| `x` | `NDArray` | -- | Input array. |

**Returns:** `NDArray` -- The spacing (ULP) for each element.

```typescript theme={null}
import * as np from 'numpy-ts';

np.spacing(np.array([1.0]));
// array([2.220446049250313e-16])  -- machine epsilon

np.spacing(np.array([1e10]));
// array([0.0000019073486328125])  -- larger spacing for larger values
```

***

### promote\_types

Return the smallest dtype to which both input dtypes can be safely cast. This follows NumPy's type promotion rules.

```typescript theme={null}
function promote_types(dtype1: DType, dtype2: DType): DType
```

| Name | Type | Default | Description |
| - | - | - | - |
| `dtype1` | `DType` | -- | First dtype. |
| `dtype2` | `DType` | -- | Second dtype. |

**Returns:** `DType` -- The promoted dtype that can represent values from both input dtypes without loss.

```typescript theme={null}
import * as np from 'numpy-ts';

np.promote_types('int32', 'float32');
// 'float64'

np.promote_types('int8', 'int16');
// 'int16'

np.promote_types('float32', 'float64');
// 'float64'

np.promote_types('bool', 'int32');
// 'int32'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.