Skip to content

feat(dart): add bfloat16 and bfloat16_array support#3564

Open
miantalha45 wants to merge 1 commit intoapache:mainfrom
miantalha45:dart-bfloat16
Open

feat(dart): add bfloat16 and bfloat16_array support#3564
miantalha45 wants to merge 1 commit intoapache:mainfrom
miantalha45:dart-bfloat16

Conversation

@miantalha45
Copy link
Copy Markdown
Contributor

@miantalha45 miantalha45 commented Apr 14, 2026

Summary

  • Add BFloat16 type class with IEEE 754 bfloat16 conversions (round-to-nearest, ties-to-even).
  • Add bfloat16 (type ID 18) and bfloat16_array (type ID 54) to the Dart type system, serializers, buffer, codegen, and type resolver
  • Add 22 tests covering scalar conversions (±0, ±Inf, NaN, subnormals, min/max normal), rounding, equality, buffer round-trips, and packed array serialization

Changes

File Change
lib/src/types/bfloat16.dart New BFloat16 class with fromBits, fromFloat32, toBits, toDouble
lib/src/buffer.dart writeBfloat16() / readBfloat16()
lib/src/resolver/type_resolver.dart TypeIds.bfloat16=18, TypeIds.bfloat16Array=54, all resolution paths
lib/src/serializer/primitive_serializers.dart bfloat16Serializer constant, write/read cases
lib/src/codegen/fory_generator.dart All codegen paths for bfloat16/bfloat16_array
lib/src/codegen/generated_support.dart Cursor writeBfloat16() / readBfloat16()
lib/src/context/write_context.dart writeBfloat16() method
lib/src/context/read_context.dart readBfloat16() method
lib/src/meta/type_meta.dart Wire type checks for bfloat16/bfloat16Array
lib/fory.dart Public export of bfloat16.dart
test/bfloat16_test.dart 22 tests

Test plan

  • All 22 new bfloat16 tests pass (dart test test/bfloat16_test.dart)
  • All existing tests still pass (dart test)
  • dart analyze clean (only pre-existing issues)

AI Assistance Checklist

  • Substantial AI assistance was used in this PR (yes)
  • I included the standardized AI Usage Disclosure block below
  • I can explain and defend all important changes without AI help
  • I reviewed AI-assisted code changes line by line before submission
  • I ran adequate human verification and recorded evidence (local/CI checks, pass/fail summary, and review confirmation)
  • I added/updated tests and specs where required
  • I validated protocol/performance impacts with evidence when applicable
  • I verified licensing and provenance compliance

AI Usage Disclosure

  • substantial_ai_assistance: yes
  • scope: <design drafting | code drafting>

AI Review Comments

Claude Code:

Skill Review

The implementation is correct and complete. Type IDs match the spec (18/54), conversion logic matches the JS reference exactly, all codegen/resolver/serializer/context/cursor paths are covered, and all 31 tests pass (22 new + 9 existing).

General Review

The investigation found 3 critical missing changes and 1 design gap: generated_support.dart - Missing writeBfloat16() / readBfloat16() on cursors (codegen will fail) write_context.dart - Missing writeBfloat16() read_context.dart - Missing readBfloat16() These are now all fixed.

Fixes #3287

@chaokunyang
Copy link
Copy Markdown
Collaborator

where is ai review comments?

@miantalha45
Copy link
Copy Markdown
Contributor Author

Adding AI Review comments

@miantalha45
Copy link
Copy Markdown
Contributor Author

where is ai review comments?

Added

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.

[Dart] add bfloat16 and bfloat16_array

2 participants