ayush00git opened a new pull request, #3336:
URL: https://github.com/apache/fory/pull/3336

   ## Why?
   
   As requested in Issue #3209, Dart implementation was missing support for 
IEEE 754 half-precision floating-point (Float16) types that are already 
available in other Fory language implementations (Rust, Go, C++, Python). This 
PR adds complete Float16 support for Dart.
   
   ## What does this PR do?
   
   This PR implements schema-based support for IEEE 754 Float16 types in the 
Fory Dart library:
   
   ### Added Types
   
   - `float16`
   
   ### Changes Made
   
   #### 1. `lib/src/datatype/float16.dart`
   Implemented the `Float16` class which wraps a 16-bit integer and handles 
IEEE 754 conversions (handling rounding, subnormals, signed zeros, 
NaN/Infinity):
   
   ```dart
   final class Float16 extends FixedNum {
     final int _bits;
     // ...
     factory Float16(num value) => Float16.fromDouble(value.toDouble());
     double toDouble() => _bitsToDouble(_bits);
   }
   ```
   
   #### 2. `lib/src/memory/`
   Added read/write support for 16-bit floats in `ByteReader` and `ByteWriter`:
   
   ```dart
   void writeFloat16(Float16 value);
   Float16 readFloat16();
   ```
   
   #### 3. `lib/src/serializer/`
   Registered `Float16Serializer` to handle serialization of `Float16` types in 
`PrimitiveTypeSerializer`:
   
   ```dart
   typeToTypeInfo[Float16]!.serializer = 
Float16Serializer.cache.getSerializer(conf);
   ```
   
   #### 4. `lib/src/const/dart_type.dart`
   Added `FLOAT16` to `DartTypeEnum` for type inference and registry.
   
   ### Usage Example
   
   ```dart
   import 'package:fory/src/datatype/float16.dart'; 
   import 'package:fory/src/memory/byte_writer.dart';
   
   var val = Float16(1.5);
   print(val.toDouble())
   
   // Handling limits and edge cases
   var max = Float16(65504.0);
   var inf = Float16(65505.0);
   var subnormal = Float16(0.0000000596046);
   
   // Serialization
   var bw = ByteWriter();
   bw.writeFloat16(val);
   ```
   
   ## Related issues
   
   - Closes #3209
   
   ## Does this PR introduce any user-facing change?
   
   - [x] **Does this PR introduce any public API change?**
     - **Yes**: Adds `Float16` class and corresponding `NumType.float16`.
     - **Yes**: Adds `readFloat16` / `writeFloat16` to memory interfaces.
     - **Yes**: Exports `Float16` for user consumption.
     
   - [x] **Does this PR introduce any binary protocol compatibility change?**
     - **Yes**: Adds support for TypeId 17 (Float16).
     - **Cross-language compatible**: Uses the same TypeId values as other Fory 
implementations.
   
   ## Benchmark
   
   N/A
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to