-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Pack/unpack double/float in Little Endian and Big Endian #1905
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
Conversation
I think this addition is pretty much non-controversial and may be merged as-is. [i.e. without RFC] @sskaje Have you noticed the tests failing with: ext/standard/tests/strings/unpack_error.phpt being the failing test? At least here on travis? May you please fix that, thanks! |
@bwoebi done this time. |
This feature gap seemed quite conspicuous when I was writing TypedArrays, so I'm glad to see an attempt to fill it. |
{ | ||
int machine_endian_check = 1; | ||
|
||
return ((char *)&machine_endian_check)[0]; |
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.
you could reuse "WORDS_BIGENDIAN" macro.
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.
Hmm, do float and integer endianness always match?
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 they would not match, you could not use bit-tricks on floats with integers... (which we anyway do)
and it's better also added some notes in UPGRADE, thanks |
Out for beer, I'll fix those later. 2016年5月28日星期六,Xinchen Hui notifications@github.com 写道:
|
@laruence tests passed on debian jessie x86_64(little endian) and mips32(big endian) + gcc, and osx 10.11 + llvm. |
I'm not satisfied that this does not have BC implications, since you had to change an existing test. Can I ask that you start an internals discussion to try to gather more consensus on this change please. Please link to internals discussion here so it may be tracked. UPGRADING has merge conflict that should be fixed at the last moment. If consensus emerges from discussion, fix this conflict and ping me directly, I will merge it quickly before more conflicts can arise. |
@krakjoe You mean I have to provide PR for every active branch ? btw, I'll fix UPGRADING later |
No, a PR to master is fine, and is all that is possible right now because of BC. |
@krakjoe The existing test only checks the error message is an unknown modifier is used, I don't think there's a BC concern there. |
Yep, you're right |
UPGRADING changed and conflict resolved. |
Merged 7267d00 Thanks. |
Linkage fixed in b3889d4. |
The pack/unpack's parameter 'd' and 'f' are machine order in PHP.
The number 236.0 packed to 'd' is: 0000000000806d40.
I was reversing a game save file, which uses 406D800000000000.
Here is how I decode that in PHP.
Since integers are allowed to pack/unpack in both little endian and big endian, I think double/float also need.
In this PR, I choose:
e: little endian double
E: big endian double
g: little endian float
G: big endian float.
BTW, these formats, 'e', 'E', 'g', and 'G' are not taken in Perl.