Skip to content

Conversation

hpkfft
Copy link
Contributor

@hpkfft hpkfft commented Aug 5, 2025

Since it is recommended that portable code use the _Float16 type defined by ISO/IEC TS 18661-3:2015, it is probably better to update the example in the nanobind docs accordingly.

@wjakob
Copy link
Owner

wjakob commented Aug 6, 2025

AFAIK _Float16 was added in C++23. It is not part of C++17.

@wjakob wjakob closed this Aug 6, 2025
@wjakob wjakob reopened this Aug 6, 2025
@wjakob
Copy link
Owner

wjakob commented Aug 6, 2025

(Sorry for closing the PR, I got confused between tabs)

@hpkfft
Copy link
Contributor Author

hpkfft commented Aug 6, 2025

C++23 added std::float16_t.
The type _Float16 was added to C in the 2015 technical spec (TS) listed above, and C++ recommended that compilers that support both C and C++ support _Float16 for C++ as well.
I think, more importantly, that the existing nanobind example uses __fp16, which is not part of any ISO specification. It is just an example showing how nanobind can support an implementation-dependent data type. In the past, ARM recommended its use. After _Float16 became standardized, ARM recommended that instead. So, I think it would be a kindness to gently steer readers to use _Float16.

@hpkfft
Copy link
Contributor Author

hpkfft commented Aug 6, 2025

BTW, the C++23 extended floating point type std::float16_t is intended to be the same as _Float16.

Recommended practice: Any names that the implementation provides for the extended floating-point types described in this subsection that are in addition to the names declared in the <stdfloat> header should be chosen to increase compatibility and interoperability with the interchange types _Float16, _Float32, _Float64, and _Float128 defined in ISO/IEC TS 18661-3 and with future versions of ISO/IEC 9899

@wjakob
Copy link
Owner

wjakob commented Aug 6, 2025

OK, fair enough!

@wjakob wjakob merged commit 538f4c1 into wjakob:master Aug 6, 2025
60 checks passed
@hpkfft hpkfft deleted the float16 branch August 6, 2025 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants