dart-lang / core

This repository is home to core Dart packages.
https://pub.dev/publishers/dart.dev
BSD 3-Clause "New" or "Revised" License
19 stars 7 forks source link

Reading float32 introduces extra precision #575

Closed aeb-dev closed 1 year ago

aeb-dev commented 1 year ago

I am not sure if this is a bug

var f = 1.23;
var l = Uint8List(4);
l.buffer.asByteData().setFloat32(0, f);
var v = l.buffer.asByteData().getFloat32(0);
print("f: $f, v: $v");

Output: f: 1.23, v: 1.2300000190734863

I thought this might be a bug because float32 supports 8 digit fraction but the fraction continues after 8 digit (I mean this part: 190734863), but float should not support(?) those values. So, If I read a float32 I should not be getting float64.