src/stdlib/SDL_stdlib.c
changeset 7351 668a3dc28361
parent 7180 3733e68edbc3
child 7357 9bd0b241c941
     1.1 --- a/src/stdlib/SDL_stdlib.c	Fri Jul 05 21:37:27 2013 -0700
     1.2 +++ b/src/stdlib/SDL_stdlib.c	Fri Jul 05 23:57:19 2013 -0700
     1.3 @@ -23,24 +23,169 @@
     1.4  /* This file contains portable stdlib functions for SDL */
     1.5  
     1.6  #include "SDL_stdinc.h"
     1.7 +#include "../libm/math_libm.h"
     1.8  
     1.9 -/* these are always #defined, make them real symbol in the library, too... */
    1.10 -#undef SDL_ceil
    1.11 -#undef SDL_abs
    1.12 -#undef SDL_sinf
    1.13 -#undef SDL_cosf
    1.14 -#undef SDL_isdigit
    1.15 -#undef SDL_isspace
    1.16 -#undef SDL_toupper
    1.17 -#undef SDL_tolower
    1.18 -double SDL_ceil(double x) { return SDL_ceil_inline(x); }
    1.19 -float SDL_cosf(float x) { return SDL_cosf_inline(x); }
    1.20 -float SDL_sinf(float x) { return SDL_sinf_inline(x); }
    1.21 -int SDL_abs(int x) { return SDL_abs_inline(x); }
    1.22 -int SDL_isdigit(int x) { return SDL_isdigit_inline(x); }
    1.23 -int SDL_isspace(int x) { return SDL_isspace_inline(x); }
    1.24 -int SDL_toupper(int x) { return SDL_toupper_inline(x); }
    1.25 -int SDL_tolower(int x) { return SDL_tolower_inline(x); }
    1.26 +
    1.27 +double
    1.28 +SDL_atan(double x)
    1.29 +{
    1.30 +#ifdef HAVE_ATAN
    1.31 +    return atan(x);
    1.32 +#else
    1.33 +    return SDL_uclibc_atan(x);
    1.34 +#endif /* HAVE_ATAN */
    1.35 +}
    1.36 +
    1.37 +double
    1.38 +SDL_atan2(double x, double y)
    1.39 +{
    1.40 +#if defined(HAVE_ATAN2)
    1.41 +    return atan2(x, y);
    1.42 +#else
    1.43 +    return SDL_uclibc_atan2(x, y);
    1.44 +#endif /* HAVE_ATAN2 */
    1.45 +}
    1.46 +
    1.47 +double
    1.48 +SDL_ceil(double x)
    1.49 +{
    1.50 +#ifdef HAVE_CEIL
    1.51 +    return ceil(x);
    1.52 +#else
    1.53 +    return (double)(int)((x)+0.5);
    1.54 +#endif /* HAVE_CEIL */
    1.55 +}
    1.56 +
    1.57 +double
    1.58 +SDL_copysign(double x, double y)
    1.59 +{
    1.60 +#if defined(HAVE_COPYSIGN)
    1.61 +    return copysign(x, y);
    1.62 +#else
    1.63 +    return SDL_uclibc_copysign(x, y);
    1.64 +#endif /* HAVE_COPYSIGN */
    1.65 +}
    1.66 +
    1.67 +double
    1.68 +SDL_cos(double x)
    1.69 +{
    1.70 +#if defined(HAVE_COS)
    1.71 +    return cos(x);
    1.72 +#else
    1.73 +    return SDL_uclibc_cos(x);
    1.74 +#endif /* HAVE_COS */
    1.75 +}
    1.76 +
    1.77 +float
    1.78 +SDL_cosf(float x)
    1.79 +{
    1.80 +#ifdef HAVE_COSF
    1.81 +    return cosf(x);
    1.82 +#else
    1.83 +    return (float)SDL_cos((double)x);
    1.84 +#endif
    1.85 +}
    1.86 +
    1.87 +double
    1.88 +SDL_fabs(double x)
    1.89 +{
    1.90 +#if defined(HAVE_FABS)
    1.91 +    return fabs(x); 
    1.92 +#else
    1.93 +    return SDL_uclibc_fabs(x);
    1.94 +#endif /* HAVE_FABS */
    1.95 +}
    1.96 +
    1.97 +double
    1.98 +SDL_floor(double x)
    1.99 +{
   1.100 +#if defined(HAVE_FLOOR)
   1.101 +    return floor(x);
   1.102 +#else
   1.103 +    return SDL_uclibc_floor(x);
   1.104 +#endif /* HAVE_FLOOR */
   1.105 +}
   1.106 +
   1.107 +double
   1.108 +SDL_log(double x)
   1.109 +{
   1.110 +#if defined(HAVE_LOG)
   1.111 +    return log(x);
   1.112 +#else
   1.113 +    return SDL_uclibc_log(x);
   1.114 +#endif /* HAVE_LOG */
   1.115 +}
   1.116 +
   1.117 +double
   1.118 +SDL_pow(double x, double y)
   1.119 +{
   1.120 +#if defined(HAVE_POW)
   1.121 +    return pow(x, y);
   1.122 +#else
   1.123 +    return SDL_uclibc_pow(x, y);
   1.124 +#endif /* HAVE_POW */
   1.125 +}
   1.126 +
   1.127 +double
   1.128 +SDL_scalbn(double x, int n)
   1.129 +{
   1.130 +#if defined(HAVE_SCALBN)
   1.131 +    return scalbn(x, n);
   1.132 +#else
   1.133 +    return SDL_uclibc_scalbn(x, n);
   1.134 +#endif /* HAVE_SCALBN */
   1.135 +}
   1.136 +
   1.137 +double
   1.138 +SDL_sin(double x)
   1.139 +{
   1.140 +#if defined(HAVE_SIN)
   1.141 +    return sin(x);
   1.142 +#else
   1.143 +    return SDL_uclibc_sin(x);
   1.144 +#endif /* HAVE_SIN */
   1.145 +}
   1.146 +
   1.147 +float 
   1.148 +SDL_sinf(float x)
   1.149 +{
   1.150 +#ifdef HAVE_SINF
   1.151 +    return sinf(x);
   1.152 +#else
   1.153 +    return (float)SDL_sin((double)x);
   1.154 +#endif /* HAVE_SINF */
   1.155 +}
   1.156 +
   1.157 +double
   1.158 +SDL_sqrt(double x)
   1.159 +{
   1.160 +#if defined(HAVE_SQRT)
   1.161 +    return sqrt(x);
   1.162 +#else
   1.163 +    return SDL_uclibc_sqrt(x);
   1.164 +#endif
   1.165 +}
   1.166 +
   1.167 +int SDL_abs(int x)
   1.168 +{
   1.169 +#ifdef HAVE_ABS
   1.170 +    return abs(x);
   1.171 +#else
   1.172 +    return ((x) < 0 ? -(x) : (x));
   1.173 +#endif
   1.174 +}
   1.175 +
   1.176 +#ifdef HAVE_CTYPE_H
   1.177 +int SDL_isdigit(int x) { return isdigit(x); }
   1.178 +int SDL_isspace(int x) { return isspace(x); }
   1.179 +int SDL_toupper(int x) { return toupper(x); }
   1.180 +int SDL_tolower(int x) { return tolower(x); }
   1.181 +#else
   1.182 +int SDL_isdigit(int x) { return ((x) >= '0') && ((x) <= '9'); }
   1.183 +int SDL_isspace(int x) { return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n'); }
   1.184 +int SDL_toupper(int x) { return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }
   1.185 +int SDL_tolower(int x) { return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }
   1.186 +#endif
   1.187  
   1.188  
   1.189  #ifndef HAVE_LIBC