-
-
Notifications
You must be signed in to change notification settings - Fork 705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix issue 19208 - swapEndian doesn't support floating point types #6720
Conversation
|
Thanks for your pull request and interest in making D better, @bbasile! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + phobos#6720" |
std/bitmanip.d
Outdated
| T swapEndian(T)(T val) @safe pure nothrow @nogc | ||
| if (isIntegral!T || isSomeChar!T || isBoolean!T) | ||
| T swapEndian(T)(const T val) @safe pure nothrow @nogc | ||
| if (canSwapEndianness!T) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that return type T may not work properly for floats. From the documentation of bigEndianToNative:
/++
...
Taking a `ubyte[n]` helps prevent accidentally using a swapped value
as a regular one (and in the case of floating point values, it's necessary,
because the FPU will mess up any swapped floating point values. So, you
can't actually have swapped floating point values as floating point values).
+/To really test if this PR works, instead of testing swapEndian(0.5f).swapEndian() == 0.5f perhaps check swapEndian(0x1.00007ep+0f) == 0x1.01007ep-1f. Although it should be asked how the FPU was expected "mess up" swapped values so it can be verified this doesn't happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes indeed. I did that because it's hard to get two exact representations of floats when swapped without cheating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swapping a valid float value that leads to NaN is out of topic i think, even if a true topic. The operation might be valid for serialization purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see how it is valid – just use a ubyte buffer on the serialised side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on the serializer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If deserializing a messed-up float can result in it getting changed, then this doesn't work for either serialization or deserialization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's stop speaking about serialization, i don't know why i put this off topic point on the table. I'll just change the test, as initially suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I think we're driving at is - under what circumstance would this function be useful? All it seems like now is a trap that appears useful for a certain purpose but will sometimes give garbage output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About your first comment @n8sh : I've added an overload for x86 that doesn't pass the parameter in ST(0).
constbecause parameter is always a value and this can reduce how many instances are generated.