@@ -8,22 +8,25 @@ uint8_t read_u8(const uint8_t *const buf) { return ((uint8_t)*buf); }
88/*
99 * write_u16() -- store a 16-bit int into a char buffer (like htons())
1010 */
11- void write_u16 (uint8_t * buf , uint16_t val ) {
11+ void write_u16 (uint8_t * buf , uint16_t val )
12+ {
1213 * buf ++ = val >> 8 ;
1314 * buf ++ = val ;
1415}
1516
1617/*
1718 * read_u16() -- unpack a 16-bit unsigned from a char buffer (like ntohs())
1819 */
19- uint16_t read_u16 (const uint8_t * const buf ) {
20+ uint16_t read_u16 (const uint8_t * const buf )
21+ {
2022 return ((uint16_t )buf [0 ] << 8 ) | buf [1 ];
2123}
2224
2325/*
2426 * write_u32() -- store a 32-bit int into a char buffer (like htonl())
2527 */
26- void write_u32 (uint8_t * buf , uint32_t val ) {
28+ void write_u32 (uint8_t * buf , uint32_t val )
29+ {
2730 * buf ++ = val >> 24 ;
2831 * buf ++ = val >> 16 ;
2932 * buf ++ = val >> 8 ;
@@ -33,15 +36,17 @@ void write_u32(uint8_t *buf, uint32_t val) {
3336/*
3437 * read_u32() -- unpack a 32-bit unsigned from a char buffer (like ntohl())
3538 */
36- uint32_t read_u32 (const uint8_t * const buf ) {
39+ uint32_t read_u32 (const uint8_t * const buf )
40+ {
3741 return ((uint32_t )buf [0 ] << 24 ) | ((uint32_t )buf [1 ] << 16 ) |
3842 ((uint32_t )buf [2 ] << 8 ) | buf [3 ];
3943}
4044
4145/*
4246 * write_i64() -- store a 64-bit int into a char buffer (like htonl())
4347 */
44- void write_i64 (uint8_t * buf , uint64_t val ) {
48+ void write_i64 (uint8_t * buf , uint64_t val )
49+ {
4550 * buf ++ = val >> 56 ;
4651 * buf ++ = val >> 48 ;
4752 * buf ++ = val >> 40 ;
@@ -55,7 +60,8 @@ void write_i64(uint8_t *buf, uint64_t val) {
5560/*
5661 * read_i64() -- unpack a 64-bit unsigned from a char buffer (like ntohl())
5762 */
58- uint64_t read_i64 (const uint8_t * const buf ) {
63+ uint64_t read_i64 (const uint8_t * const buf )
64+ {
5965 return ((uint64_t )buf [0 ] << 56 ) | ((uint64_t )buf [1 ] << 48 ) |
6066 ((uint64_t )buf [2 ] << 40 ) | ((uint64_t )buf [3 ] << 32 ) |
6167 ((uint64_t )buf [4 ] << 24 ) | ((uint64_t )buf [5 ] << 16 ) |
@@ -66,7 +72,8 @@ uint64_t read_i64(const uint8_t *const buf) {
6672 * write_f64() -- store a 64-bit float into a char buffer, taken from beej.us
6773 * guide
6874 */
69- void write_f64 (uint8_t * buf , double_t val ) {
75+ void write_f64 (uint8_t * buf , double_t val )
76+ {
7077 unsigned bits = 64 , expbits = 11 ;
7178 long double fnorm ;
7279 int shift ;
@@ -78,10 +85,10 @@ void write_f64(uint8_t *buf, double_t val) {
7885 } else {
7986 // check sign and begin normalization
8087 if (val < 0 ) {
81- sign = 1 ;
88+ sign = 1 ;
8289 fnorm = - val ;
8390 } else {
84- sign = 0 ;
91+ sign = 0 ;
8592 fnorm = val ;
8693 }
8794
@@ -95,13 +102,13 @@ void write_f64(uint8_t *buf, double_t val) {
95102 fnorm *= 2.0 ;
96103 shift -- ;
97104 }
98- fnorm = fnorm - 1.0 ;
105+ fnorm = fnorm - 1.0 ;
99106
100107 // calculate the binary form (non-float) of the significand data
101108 significand = fnorm * ((1LL << significandbits ) + 0.5f );
102109
103110 // get the biased exponent
104- exp = shift + ((1 << (expbits - 1 )) - 1 ); // shift + bias
111+ exp = shift + ((1 << (expbits - 1 )) - 1 ); // shift + bias
105112
106113 // return the final answer
107114 uint64_t d =
@@ -115,8 +122,9 @@ void write_f64(uint8_t *buf, double_t val) {
115122 * read_f64() -- unpack a 64-bit float into a char buffer, taken from beej.us
116123 * guide
117124 */
118- double_t read_f64 (const uint8_t * const buf ) {
119- uint64_t i = read_i64 (buf );
125+ double_t read_f64 (const uint8_t * const buf )
126+ {
127+ uint64_t i = read_i64 (buf );
120128 unsigned bits = 64 , expbits = 11 ;
121129 long double result ;
122130 long long shift ;
@@ -132,7 +140,7 @@ double_t read_f64(const uint8_t *const buf) {
132140 result += 1.0f ; // add the one back on
133141
134142 // deal with the exponent
135- bias = (1 << (expbits - 1 )) - 1 ;
143+ bias = (1 << (expbits - 1 )) - 1 ;
136144 shift = ((i >> significandbits ) & ((1LL << expbits ) - 1 )) - bias ;
137145 while (shift > 0 ) {
138146 result *= 2.0 ;
0 commit comments