SDL 2.0
SDL_stdlib.c File Reference
#include "../SDL_internal.h"
#include "SDL_stdinc.h"
#include "../libm/math_libm.h"
+ Include dependency graph for SDL_stdlib.c:

Go to the source code of this file.

Functions

double SDL_atan (double x)
 
float SDL_atanf (float x)
 
double SDL_atan2 (double x, double y)
 
float SDL_atan2f (float x, float y)
 
double SDL_acos (double val)
 
float SDL_acosf (float val)
 
double SDL_asin (double val)
 
float SDL_asinf (float val)
 
double SDL_ceil (double x)
 
float SDL_ceilf (float x)
 
double SDL_copysign (double x, double y)
 
float SDL_copysignf (float x, float y)
 
double SDL_cos (double x)
 
float SDL_cosf (float x)
 
double SDL_exp (double x)
 
float SDL_expf (float x)
 
double SDL_fabs (double x)
 
float SDL_fabsf (float x)
 
double SDL_floor (double x)
 
float SDL_floorf (float x)
 
double SDL_fmod (double x, double y)
 
float SDL_fmodf (float x, float y)
 
double SDL_log (double x)
 
float SDL_logf (float x)
 
double SDL_log10 (double x)
 
float SDL_log10f (float x)
 
double SDL_pow (double x, double y)
 
float SDL_powf (float x, float y)
 
double SDL_scalbn (double x, int n)
 
float SDL_scalbnf (float x, int n)
 
double SDL_sin (double x)
 
float SDL_sinf (float x)
 
double SDL_sqrt (double x)
 
float SDL_sqrtf (float x)
 
double SDL_tan (double x)
 
float SDL_tanf (float x)
 
int SDL_abs (int x)
 
int SDL_isdigit (int x)
 
int SDL_isspace (int x)
 
int SDL_toupper (int x)
 
int SDL_tolower (int x)
 

Function Documentation

◆ SDL_abs()

int SDL_abs ( int  x)

Definition at line 429 of file SDL_stdlib.c.

430{
431#if defined(HAVE_ABS)
432 return abs(x);
433#else
434 return ((x) < 0 ? -(x) : (x));
435#endif
436}
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574

◆ SDL_acos()

double SDL_acos ( double  val)

Definition at line 75 of file SDL_stdlib.c.

76{
77#if defined(HAVE_ACOS)
78 return acos(val);
79#else
80 double result;
81 if (val == -1.0) {
82 result = M_PI;
83 } else {
84 result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
85 if (result < 0.0)
86 {
87 result += M_PI;
88 }
89 }
90 return result;
91#endif
92}
GLuint GLfloat * val
GLuint64EXT * result
double SDL_sqrt(double x)
Definition: SDL_stdlib.c:390
double SDL_atan(double x)
Definition: SDL_stdlib.c:35

References SDL_atan(), and SDL_sqrt().

Referenced by SDL_acosf(), and SDL_asin().

◆ SDL_acosf()

float SDL_acosf ( float  val)

Definition at line 95 of file SDL_stdlib.c.

96{
97#if defined(HAVE_ACOSF)
98 return acosf(val);
99#else
100 return (float)SDL_acos((double)val);
101#endif
102}
double SDL_acos(double val)
Definition: SDL_stdlib.c:75

References SDL_acos().

◆ SDL_asin()

double SDL_asin ( double  val)

Definition at line 105 of file SDL_stdlib.c.

106{
107#if defined(HAVE_ASIN)
108 return asin(val);
109#else
110 double result;
111 if (val == -1.0) {
112 result = -(M_PI / 2.0);
113 } else {
114 result = (M_PI / 2.0) - SDL_acos(val);
115 }
116 return result;
117#endif
118}

References SDL_acos().

Referenced by SDL_asinf().

◆ SDL_asinf()

float SDL_asinf ( float  val)

Definition at line 121 of file SDL_stdlib.c.

122{
123#if defined(HAVE_ASINF)
124 return asinf(val);
125#else
126 return (float)SDL_asin((double)val);
127#endif
128}
double SDL_asin(double val)
Definition: SDL_stdlib.c:105

References SDL_asin().

◆ SDL_atan()

double SDL_atan ( double  x)

Definition at line 35 of file SDL_stdlib.c.

36{
37#if defined(HAVE_ATAN)
38 return atan(x);
39#else
40 return SDL_uclibc_atan(x);
41#endif
42}
double SDL_uclibc_atan(double x)
double atan(double x)
Definition: s_atan.c:71

References atan(), and SDL_uclibc_atan().

Referenced by SDL_acos(), and SDL_atanf().

◆ SDL_atan2()

double SDL_atan2 ( double  x,
double  y 
)

Definition at line 55 of file SDL_stdlib.c.

