X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Futil.h;h=cda59bfec453cf6c59461f2018b07e878b8b68f9;hb=86aa9bdd85243207bbd7e888d73c2b865d805265;hp=44545d412f1db9a8353cc4f9c9c1112d29beae75;hpb=1ee73f3c18d424d7f1f0f36aa1f3ca06337a9d9c;p=retroray diff --git a/src/util.h b/src/util.h index 44545d4..cda59bf 100644 --- a/src/util.h +++ b/src/util.h @@ -57,4 +57,28 @@ int match_prefix(const char *str, const char *prefix); void enable_fpexcept(void); void disable_fpexcept(void); +#ifndef INLINE +#if (__STDC_VERSION__ >= 199901) || defined(__GNUC__) +#define INLINE inline +#else +#define INLINE __inline +#endif +#endif + +#if defined(__i386__) || defined(__386__) || defined(MSDOS) + +/* fast conversion of double -> 32bit int + * for details see: + * - http://chrishecker.com/images/f/fb/Gdmfp.pdf + * - http://stereopsis.com/FPU.html#convert + */ +static INLINE int32_t cround64(double val) +{ + val += 6755399441055744.0; + return *(int32_t*)&val; +} +#else +#define cround64(x) ((int32_t)(x)) +#endif + #endif /* UTIL_H_ */