Open cnordenb opened 6 months ago
I'm using the Float16Array
polyfill from here: https://github.com/petamoriken/float16. So if there's a bug with that polyfill, you should report it there instead.
However, the behavior you are describing with 16-bit seems consistent with 32-bit and 64-bit, so it doesn't appear to be a bug:
0 11111 0000000000 in 16-bit is infinity
> console.log(new Float16Array(new Int16Array([0b0_11111_0000000000]).buffer)[0])
Infinity
0 11111111 00000000000000000000000 in 32-bit is infinity
> console.log(new Float32Array(new Int32Array([0b0_11111111_00000000000000000000000]).buffer)[0])
Infinity
0 11111111111 0000000000000000000000000000000000000000000000000000 in 64-bit is infinity
> console.log(new Float64Array(new BigInt64Array([0b0_11111111111_0000000000000000000000000000000000000000000000000000n]).buffer)[0])
Infinity
Ah, I'm just learning computer arithmetic as a student and realised after looking more into the IEEE 754 that that is how infinity is represented as a special case but your tool didn't mention that and just reported 1 2^16 1 = infinity so I got bamboozled.
If you ever feel like adding more to your tool I think it would be very helpful for new learners if there was some sort of asterisk for the special cases explaining that the IEEE 754 format has decided to represent eg. infinity with those particular bits.
Thank you for making this, it's very helpful getting familiarised with how the float works in an interactive way!
0 11111 0000000000 in 16 bit float should read 65536. This web app claims it is infinity.