56{
57#if defined(HAVE_ATAN2)
58 return atan2(x, y);
59#else
60 return SDL_uclibc_atan2(x, y);
61#endif
62}
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
double SDL_uclibc_atan2(double y, double x)

References SDL_uclibc_atan2().

Referenced by SDL_atan2f().

◆ SDL_atan2f()

float SDL_atan2f ( float  x,
float  y 
)

Definition at line 65 of file SDL_stdlib.c.

66{
67#if defined(HAVE_ATAN2F)
68 return atan2f(x, y);
69#else
70 return (float)SDL_atan2((double)x, (double)y);
71#endif
72}
double SDL_atan2(double x, double y)
Definition: SDL_stdlib.c:55

References SDL_atan2().

◆ SDL_atanf()

float SDL_atanf ( float  x)

Definition at line 45 of file SDL_stdlib.c.

46{
47#if defined(HAVE_ATANF)
48 return atanf(x);
49#else
50 return (float)SDL_atan((double)x);
51#endif
52}

References SDL_atan().

◆ SDL_ceil()

double SDL_ceil ( double  x)

Definition at line 131 of file SDL_stdlib.c.

132{
133#if defined(HAVE_CEIL)
134 return ceil(x);
135#else
136 double integer = SDL_floor(x);
137 double fraction = x - integer;
138 if (fraction > 0.0) {
139 integer += 1.0;
140 }
141 return integer;
142#endif /* HAVE_CEIL */
143}
double SDL_floor(double x)
Definition: SDL_stdlib.c:244

References SDL_floor().

Referenced by SDL_ceilf().

◆ SDL_ceilf()

float SDL_ceilf ( float  x)

Definition at line 146 of file SDL_stdlib.c.

147{
148#if defined(HAVE_CEILF)
149 return ceilf(x);
150#else
151 return (float)SDL_ceil((float)x);
152#endif
153}
double SDL_ceil(double x)
Definition: SDL_stdlib.c:131

References SDL_ceil().

◆ SDL_copysign()

double SDL_copysign ( double  x,
double  y 
)

Definition at line 156 of file SDL_stdlib.c.

157{
158#if defined(HAVE_COPYSIGN)
159 return copysign(x, y);
160#elif defined(HAVE__COPYSIGN)
161 return _copysign(x, y);
162#elif defined(__WATCOMC__) && defined(__386__)
163 /* this is nasty as hell, but it works.. */
164 unsigned int *xi = (unsigned int *) &x,
165 *yi = (unsigned int *) &y;
166 xi[1] = (yi[1] & 0x80000000) | (xi[1] & 0x7fffffff);
167 return x;
168#else
169 return SDL_uclibc_copysign(x, y);
170#endif /* HAVE_COPYSIGN */
171}
double SDL_uclibc_copysign(double x, double y)
double copysign(double x, double y)
Definition: s_copysign.c:21

References copysign(), and SDL_uclibc_copysign().

Referenced by SDL_copysignf().

◆ SDL_copysignf()

float SDL_copysignf ( float  x,
float  y 
)

Definition at line 174 of file SDL_stdlib.c.

175{
176#if defined(HAVE_COPYSIGNF)
177 return copysignf(x, y);
178#else
179 return (float)SDL_copysign((double)x, (double)y);
180#endif
181}
double SDL_copysign(double x, double y)
Definition: SDL_stdlib.c:156

References SDL_copysign().

◆ SDL_cos()

double SDL_cos ( double  x)

Definition at line 184 of file SDL_stdlib.c.

185{
186#if defined(HAVE_COS)
187 return cos(x);
188#else
189 return SDL_uclibc_cos(x);
190#endif
191}
double SDL_uclibc_cos(double x)
double cos(double x)
Definition: s_cos.c:46

References cos(), and SDL_uclibc_cos().

Referenced by SDL_cosf().

◆ SDL_cosf()

float SDL_cosf ( float  x)

Definition at line 194 of file SDL_stdlib.c.

195{
196#if defined(HAVE_COSF)
197 return cosf(x);
198#else
199 return (float)SDL_cos((double)x);
200#endif
201}
double SDL_cos(double x)
Definition: SDL_stdlib.c:184

References SDL_cos().

◆ SDL_exp()

double SDL_exp ( double  x)

Definition at line 204 of file SDL_stdlib.c.

205{
206#if defined(HAVE_EXP)
207 return exp(x);
208#else
209 return SDL_uclibc_exp(x);
210#endif
211}
double SDL_uclibc_exp(double x)

References SDL_uclibc_exp().

Referenced by SDL_expf().

◆ SDL_expf()

float SDL_expf ( float  x)

Definition at line 214 of file SDL_stdlib.c.

215{
216#if defined(HAVE_EXPF)
217 return expf(x);
218#else
219 return (float)SDL_exp((double)x);
220#endif
221}
double SDL_exp(double x)
Definition: SDL_stdlib.c:204

