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_trunc (double x)
 
float SDL_truncf (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_isupper (int x)
 
int SDL_islower (int x)
 
int SDL_toupper (int x)
 
int SDL_tolower (int x)
 

Function Documentation

◆ SDL_abs()

int SDL_abs ( int  x)

Definition at line 453 of file SDL_stdlib.c.

454 {
455 #if defined(HAVE_ABS)
456  return abs(x);
457 #else
458  return ((x) < 0 ? -(x) : (x));
459 #endif
460 }
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:414
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(), and SDL_trunc().

◆ 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(), SDL_floorf(), and SDL_trunc().

◆ 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 288 of file SDL_stdlib.c.

289 {
290 #if defined(HAVE_FMOD)
291  return fmod(x, y);
292 #else
293  return SDL_uclibc_fmod(x, y);
294 #endif
295 }
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 298 of file SDL_stdlib.c.

299 {
300 #if defined(HAVE_FMODF)
301  return fmodf(x, y);
302 #else
303  return (float)SDL_fmod((double)x, (double)y);
304 #endif
305 }
double SDL_fmod(double x, double y)
Definition: SDL_stdlib.c:288

References SDL_fmod().

◆ SDL_isdigit()

int SDL_isdigit ( int  x)

Definition at line 470 of file SDL_stdlib.c.

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

◆ SDL_islower()

int SDL_islower ( int  x)

Definition at line 473 of file SDL_stdlib.c.

473 { return ((x) >= 'a') && ((x) <= 'z'); }

◆ SDL_isspace()

int SDL_isspace ( int  x)

Definition at line 471 of file SDL_stdlib.c.

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

◆ SDL_isupper()

int SDL_isupper ( int  x)

Definition at line 472 of file SDL_stdlib.c.

472 { return ((x) >= 'A') && ((x) <= 'Z'); }

◆ SDL_log()

double SDL_log ( double  x)

Definition at line 308 of file SDL_stdlib.c.

309 {
310 #if defined(HAVE_LOG)
311  return log(x);
312 #else
313  return SDL_uclibc_log(x);
314 #endif
315 }
double SDL_uclibc_log(double x)

References SDL_uclibc_log().

Referenced by SDL_logf().

◆ SDL_log10()

double SDL_log10 ( double  x)

Definition at line 328 of file SDL_stdlib.c.

329 {
330 #if defined(HAVE_LOG10)
331  return log10(x);
332 #else
333  return SDL_uclibc_log10(x);
334 #endif
335 }
double SDL_uclibc_log10(double x)

References SDL_uclibc_log10().

Referenced by SDL_log10f().

◆ SDL_log10f()

float SDL_log10f ( float  x)

Definition at line 338 of file SDL_stdlib.c.

339 {
340 #if defined(HAVE_LOG10F)
341  return log10f(x);
342 #else
343  return (float)SDL_log10((double)x);
344 #endif
345 }
double SDL_log10(double x)
Definition: SDL_stdlib.c:328

References SDL_log10().

◆ SDL_logf()

float SDL_logf ( float  x)

Definition at line 318 of file SDL_stdlib.c.

319 {
320 #if defined(HAVE_LOGF)
321  return logf(x);
322 #else
323  return (float)SDL_log((double)x);
324 #endif
325 }
double SDL_log(double x)
Definition: SDL_stdlib.c:308

References SDL_log().

◆ SDL_pow()

double SDL_pow ( double  x,
double  y 
)

Definition at line 348 of file SDL_stdlib.c.

349 {
350 #if defined(HAVE_POW)
351  return pow(x, y);
352 #else
353  return SDL_uclibc_pow(x, y);
354 #endif
355 }
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 358 of file SDL_stdlib.c.

359 {
360 #if defined(HAVE_POWF)
361  return powf(x, y);
362 #else
363  return (float)SDL_pow((double)x, (double)y);
364 #endif
365 }
double SDL_pow(double x, double y)
Definition: SDL_stdlib.c:348

References SDL_pow().

◆ SDL_scalbn()

double SDL_scalbn ( double  x,
int  n 
)

Definition at line 368 of file SDL_stdlib.c.

369 {
370 #if defined(HAVE_SCALBN)
371  return scalbn(x, n);
372 #elif defined(HAVE__SCALB)
373  return _scalb(x, n);
374 #elif defined(HAVE_LIBC) && defined(HAVE_FLOAT_H) && (FLT_RADIX == 2)
375 /* from scalbn(3): If FLT_RADIX equals 2 (which is
376  * usual), then scalbn() is equivalent to ldexp(3). */
377  return ldexp(x, n);
378 #else
379  return SDL_uclibc_scalbn(x, n);
380 #endif
381 }
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 384 of file SDL_stdlib.c.

385 {
386 #if defined(HAVE_SCALBNF)
387  return scalbnf(x, n);
388 #else
389  return (float)SDL_scalbn((double)x, n);
390 #endif
391 }
double SDL_scalbn(double x, int n)
Definition: SDL_stdlib.c:368

References SDL_scalbn().

◆ SDL_sin()

double SDL_sin ( double  x)

Definition at line 394 of file SDL_stdlib.c.

395 {
396 #if defined(HAVE_SIN)
397  return sin(x);
398 #else
399  return SDL_uclibc_sin(x);
400 #endif
401 }
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 404 of file SDL_stdlib.c.

405 {
406 #if defined(HAVE_SINF)
407  return sinf(x);
408 #else
409  return (float)SDL_sin((double)x);
410 #endif
411 }
double SDL_sin(double x)
Definition: SDL_stdlib.c:394

References SDL_sin().

◆ SDL_sqrt()

double SDL_sqrt ( double  x)

Definition at line 414 of file SDL_stdlib.c.

415 {
416 #if defined(HAVE_SQRT)
417  return sqrt(x);
418 #else
419  return SDL_uclibc_sqrt(x);
420 #endif
421 }
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 424 of file SDL_stdlib.c.

425 {
426 #if defined(HAVE_SQRTF)
427  return sqrtf(x);
428 #else
429  return (float)SDL_sqrt((double)x);
430 #endif
431 }

References SDL_sqrt().

◆ SDL_tan()

double SDL_tan ( double  x)

Definition at line 434 of file SDL_stdlib.c.

435 {
436 #if defined(HAVE_TAN)
437  return tan(x);
438 #else
439  return SDL_uclibc_tan(x);
440 #endif
441 }
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 444 of file SDL_stdlib.c.

445 {
446 #if defined(HAVE_TANF)
447  return tanf(x);
448 #else
449  return (float)SDL_tan((double)x);
450 #endif
451 }
double SDL_tan(double x)
Definition: SDL_stdlib.c:434

References SDL_tan().

◆ SDL_tolower()

int SDL_tolower ( int  x)

Definition at line 475 of file SDL_stdlib.c.

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

◆ SDL_toupper()

int SDL_toupper ( int  x)

Definition at line 474 of file SDL_stdlib.c.

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

◆ SDL_trunc()

double SDL_trunc ( double  x)

Definition at line 264 of file SDL_stdlib.c.

265 {
266 #if defined(HAVE_TRUNC)
267  return trunc(x);
268 #else
269  if (x >= 0.0f) {
270  return SDL_floor(x);
271  } else {
272  return SDL_ceil(x);
273  }
274 #endif
275 }

References SDL_ceil(), and SDL_floor().

Referenced by SDL_truncf().

◆ SDL_truncf()

float SDL_truncf ( float  x)

Definition at line 278 of file SDL_stdlib.c.

279 {
280 #if defined(HAVE_TRUNCF)
281  return truncf(x);
282 #else
283  return (float)SDL_trunc((double)x);
284 #endif
285 }
double SDL_trunc(double x)
Definition: SDL_stdlib.c:264

References SDL_trunc().