feat: Add IEEE 754 float16 (binary16) support to Rust runtime#3252
feat: Add IEEE 754 float16 (binary16) support to Rust runtime#3252AshharAhmadKhan wants to merge 11 commits intoapache:mainfrom
Conversation
- Add float16 type as transparent wrapper around u16 - Implement IEEE 754 compliant f32<->float16 conversions - Round-to-nearest, ties-to-even rounding - Proper handling of NaN, Inf, ±0, subnormals - Overflow to infinity, underflow to subnormal/zero - Add buffer read/write methods (write_f16, read_f16) - Implement Serializer trait for float16 - Add float16 to all relevant type arrays and functions - Implement arithmetic via f32 round-back - Use Policy A (bitwise Eq/Hash, separate IEEE helpers) - Add comprehensive unit tests (11 tests, all passing) Resolves apache#3207
- Add #[allow(non_camel_case_types)] to float16 struct (per issue requirements) - Add #[allow(dead_code)] to EXP_BIAS constant
- Add Apache license header to number.rs (required by CI) - Suppress clippy::should_implement_trait warnings for explicit arithmetic methods (methods required by issue spec alongside trait implementations)
- Add #[allow(clippy::should_implement_trait)] to all arithmetic methods - Restore missing float16 import in number.rs - Fix formatting
|
hey @chaokunyang Should I:
Happy to resolve this whichever way you prefer. |
|
Hi @AshharAhmadKhan , I suggest to merge git main branch and only add support for |
|
Hi @chaokunyang, |
- Add float16 type as transparent wrapper around u16 - Implement IEEE 754 compliant f32<->float16 conversions - Round-to-nearest, ties-to-even rounding - Proper handling of NaN, Inf, ±0, subnormals - Overflow to infinity, underflow to subnormal/zero - Add buffer read/write methods (write_f16, read_f16) - Implement Serializer trait for float16 - Add float16 to all relevant type arrays and functions - Implement arithmetic via f32 round-back - Use Policy A (bitwise Eq/Hash, separate IEEE helpers) - Add comprehensive unit tests (11 tests, all passing) Resolves apache#3207
|
@AshharAhmadKhan Rust ci still failed, could you fix it first? |
All 400+ tests passing. Clippy clean. Ready for CI review.
|
Hi @chaokunyang, I've resolved all the Clippy warnings and formatting issues. All 56 CI checks are now passing ✅, including the previously failing Rust CI checks on macOS and Ubuntu. The implementation is ready for review. Please let me know if any additional changes are needed. Thanks! |

Summary
This PR implements full IEEE 754 half-precision (binary16)
float16support for the Rust runtime as requested in issue #3207.Implementation Details
Core Type (
fory-core/src/float16.rs)#[repr(transparent)] pub struct float16(u16)- 614 linesIntegration
buffer.rs):write_f16()andread_f16()using little-endianserializer/number.rs): FullSerializertrait +ForyDefaultimplementationtypes.rs): Added toBASIC_TYPES,PRIMITIVE_TYPES,PRIMITIVE_ARRAY_TYPES,BASIC_TYPE_NAMES,PRIMITIVE_ARRAY_TYPE_MAP,is_primitive_type_id()lib.rs): Public module withFloat16aliasTesting
Why?
Support for half-precision floats is essential for:
What does this PR do?
Adds production-ready IEEE 754 binary16 support to Rust runtime matching the exact specification in #3207, including:
Related issues
Closes #3207
Does this PR introduce any user-facing change?
Does this PR introduce any public API change?
float16(exported asFloat16)from_bits,to_bits,from_f32,to_f32, classification methods, arithmetic methodsZERO,NEG_ZERO,INFINITY,NEG_INFINITY,NAN,MAX,MIN_POSITIVE,MIN_POSITIVE_SUBNORMALDoes this PR introduce any binary protocol compatibility change?
FLOAT16(TypeId = 16) andFLOAT16_ARRAY(TypeId = 50) to wire formatBenchmark
Not applicable - this PR adds new functionality without modifying existing code paths. No performance impact on existing f32/f64 usage.