References SDL_exp().

◆ SDL_fabs()

double SDL_fabs ( double  x)

Definition at line 224 of file SDL_stdlib.c.

225{
226#if defined(HAVE_FABS)
227 return fabs(x);
228#else
229 return SDL_uclibc_fabs(x);
230#endif
231}
double SDL_uclibc_fabs(double x)
double fabs(double x)
Definition: s_fabs.c:22

References fabs(), and SDL_uclibc_fabs().

Referenced by SDL_fabsf().

◆ SDL_fabsf()

float SDL_fabsf ( float  x)

Definition at line 234 of file SDL_stdlib.c.

235{
236#if defined(HAVE_FABSF)
237 return fabsf(x);
238#else
239 return (float)SDL_fabs((double)x);
240#endif
241}
double SDL_fabs(double x)
Definition: SDL_stdlib.c:224

References SDL_fabs().

◆ SDL_floor()

double SDL_floor ( double  x)

Definition at line 244 of file SDL_stdlib.c.

245{
246#if defined(HAVE_FLOOR)
247 return floor(x);
248#else
249 return SDL_uclibc_floor(x);
250#endif
251}
double SDL_uclibc_floor(double x)
double floor(double x)
Definition: s_floor.c:33

References floor(), and SDL_uclibc_floor().

Referenced by SDL_ceil(), and SDL_floorf().

◆ SDL_floorf()

float SDL_floorf ( float  x)

Definition at line 254 of file SDL_stdlib.c.

255{
256#if defined(HAVE_FLOORF)
257 return floorf(x);
258#else
259 return (float)SDL_floor((double)x);
260#endif
261}

References SDL_floor().

◆ SDL_fmod()

double SDL_fmod ( double  x,
double  y 
)

Definition at line 264 of file SDL_stdlib.c.

265{
266#if defined(HAVE_FMOD)
267 return fmod(x, y);
268#else
269 return SDL_uclibc_fmod(x, y);
270#endif
271}
double SDL_uclibc_fmod(double x, double y)

References SDL_uclibc_fmod().

Referenced by SDL_fmodf().

◆ SDL_fmodf()

float SDL_fmodf ( float  x,
float  y 
)

Definition at line 274 of file SDL_stdlib.c.

275{
276#if defined(HAVE_FMODF)
277 return fmodf(x, y);
278#else
279 return (float)SDL_fmod((double)x, (double)y);
280#endif
281}
double SDL_fmod(double x, double y)
Definition: SDL_stdlib.c:264

References SDL_fmod().

◆ SDL_isdigit()

int SDL_isdigit ( int  x)

Definition at line 444 of file SDL_stdlib.c.

444{ return ((x) >= '0') && ((x) <= '9'); }

◆ SDL_isspace()

int SDL_isspace ( int  x)

Definition at line 445 of file SDL_stdlib.c.

445{ return ((x) == ' ') || ((x) == '\t') || ((x) == '\r') || ((x) == '\n') || ((x) == '\f') || ((x) == '\v'); }

◆ SDL_log()

double SDL_log ( double  x)

Definition at line 284 of file SDL_stdlib.c.

285{
286#if defined(HAVE_LOG)
287 return log(x);
288#else
289 return SDL_uclibc_log(x);
290#endif
291}
double SDL_uclibc_log(double x)

References SDL_uclibc_log().

Referenced by SDL_logf().

◆ SDL_log10()

double SDL_log10 ( double  x)

Definition at line 304 of file SDL_stdlib.c.

305{
306#if defined(HAVE_LOG10)
307 return log10(x);
308#else
309 return SDL_uclibc_log10(x);
310#endif
311}
double SDL_uclibc_log10(double x)

References SDL_uclibc_log10().

Referenced by SDL_log10f().

◆ SDL_log10f()

float SDL_log10f ( float  x)

Definition at line 314 of file SDL_stdlib.c.

315{
316#if defined(HAVE_LOG10F)
317 return log10f(x);
318#else
319 return (float)SDL_log10((double)x);
320#endif
321}
double SDL_log10(double x)
Definition: SDL_stdlib.c:304

References SDL_log10().

◆ SDL_logf()

float SDL_logf ( float  x)

Definition at line 294 of file SDL_stdlib.c.

295{
296#if defined(HAVE_LOGF)
297 return logf(x);
298#else
299 return (float)SDL_log((double)x);
300#endif
301}
double SDL_log(double x)
Definition: SDL_stdlib.c:284

References SDL_log().

◆ SDL_pow()

double SDL_pow ( double  x,
double  y 
)

Definition at line 324 of file SDL_stdlib.c.

