﻿# CUB radix-sort bit ranges apply after floating-point key transformation

Understand CUB DeviceRadixSort floating-point transformations, partial-bit sorting, stable equivalent keys, and why NaN ordering needs an application policy.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-cub-radix-sort-transformed-bit-range/
Language: en

## Sorting fewer bits changes the key definition

A GPU ranking stage may use `cub::DeviceRadixSort` and restrict `begin_bit` and `end_bit` to reduce the compared key domain. For floating-point inputs, those indices should not be interpreted as a direct request to compare an arbitrary field of the original representation.

The [DeviceRadixSort reference](https://nvidia.github.io/cccl/unstable/cub/api/structcub_1_1DeviceRadixSort.html) describes transformations used to create radix-sortable keys. The referenced development documentation and repository branch should be matched to the installed CCCL version.

## Transformation precedes bit truncation

The [implementation header documentation](https://raw.githubusercontent.com/NVIDIA/cccl/main/cub/cub/device/device_radix_sort.cuh) specifies that type-specific transformations happen before restriction to the selected bit interval. Positive floating-point values invert the sign bit; negative values invert the complete key for ascending ordering.

Therefore, a partial-bit comparison defines equivalence in transformed-key space. It need not express the application notion of rounding, numeric buckets, or similarity. If bucketing is the intended algorithm, define its key explicitly and verify that its ordering matches the required semantics.

## Stability concerns the compared key

Stable sorting preserves input order among keys considered equal by the sorting operation. When only a bit subrange participates, different original values can compare equal within that subrange. Their retained input order is not evidence of a hidden full-value secondary sort.

For key-value sorting, attach original item identities and verify that values follow their keys. The [tensor-axis guide](/journal/tensor-axes-batch-sequence-hidden/) provides a related principle: an array position and an application identity are different pieces of metadata.

## Special floating-point values need explicit expectations

The documented contract treats positive and negative zero as equivalent and describes NaN ordering through transformed bit representations rather than a separate semantic NaN policy. An application that needs missing scores first or last should establish that policy before relying on numeric-looking output.

The official [custom-key example](https://raw.githubusercontent.com/NVIDIA/cccl/main/cub/examples/device/example_device_radix_sort_custom.cu) illustrates the importance of bit-ordered representation. It is an explanatory example, not a universal prescription for missing-value handling.

## Test ordering and identity together

Construct cases with repeated compared keys, mixed signs, both zero signs, and relevant non-finite values. Compare against a host reference implementing the same transformation and selected interval, not an ordinary full floating-point sort.

Record key type, interval, direction, and CCCL revision in the [GPU evidence record](/journal/gpu-acceptance-evidence/). A shorter sort interval is an algorithmic choice whose correctness must be established before its performance is evaluated.
