godot icon indicating copy to clipboard operation
godot copied to clipboard

Add `get_half` and `put_half` on `StreamPeer`

Open theraot opened this issue 2 years ago • 2 comments

This pull request implements get_half and put_half, closes https://github.com/godotengine/godot-proposals/discussions/5983

The code is using Math::half_to_float and Math::make_half_float.

Using them results - as expected - in lose of precision.

This is an example script that uses them:

	var peer := StreamPeerBuffer.new()
	var input_value := 15.1234
	var expected_value := 15.1171875
	prints(peer.get_size() == 0)
	peer.put_half(input_value)
	prints(peer.get_size() == 2)
	peer.seek(0)
	prints(peer.get_half() == expected_value)

The output should be:

true
true
true

theraot avatar Jun 30 '23 13:06 theraot

I don't know.

theraot avatar Aug 03 '23 02:08 theraot

If the changes in this PR are still wanted, I can try to rebase with the latest changes on master after https://github.com/godotengine/godot/pull/95784 got merged (in order to be able to add tests for this two new methods) BTW, the rebase will require that I create a new PR with this changes. @theraot if you agree with that I'll add you as a Co-Author of that PR because most of the code will be yours.

pafuent avatar Sep 30 '24 20:09 pafuent

@pafuent you can go ahead.

theraot avatar Sep 30 '24 22:09 theraot

  • Superseded by https://github.com/godotengine/godot/pull/97716. Thanks for the contribution nonetheless!

Calinou avatar Mar 02 '25 16:03 Calinou