325{
326#if defined(HAVE_POW)
327 return pow(x, y);
328#else
329 return SDL_uclibc_pow(x, y);
330#endif
331}
double SDL_uclibc_pow(double x, double y)

References SDL_uclibc_pow().

Referenced by SDL_powf().

◆ SDL_powf()

float SDL_powf ( float  x,
float  y 
)

Definition at line 334 of file SDL_stdlib.c.

335{
336#if defined(HAVE_POWF)
337 return powf(x, y);
338#else
339 return (float)SDL_pow((double)x, (double)y);
340#endif
341}
double SDL_pow(double x, double y)
Definition: SDL_stdlib.c:324

References SDL_pow().

◆ SDL_scalbn()

double SDL_scalbn ( double  x,
int  n 
)

Definition at line 344 of file SDL_stdlib.c.

345{
346#if defined(HAVE_SCALBN)
347 return scalbn(x, n);
348#elif defined(HAVE__SCALB)
349 return _scalb(x, n);
350#elif defined(HAVE_LIBC) && defined(HAVE_FLOAT_H) && (FLT_RADIX == 2)
351/* from scalbn(3): If FLT_RADIX equals 2 (which is
352 * usual), then scalbn() is equivalent to ldexp(3). */
353 return ldexp(x, n);
354#else
355 return SDL_uclibc_scalbn(x, n);
356#endif
357}
GLdouble n
double SDL_uclibc_scalbn(double x, int n)
#define scalbn
Definition: math_private.h:46

References scalbn, and SDL_uclibc_scalbn().

Referenced by SDL_scalbnf().

◆ SDL_scalbnf()

float SDL_scalbnf ( float  x,
int  n 
)

Definition at line 360 of file SDL_stdlib.c.

361{
362#if defined(HAVE_SCALBNF)
363 return scalbnf(x, n);
364#else
365 return (float)SDL_scalbn((double)x, n);
366#endif
367}
double SDL_scalbn(double x, int n)
Definition: SDL_stdlib.c:344

References SDL_scalbn().

◆ SDL_sin()

double SDL_sin ( double  x)

Definition at line 370 of file SDL_stdlib.c.

371{
372#if defined(HAVE_SIN)
373 return sin(x);
374#else
375 return SDL_uclibc_sin(x);
376#endif
377}
double SDL_uclibc_sin(double x)
double sin(double x)
Definition: s_sin.c:46

References SDL_uclibc_sin(), and sin().

Referenced by SDL_sinf().

◆ SDL_sinf()

float SDL_sinf ( float  x)

Definition at line 380 of file SDL_stdlib.c.

381{
382#if defined(HAVE_SINF)
383 return sinf(x);
384#else
385 return (float)SDL_sin((double)x);
386#endif
387}
double SDL_sin(double x)
Definition: SDL_stdlib.c:370

References SDL_sin().

◆ SDL_sqrt()

double SDL_sqrt ( double  x)

Definition at line 390 of file SDL_stdlib.c.

391{
392#if defined(HAVE_SQRT)
393 return sqrt(x);
394#else
395 return SDL_uclibc_sqrt(x);
396#endif
397}
double SDL_uclibc_sqrt(double x)

References SDL_uclibc_sqrt().

Referenced by SDL_acos(), and SDL_sqrtf().

◆ SDL_sqrtf()

float SDL_sqrtf ( float  x)

Definition at line 400 of file SDL_stdlib.c.

401{
402#if defined(HAVE_SQRTF)
403 return sqrtf(x);
404#else
405 return (float)SDL_sqrt((double)x);
406#endif
407}

References SDL_sqrt().

◆ SDL_tan()

double SDL_tan ( double  x)

Definition at line 410 of file SDL_stdlib.c.

411{
412#if defined(HAVE_TAN)
413 return tan(x);
414#else
415 return SDL_uclibc_tan(x);
416#endif
417}
double SDL_uclibc_tan(double x)
double tan(double x)
Definition: s_tan.c:45

References SDL_uclibc_tan(), and tan().

Referenced by SDL_tanf().

◆ SDL_tanf()

float SDL_tanf ( float  x)

Definition at line 420 of file SDL_stdlib.c.

421{
422#if defined(HAVE_TANF)
423 return tanf(x);
424#else
425 return (float)SDL_tan((double)x);
426#endif
427}
double SDL_tan(double x)
Definition: SDL_stdlib.c:410

References SDL_tan().

◆ SDL_tolower()

int SDL_tolower ( int  x)

Definition at line 447 of file SDL_stdlib.c.

447{ return ((x) >= 'A') && ((x) <= 'Z') ? ('a'+((x)-'A')) : (x); }

◆ SDL_toupper()

int SDL_toupper ( int  x)

Definition at line 446 of file SDL_stdlib.c.

446{ return ((x) >= 'a') && ((x) <= 'z') ? ('A'+((x)-'a')) : (x); }