bytemaster / fc Goto Github PK
View Code? Open in Web Editor NEWAccelerate your C++ Compiles
License: MIT License
Accelerate your C++ Compiles
License: MIT License
template<typename T, class = typename std::enable_if<!std::is_same<mutable_variant_object, std::remove_reference_t> >::type>
Hi,
In raw.hpp, for signed int 32, it looks like some value will have unpack errors.
For example ,if I pack value "0x90000000"(whose binary code is 10010000000000000000000000000000 and in demical it is -1879048192) using "pack( Stream& s, const unsigned_int& v )", the steps are:
The packed part works fine. But when I unpack the value it gets another value instead of 0x90000000.
I use the algorithm in "unpack( Stream& s, signed_int& vi ) ". The steps are:
so, after the unpack function, the value is -1879048191 instead of -1879048192.
Here is the code I used to test. I'm using a uint64_t to hold packed bytes instead of Stream in raw.hpp:
#include <iostream>
#include <bitset>
using namespace std;
uint64_t pack(int32_t value){
uint32_t val = (value<<1) ^ (value>>31);
int k=0;
uint64_t packed = 0 ;
do {
cout << "round" << endl;
uint8_t b = uint8_t(val) & 0x7f;
val >>= 7;
b |= ((val > 0) << 7);
packed |= (uint64_t)b << k;
k += 8;
} while( val );
return packed;
}
int32_t unpackSigned(uint64_t packed){
uint32_t v = 0; char b = 0; int by = 0;
do {
b = packed & 0xff;
v |= uint32_t(uint8_t(b) & 0x7f) << by;
by += 7;
packed >>= 8;
} while( uint8_t(b) & 0x80 );
int value = 0;
value = ((v>>1) ^ (v>>31)) + (v&0x01);
value = v&0x01 ? value : -value;
value = -value;
return value;
}
int main() {
int32_t v = 0x90000000;
uint64_t packed = pack(v);
int32_t r =unpackSigned(packed);
cout << v << endl;
cout << r << endl;
}
In my test this unpack written by me works:
int32_t unpackSigned(uint64_t packed){
uint32_t v = 0; char b = 0; int by = 0;
do {
b = packed & 0xff;
v |= uint32_t(uint8_t(b) & 0x7f) << by;
by += 7;
packed >>= 8;
} while( uint8_t(b) & 0x80 );
int value = 0;
/*
value = ((v>>1) ^ (v>>31)) + (v&0x01);
cout << (v>>31) << endl;
value = v&0x01 ? value : -value;
value = -value;
*/
if(v&0x01 == 1){
v ^= 0xffffffff;
v >>= 1;
value = 0x80000000 + v;
}
else{
value = v >>= 1;
}
return value;
}
Could you please help to research this?@bytemaster
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.