Mercurial > hg
comparison mercurial/util.h @ 24016:fb93721cc229
util: add getbefloat64
As far as I can tell, this is wrong. double's format isn't strictly
specified in the C standard, but the wikipedia article implies that
platforms implementing optional Annex F "IEC 60559 floating-point
arithmetic" will work correctly.
My local C experts believe doing *((double *) &t) is a strict aliasing
violation, and that using a union is also one. Doing memcpy appears to
be the least-undefined behavior possible.
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 03 Feb 2015 13:17:21 -0500 |
parents | e2bf959a5a0d |
children | 98042b0e19f9 |
comparison
equal
deleted
inserted
replaced
24015:e2bf959a5a0d | 24016:fb93721cc229 |
---|---|
194 c[1] = (x >> 16) & 0xff; | 194 c[1] = (x >> 16) & 0xff; |
195 c[2] = (x >> 8) & 0xff; | 195 c[2] = (x >> 8) & 0xff; |
196 c[3] = (x) & 0xff; | 196 c[3] = (x) & 0xff; |
197 } | 197 } |
198 | 198 |
199 static inline double getbefloat64(const char *c) | |
200 { | |
201 const unsigned char *d = (const unsigned char *)c; | |
202 double ret; | |
203 int i; | |
204 uint64_t t = 0; | |
205 for (i = 0; i < 8; i++) { | |
206 t = (t<<8) + d[i]; | |
207 } | |
208 memcpy(&ret, &t, sizeof(t)); | |
209 return ret; | |
210 } | |
211 | |
199 #endif /* _HG_UTIL_H_ */ | 212 #endif /* _HG_UTIL_H_ */ |