From: Alan Cox Date: Tue, 21 Jun 2016 18:42:52 +0000 (+0100) Subject: libc: fixups X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=db8260dd4b26fe8fe3de390a8152b763d8ed5307;p=FUZIX.git libc: fixups --- diff --git a/Library/include/fenv.h b/Library/include/fenv.h new file mode 100644 index 00000000..90646028 --- /dev/null +++ b/Library/include/fenv.h @@ -0,0 +1,46 @@ +/* From MUSL */ +#ifndef _FENV_H +#define _FENV_H + +/* None of this works yet .. */ +#if 0 +#define FE_INVALID 1 +#define __FE_DENORM 2 +#define FE_DIVBYZERO 4 +#define FE_OVERFLOW 8 +#define FE_UNDERFLOW 16 +#define FE_INEXACT 32 + +#define FE_ALL_EXCEPT 63 + +#define FE_TONEAREST 0 +#define FE_DOWNWARD 0x400 +#define FE_UPWARD 0x800 +#define FE_TOWARDZERO 0xc00 + +typedef unsigned short fexcept_t; + +typedef struct { + unsigned int __unused; +} fenv_t; + +#define FE_DFL_ENV ((const fenv_t *) -1) + +int feclearexcept(int); +int fegetexceptflag(fexcept_t *, int); +int feraiseexcept(int); +int fesetexceptflag(const fexcept_t *, int); +int fetestexcept(int); + +int fegetround(void); +int fesetround(int); + +int fegetenv(fenv_t *); +int feholdexcept(fenv_t *); +int fesetenv(const fenv_t *); +int feupdateenv(const fenv_t *); + +#endif + +#endif + diff --git a/Library/include/float.h b/Library/include/float.h index 92703d5f..4792bc4b 100644 --- a/Library/include/float.h +++ b/Library/include/float.h @@ -1,79 +1,45 @@ -/*------------------------------------------------------------------------- - float.h - ANSI functions forward declarations +/* From MUSL */ - Copyright (C) 1998, Sandeep Dutta . sandeep.dutta@usa.net +#ifndef _FLOAT_H +#define _FLOAT_H - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2, or (at your option) any - later version. +#define FLT_RADIX 2 - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. +#define FLT_MIN 1.17549435e-38F +#define FLT_MAX 3.40282347e+38F +#define FLT_EPSILON 1.19209290e-07F - You should have received a copy of the GNU General Public License - along with this library; see the file COPYING. If not, write to the - Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, - MA 02110-1301, USA. +#define FLT_MANT_DIG 24 +#define FLT_MIN_EXP (-125) +#define FLT_MAX_EXP 128 - As a special exception, if you link this library with other files, - some of which are compiled with SDCC, to produce an executable, - this library does not by itself cause the resulting executable to - be covered by the GNU General Public License. This exception does - not however invalidate any other reasons why the executable file - might be covered by the GNU General Public License. --------------------------------------------------------------------------*/ +#define FLT_DIG 6 +#define FLT_MIN_10_EXP (-37) +#define FLT_MAX_10_EXP 38 -#ifndef __FLOAT_H -#define __FLOAT_H 1 +#define DBL_MIN 2.2250738585072014e-308 +#define DBL_MAX 1.7976931348623157e+308 +#define DBL_EPSILON 2.2204460492503131e-16 -#include +#define DBL_MANT_DIG 53 +#define DBL_MIN_EXP (-1021) +#define DBL_MAX_EXP 1024 -#define FLT_RADIX 2 -#define FLT_MANT_DIG 24 -#define FLT_EPSILON 1.192092896E-07F -#define FLT_DIG 6 -#define FLT_MIN_EXP (-125) -#define FLT_MIN 1.175494351E-38F -#define FLT_MIN_10_EXP (-37) -#define FLT_MAX_EXP (+128) -#define FLT_MAX 3.402823466E+38F -#define FLT_MAX_10_EXP (+38) +#define DBL_DIG 15 +#define DBL_MIN_10_EXP (-307) +#define DBL_MAX_10_EXP 308 -/* the following deal with IEEE single-precision numbers */ -#define EXCESS 126 -#define SIGNBIT ((unsigned long)0x80000000) -#define __INFINITY ((unsigned long)0x7F800000) -#define HIDDEN (unsigned long)(1ul << 23) -#define SIGN(fp) (((unsigned long)(fp) >> (8*sizeof(fp)-1)) & 1) -#define EXP(fp) (((unsigned long)(fp) >> 23) & (unsigned int) 0x00FF) -#define MANT(fp) (((fp) & (unsigned long)0x007FFFFF) | HIDDEN) -#define NORM 0xff000000 -#define PACK(s,e,m) ((s) | ((unsigned long)(e) << 23) | (m)) +#define FLT_ROUNDS 1 /* Check this */ -float __uchar2fs (unsigned char); -float __schar2fs (signed char); -float __uint2fs (unsigned int); -float __sint2fs (signed int); -float __ulong2fs (unsigned long); -float __slong2fs (signed long); -unsigned char __fs2uchar (float); -signed char __fs2schar (float); -unsigned int __fs2uint (float); -signed int __fs2sint (float); -unsigned long __fs2ulong (float); -signed long __fs2slong (float); +#if defined(__SDCC_z80) || defined(__SDCC_z180) +#define FLT_EVAL_METHOD 0 +typedef float float_t; +typedef double double_t; +#else +#define FLT_EVAL_METHOD -2 +typedef float float_t; +typedef double double_t; +#endif -float __fsadd (float, float); -float __fssub (float, float); -float __fsmul (float, float); -float __fsdiv (float, float); - -char __fslt (float, float); -char __fseq (float, float); -char __fsgt (float, float); - -#endif /* __SDC51_FLOAT_H */ +#endif diff --git a/Library/include/math.h b/Library/include/math.h index 669c9698..2a5a4b5a 100644 --- a/Library/include/math.h +++ b/Library/include/math.h @@ -1,85 +1,175 @@ #ifndef _MATH_H #define _MATH_H -#ifndef double +/* Large elements of this are drawn from MUSL */ -/* Compiler with full float/double support */ +extern int signgam; -extern double fabs(double); -extern double floor(double); -extern double ceil(double); -extern double modf(double, double *); -extern double frexp(double, int *); -extern double ldexp(double, int); -extern double atof(char *); +#ifndef double -extern double sqrt(double); +/* Compiler with full float/double support */ -extern double sin(double); -extern double cos(double); -extern double tan(double); -extern double asin(double); extern double acos(double); +extern double asin(double); extern double atan(double); extern double atan2(double, double); -extern double sinh(double); +extern double atof(char *); +extern double cbrt(double); +extern double ceil(double); +extern double copysign(double, double); +extern double cos(double); extern double cosh(double); -extern double tanh(double); - +extern double erf(double); +extern double exp(double); +extern double expm1(double); +extern double fabs(double); +extern double fdim(double double); +extern double floor(double); +extern double fmax(double, double); +extern double fmin(double, double); +extern double fmod(double, double); +extern double frexp(double, int *); +extern double hypot(double, double); +extern int ilogb(double); +extern double j0(double); +extern double j1(double); +extern double jn(int, double); +extern double ldexp(double, int); +extern double lgamma(double); +extern double lgamma_r, int *); extern double log(double); extern double log10(double); extern double log1p(double); extern double log2(double); extern double logb(double); - +extern long lrint(double); +extern long lround(double); +extern double modf(double, double *); extern double nan(const char *__tagp); - +extern double nearbyint(double); +extern double nextafter(double, double); extern double pow(double, double); -extern double exp(double); - +extern double remainder(double, double); +extern double remquo(double, double, int *); +extern double rint(double); +extern double round(double); extern double scalbln(double, long); extern double scalbn(double, int); +extern double sin(double); +extern double sinh(double); +extern double sqrt(double); +extern double tan(double); +extern double tanh(double); +extern double tgamma(double); +extern double trunc(double); +extern double y0(double); +extern double y1(double); +extern double yn(int, double); +extern unsigned long __double_bits(double); +extern int __fpclassify(double); +extern int __signbit(double); -extern double hypot(double, double); +#define fpclassify(x) ( \ + sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \ + __fpclassify(x)) + +#define isinf(x) ( \ + sizeof(x) == sizeof(float) ? (__float_bits(x) & 0x7fffffff) == 0x7f800000 : \ + (__double_bits(x) & (__uint64_t)-1>>1) == (__uint64_t)0x7ff<<52) + +#define isnan(x) ( \ + sizeof(x) == sizeof(float) ? (__float_bits(x) & 0x7fffffff) > 0x7f800000 : \ + (__double_bits(x) & (__uint64_t)-1>>1) > (__uint64_t)0x7ff<<52) + +#define isnormal(x) ( \ + sizeof(x) == sizeof(float) ? ((__float_bits(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \ + ((__double_bits(x)+((__uint64_t)1<<52)) & (__uint64_t)-1>>1) >= (__uint64_t)1<<53) + +#define isfinite(x) ( \ + sizeof(x) == sizeof(float) ? (__float_bits(x) & 0x7fffffff) < 0x7f800000 : \ + (__double_bits(x) & (__uint64_t)-1>>1) < (__uint64_t)0x7ff<<52) + +#define signbit(x) ( \ + sizeof(x) == sizeof(float) ? (int)(__float_bits(x)>>31) : \ + (int)(__double_bits(x)>>63)) #else /* We have double defined as float .. so fix up the support routines */ -#define fabs(a) fabsf(a) -#define floor(a) floorf(a) -#define ceil(a) ceilf(a) -#define modf(a,b) modff(a,b) -#define frexp(a,b) frexpf(a,b) -#define ldexp(a,b) ldexpf(a,b) +#define acos(a) acosf(a) +#define asin(a) asinf(a) +#define atan(a) atanf(a) +#define atan2(a,b) atan2f(a,b) /* FIXME atof equivalence */ - -#define sqrt(a) sqrtf(a) - -#define sin(a) sinf(a) -#define cos(a) cosf(a) -#define tan(a) tanf(a) -#define asin(a) asinf(a) -#define acos(a) acosf(a) -#define atan(a) atanf(a) -#define atan2(a,b) atan2f(a,b) -#define sinh(a) sinhf(a) -#define cosh(a) coshf(a) -#define tanh(a) tanhf(a) - +#define cbrt(a) cbrtf(a) +#define ceil(a) ceilf(a) +#define copysign(a,b) copysignf(a,b) +#define cos(a) cosf(a) +#define cosh(a) coshf(a) +#define erf(a) erff(a) +#define exp(a) expf(a) +#define expm1(a) expm1f(a) +#define fabs(a) fabsf(a) +#define fdim(a,b) fdimf(a,b) +#define floor(a) floorf(a) +#define fmax(a,b) fmaxf(a,b) +#define fmin(a,b) fminf(a,b) +#define fmod(a,b) fmodf(a,b) +#define frexp(a,b) frexpf(a,b) +#define hypot(a,b) hypotf(a,b) +#define ilogb(a) ilogbf(a) +#define j0(a) j0f(a) +#define j1(a) j1f(a) +#define jn(a,b) jnf(a,b) +#define ldexp(a,b) ldexpf(a,b) +#define lgamma(a) lgammaf(a) +#define lgamma_r(a,b) lgammaf_r(a,b) #define log(a) logf(a) #define log10(a) log10f(a) #define log1p(a) log1pf(a) #define log2(a) log2f(a) #define logb(a) logbf(a) - +#define lrint(a) lrintf(a) +#define lround(a) lroundf(a) +#define modf(a,b) modff(a,b) #define nan(a) nanf(a) - +#define nearbyint(a) nearbyintf(a) +#define nextafter(a,b) nextafterf(a,b) #define pow(a,b) powf(a,b) -#define exp(a) expf(a) -#define hypot(a,b) hypotf(a,b) - +#define remainder(a,b) remainderf(a,b) +#define remquo(a,b,c) remquof(a,b,c) +#define rint(a) rintf(a) +#define round(a) roundf(a) #define scalbln(a,b) scalblnf(a,b) #define scalbn(a,b) scalblf(a,b) +#define sin(a) sinf(a) +#define sinh(a) sinhf(a) +#define sqrt(a) sqrtf(a) +#define tan(a) tanf(a) +#define tanh(a) tanhf(a) +#define tgamma(a) tgammaf(a) +#define trunc(a) truncf(a) +#define y0(a) y0f(a) +#define y1(a) y1f(a) +#define yn(a,b) ynf(a,b) + +#define fpclassify(x) __fpclassify(x)) + +#define isinf(x) ( \ + (__float_bits(x) & 0x7fffffff) == 0x7f800000) + +#define isnan(x) ( \ + (__float_bits(x) & 0x7fffffff) > 0x7f800000) + +#define isnormal(x) ( \ + ((__float_bits(x)+0x00800000) & 0x7fffffff) >= 0x0100000) + +#define isfinite(x) ( \ + (__float_bits(x) & 0x7fffffff) < 0x7f800000) + + +#define signbit(x) ( \ + (int)(__float_bits(x)>>31)) #endif @@ -88,22 +178,59 @@ extern float acoshf(float); extern float asinf(float); extern float asinhf(float); extern float atanf(float); -extern float atan2f(float); +extern float atan2f(float, float); extern float atanhf(float); +extern float cbrtf(float); extern float ceilf(float); +extern float copysignf(float, float); +extern float cosf(float); +extern float coshf(float); +extern float erff(float); +extern float expf(float); +extern float expm1f(float); extern float fabsf(float); +extern float fdimf(float, float); extern float floorf(float); +extern float fmaxf(float, float); +extern float fminf(float, float); +extern float fmodf(float, float); extern float frexpf(float, int *); extern float hypotf(float, float); +extern int ilogbf(float); +extern float j0f(float); +extern float j1f(float); +extern float jnf(int, float); +extern float ldexpf(float, int); +extern float lgammaf(float); +extern float lgammaf_r(float, int *); extern float logf(float); extern float log10f(float); extern float log1pf(float); extern float log2f(float); extern float logbf(float); +extern long lrintf(float); +extern long lroundf(float); +extern float modff(float, float *); extern float nanf(const char *__tagp); +extern float nearbyint(float); +extern float nextafterf(float, float); +extern float remainderf(float, float); +extern float remquof(float, float, int *); +extern float rintf(float); +extern float roundf(float); extern float scalblf(float, long); extern float scalbnf(float, int); +extern float sinf(float); +extern float sinhf(float); extern float sqrtf(float); +extern float tgammaf(float); +extern float trunc(float); +extern float y0f(float); +extern float y1f(float); +extern float ynf(int, float); +extern unsigned int __float_bits(float); +extern int __fpclassifyf(float); +extern int __signbitf(float); /* FIXME: sort out the right NaN's */ #define __sNaN 0x1.fffff0p128 @@ -111,4 +238,37 @@ extern float sqrtf(float); #define __FINFINITY 1e40f +#define INFINITY __FINFINITY +#define NAN __NaN + +#define M_E 2.7182818284590452354 +#define M_LOG2E 1.4426950408889634074 +#define M_LOG10E 0.43429448190325182765 +#define M_LN2 0.69314718055994530942 +#define M_LN10 2.30258509299404568402 +#define M_PI 3.14159265358979323846 +#define M_PI_2 1.57079632679489661923 +#define M_PI_4 0.78539816339744830962 +#define M_1_PI 0.31830988618379067154 +#define M_2_PI 0.63661977236758134308 +#define M_2_SQRTPI 1.12837916709551257390 +#define M_SQRT2 1.41421356237309504880 +#define M_SQRT_1_2 0.70710678118654752440 + +#define HUGE 3.40282347e+38F +#define HUGE_VALF INFINITY +#define HUGE_VAL ((double)INFINITY) + +#define MAXFLOAT 3.40282347e+38F + +#define FP_NAN 0 +#define FP_INFINITE 1 +#define FP_ZERO 2 +#define FP_SUBNORMAL 3 +#define FP_NORMAL 4 + +#define FP_ILOGBNAN (-1-(int)(((unsigned)-1)>>1)) +#define FP_ILOGB0 FP_ILOGBNAN + + #endif diff --git a/Library/libs/creat.c b/Library/libs/creat.c index 0348e565..8c095ecb 100644 --- a/Library/libs/creat.c +++ b/Library/libs/creat.c @@ -5,7 +5,7 @@ #include #include -int creat(__const char * file, mode_t mode) +int creat(const char * file, mode_t mode) { return open(file, O_TRUNC|O_CREAT|O_WRONLY, mode); } diff --git a/Library/libs/err.c b/Library/libs/err.c index a4359954..a7cff165 100644 --- a/Library/libs/err.c +++ b/Library/libs/err.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include diff --git a/Library/libs/index.c b/Library/libs/index.c index 221ae325..b5d0474a 100644 --- a/Library/libs/index.c +++ b/Library/libs/index.c @@ -5,7 +5,7 @@ #include #include -char *index(__const char *src, int chr) +char *index(const char *src, int chr) { return strchr(src, chr); } diff --git a/Library/libs/remove.c b/Library/libs/remove.c index 10f0ea7c..bfe1d65b 100644 --- a/Library/libs/remove.c +++ b/Library/libs/remove.c @@ -8,7 +8,7 @@ #include #include -int remove(__const char *src) +int remove(const char *src) { int er = errno; int rv = unlink(src); diff --git a/Library/libs/rindex.c b/Library/libs/rindex.c index d25435cd..afc4e203 100644 --- a/Library/libs/rindex.c +++ b/Library/libs/rindex.c @@ -5,7 +5,7 @@ #include #include -char *rindex(__const char *src, int chr) +char *rindex(const char *src, int chr) { return strrchr(src, chr); } diff --git a/Library/libs/stricmp.c b/Library/libs/stricmp.c index 67d8d0b3..fc7a24f0 100644 --- a/Library/libs/stricmp.c +++ b/Library/libs/stricmp.c @@ -14,7 +14,7 @@ int stricmp(const char *s, const char *d) unsigned char sc = *(const uchar *) s++, dc = *(const uchar *) d++; if (sc != dc) { - if (_tolower(sc) != _tolower(dc)) + if (tolower(sc) != tolower(dc)) return (int) (char) (sc - dc); } else if (sc == '\0') break; diff --git a/Library/libs/strnicmp.c b/Library/libs/strnicmp.c index 1ea68c95..28d82ade 100644 --- a/Library/libs/strnicmp.c +++ b/Library/libs/strnicmp.c @@ -15,7 +15,7 @@ int strnicmp(const char *s, const char *d, size_t l) unsigned char sc = *(const uchar *) s++, dc = *(const uchar *) d++; if (sc != dc) { - if (_tolower(sc) != _tolower(dc)) + if (tolower(sc) != tolower(dc)) return (int) (char) (sc - dc); } else if (sc == '\0') break;