X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCutil.c;h=a08cd115abe74ce9aea81c81de8c9e013cd6d361;hb=e5c62ddb5b835550d3e4f84dbe9939b5c74b87af;hp=32c7bf74d4f2af67886c93850f24825ed1ab7257;hpb=386cee8465119215de67a9e2c767818d4a923578;p=fw%2Fsdcc diff --git a/src/SDCCutil.c b/src/SDCCutil.c index 32c7bf74..a08cd115 100644 --- a/src/SDCCutil.c +++ b/src/SDCCutil.c @@ -22,6 +22,8 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ +#include + #ifdef _WIN32 #include #include @@ -136,7 +138,7 @@ getBinPath(const char *prel) return path; } /* not enough info in prel; do it with module name */ - else if (0 != GetModuleFileName(NULL, path, sizeof path) != 0 && + else if (0 != GetModuleFileName(NULL, path, sizeof path) && NULL != (p = strrchr(path, DIR_SEPARATOR_CHAR))) { *p = '\0'; return path; @@ -296,6 +298,55 @@ const char *getBuildNumber(void) return (SDCC_BUILD_NUMBER); } +/*-----------------------------------------------------------------*/ +/* doubleFromFixed16x16 - convert a fixed16x16 to double */ +/*-----------------------------------------------------------------*/ +double doubleFromFixed16x16(TYPE_UDWORD value) +{ +#if 0 + /* This version is incorrect negative values. */ + double tmp=0, exp=2; + + tmp = (value & 0xffff0000) >> 16; + + while(value) { + value &= 0xffff; + if(value & 0x8000)tmp += 1/exp; + exp *= 2; + value <<= 1; + } + + return (tmp); +#else + return ((double)(value * 1.0) / (double)(1UL << 16)); +#endif +} + +TYPE_UDWORD fixed16x16FromDouble(double value) +{ +#if 0 + /* This version is incorrect negative values. */ + unsigned int tmp=0, pos=16; + TYPE_UDWORD res; + + tmp = floor( value ); + res = tmp << 16; + value -= tmp; + + tmp = 0; + while(pos--) { + value *= 2; + if(value >= 1.0)tmp |= (1 << pos); + value -= floor( value ); + } + + res |= tmp; + + return (res); +#else + return (TYPE_UDWORD)(value * (double)(1UL << 16)); +#endif +} #if defined(HAVE_VSNPRINTF) || defined(HAVE_VSPRINTF)