blib/lib/SDL2/stdinc.pm untested

filter: Statementstmt 0.0% 0 / 326 Branchbran 0.0% 0 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 365 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package SDL2::stdinc 0.01 {
2 use strictures 2;
3 use experimental 'signatures';
4 use SDL2::Utils;
5 #
6 use SDL2::iconv_t;
7 #
8 enum SDL_bool => [ [ SDL_FALSE => !1 ], [ SDL_TRUE => 1 ] ];
9 use FFI::Platypus::Buffer qw[grow scalar_to_pointer];
10  
11 # Tricky memory stuff
12 ffi->type( '(size_t)->opaque' => 'SDL_malloc_func' );
13 ffi->type( '(size_t,size_t)->opaque' => 'SDL_calloc_func' );
14 ffi->type( '(opaque,size_t)->opaque' => 'SDL_realloc_func' );
15 ffi->type( '(opaque)->void' => 'SDL_free_func' );
16 ffi->load_custom_type( '::WideString' => 'wstring', );
17 ffi->load_custom_type( '::WideString' => 'wstring_w', access => 'write' );
18 ffi->type( 'string' => 'wide_string' );
19 ffi->load_custom_type( '::StringArray' => 'string_array' );
20 #
21 attach stdinc => {
22 SDL_malloc => [ ['size_t'], 'opaque' ],
23 SDL_calloc => [ [ 'size_t', 'size_t' ], 'opaque' ],
24 SDL_realloc => [ [ 'opaque', 'size_t' ], 'opaque' ],
25 SDL_free => [ ['opaque'] ],
26 #
27 SDL_GetMemoryFunctions => [
28 [ 'opaque*', 'opaque*', 'opaque*', 'opaque*' ] =>
29 sub ( $inner, $malloc_func, $calloc_func, $realloc_func, $free_func ) {
30 $inner->( $malloc_func, $calloc_func, $realloc_func, $free_func );
31 $$malloc_func = ffi->function( $$malloc_func, ['size_t'], 'opaque' );
32 $$calloc_func = ffi->function( $$calloc_func, [ 'size_t', 'size_t' ], 'opaque' );
33 $$realloc_func = ffi->function( $$realloc_func, [ 'opaque', 'size_t' ], 'opaque' );
34 $$free_func = ffi->function( $$free_func, ['opaque'], );
35 }
36 ],
37 SDL_SetMemoryFunctions => [
38 [ 'SDL_malloc_func', 'SDL_calloc_func', 'SDL_realloc_func', 'SDL_free_func' ] =>
39 sub ( $inner, $malloc_func, $calloc_func, $realloc_func, $free_func ) {
40 if ( ref $malloc_func eq 'CODE' ) {
41 $malloc_func = ffi->closure($malloc_func);
42 $malloc_func->sticky;
43 }
44 if ( ref $calloc_func eq 'CODE' ) {
45 $calloc_func = ffi->closure($calloc_func);
46 $calloc_func->sticky;
47 }
48 if ( ref $realloc_func eq 'CODE' ) {
49 $realloc_func = ffi->closure($realloc_func);
50 $realloc_func->sticky;
51 }
52 if ( ref $free_func eq 'CODE' ) {
53 $free_func = ffi->closure($free_func);
54 $free_func->sticky;
55 }
56 $inner->( $malloc_func, $calloc_func, $realloc_func, $free_func );
57 }
58 ],
59 SDL_GetNumAllocations => [ [], 'int' ],
60 #
61 SDL_getenv => [ ['string'], 'string' ],
62 SDL_setenv => [ [ 'string', 'string', 'int' ], 'int' ],
63 #
64 SDL_qsort => [
65 [ 'opaque', 'size_t', 'size_t', '(opaque,opaque)->int' ] =>
66 sub ( $inner, $ptr, $count, $size, $comp ) {
67 my $wrapped = 0;
68 if ( ref $comp eq 'CODE' ) {
69 $wrapped = 1;
70 $comp = ffi->closure($comp);
71 $comp->sticky;
72 }
73 $inner->( $ptr, $count, $size, $comp );
74 $comp->unstick if $wrapped;
75 }
76 ],
77 #
78 SDL_abs => [ ['int'], 'int' ],
79 #
80 SDL_isalpha => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
81 SDL_isalnum => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
82 SDL_isblank => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
83 SDL_iscntrl => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
84 SDL_isdigit => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
85 SDL_isxdigit => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
86 SDL_ispunct => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
87 SDL_isspace => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
88 SDL_isupper => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
89 SDL_islower => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
90 SDL_isprint => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
91 SDL_isgraph => [ ['int'], 'int' => sub ( $inner, $char ) { $inner->( ord $char ) } ],
92 #
93 SDL_toupper => [ ['int'], 'int' => sub ( $inner, $char ) { chr $inner->( ord $char ) } ],
94 SDL_tolower => [ ['int'], 'int' => sub ( $inner, $char ) { chr $inner->( ord $char ) } ],
95 #
96 SDL_crc32 => [
97 [ 'uint32', 'opaque', 'size_t' ],
98 'uint32' => sub ( $inner, $crc, $str, $len = length( ref $str ? $$str : $str ) ) {
99 $inner->( $crc, ref $str ? scalar_to_pointer($$str) : $str, $len );
100 }
101 ],
102 #
103 SDL_memset => [
104 [ 'opaque', 'int', 'size_t' ],
105 'opaque' => sub ( $inner, $dst, $c, $len ) {
106 $inner->( ref $dst ? scalar_to_pointer($$dst) : $dst, ord($c), $len );
107 }
108 ],
109 SDL_memcpy => [
110 [ 'opaque', 'opaque', 'size_t' ],
111 'opaque' => sub ( $inner, $dst, $src, $len ) {
112 $inner->(
113 ref $dst ? scalar_to_pointer($$dst) : $dst,
114 ref $src ? scalar_to_pointer($$src) : $src, $len
115 );
116 }
117 ],
118 SDL_memmove => [
119 [ 'opaque', 'opaque', 'size_t' ],
120 'opaque' => sub ( $inner, $dst, $src, $count ) {
121 $inner->(
122 ref $dst ? scalar_to_pointer($$dst) : $dst,
123 ref $src ? scalar_to_pointer($$src) : $src, $count
124 );
125 }
126 ],
127 SDL_memcmp => [
128 [ 'opaque', 'opaque', 'size_t' ],
129 'int' => sub ( $inner, $lhs, $rhs, $count ) {
130 $inner->(
131 ref $lhs ? scalar_to_pointer($$lhs) : $lhs,
132 ref $rhs ? scalar_to_pointer($$rhs) : $rhs, $count
133 );
134 }
135 ],
136 SDL_wcslen => [ ['wstring'], 'size_t' ],
137 SDL_wcslcpy => [ [ 'wstring', 'wstring', 'size_t' ], 'size_t' ],
138 SDL_wcslcat => [ [ 'wstring', 'wstring', 'size_t' ], 'size_t' ], # FIX
139 SDL_wcsdup => [ ['wstring'], 'wstring' ],
140 SDL_wcsstr => [ [ 'wstring', 'wstring' ], 'wstring' ],
141 SDL_wcscmp => [ [ 'wstring', 'wstring' ], 'int' ],
142 SDL_wcsncmp => [ [ 'wstring', 'wstring', 'size_t' ], 'int' ],
143 SDL_wcscasecmp => [ [ 'wstring', 'wstring' ], 'int' ],
144 SDL_wcsncasecmp => [ [ 'wstring', 'wstring', 'size_t' ], 'int' ],
145 #
146 SDL_strlen => [ ['string'], 'size_t' ],
147 SDL_strlcpy => [ [ 'string', 'string', 'size_t' ], 'size_t' ],
148 SDL_utf8strlcpy => [ [ 'string', 'string', 'size_t' ], 'size_t' ],
149 SDL_strlcat => [ [ 'string', 'string', 'size_t' ], 'size_t' ],
150 #
151 SDL_strdup => [ ['string'], 'string' ],
152 SDL_strrev => [ ['string'], 'string' ],
153 SDL_strupr => [ ['string'], 'string' ],
154 SDL_strlwr => [ ['string'], 'string' ],
155 SDL_strchr => [
156 [ 'string', 'int' ],
157 'string' => sub ( $inner, $str, $chr ) {
158 $inner->( $str, ord $chr );
159 }
160 ],
161 SDL_strrchr => [
162 [ 'string', 'int' ],
163 'string' => sub ( $inner, $str, $chr ) {
164 $inner->( $str, ord $chr );
165 }
166 ],
167 SDL_strstr => [ [ 'string', 'string' ], 'string' ],
168 SDL_strtokr => [ [ 'string', 'string', 'string' ], 'string' ], # FIX
169 SDL_utf8strlen => [ ['string'], 'size_t' ],
170 SDL_itoa => [ [ 'int', 'string', 'int' ], 'string' ],
171 SDL_uitoa => [ [ 'uint', 'string', 'int' ], 'string' ],
172 SDL_ltoa => [ [ 'long', 'string', 'int' ], 'string' ],
173 SDL_ultoa => [ [ 'ulong', 'string', 'int' ], 'string' ],
174 SDL_lltoa => [ [ 'sint64', 'string', 'int' ], 'string' ],
175 SDL_ulltoa => [ [ 'uint64', 'string', 'int' ], 'string' ],
176 SDL_atoi => [ ['string'], 'int' ],
177 SDL_atof => [ ['string'], 'double' ],
178 SDL_strtol => [ [ 'string', 'string*', 'int' ], 'long' ],
179 SDL_strtoul => [ [ 'string', 'string*', 'int' ], 'long' ],
180 SDL_strtoll => [ [ 'string', 'string*', 'int' ], 'sint64' ],
181 SDL_strtoull => [ [ 'string', 'string*', 'int' ], 'uint64' ],
182 SDL_strtod => [ [ 'string', 'string*' ], 'double' ],
183 SDL_strcmp => [ [ 'string', 'string' ], 'int' ],
184 SDL_strncmp => [ [ 'string', 'string', 'size_t' ], 'int' ],
185 SDL_strcasecmp => [ [ 'string', 'string' ], 'int' ],
186 SDL_strncasecmp => [ [ 'string', 'string', 'size_t' ], 'int' ],
187 #
188 SDL_acos => [ ['double'], 'double' ],
189 SDL_acosf => [ ['float'], 'float' ],
190 SDL_asin => [ ['double'], 'double' ],
191 SDL_asinf => [ ['float'], 'float' ],
192 SDL_atan => [ ['double'], 'double' ],
193 SDL_atan2 => [ [ 'double', 'double' ], 'double' ],
194 SDL_atan2f => [ [ 'float', 'float' ], 'float' ],
195 SDL_atanf => [ ['float'], 'float' ],
196 SDL_ceil => [ ['double'], 'double' ],
197 SDL_ceilf => [ ['float'], 'float' ],
198 SDL_copysign => [ [ 'double', 'double' ], 'double' ],
199 SDL_copysignf => [ [ 'float', 'float' ], 'float' ],
200 SDL_cos => [ ['double'], 'double' ],
201 SDL_cosf => [ ['float'], 'float' ],
202 SDL_exp => [ ['double'], 'double' ],
203 SDL_expf => [ ['float'], 'float' ],
204 SDL_fabs => [ ['double'], 'double' ],
205 SDL_fabsf => [ ['float'], 'float' ],
206 SDL_floor => [ ['double'], 'double' ],
207 SDL_floorf => [ ['float'], 'float' ],
208 SDL_trunc => [ ['double'], 'double' ],
209 SDL_truncf => [ ['float'], 'float' ],
210 SDL_fmod => [ [ 'double', 'double' ], 'double' ],
211 SDL_fmodf => [ [ 'float', 'float' ], 'float' ],
212 SDL_log => [ ['double'], 'double' ],
213 SDL_logf => [ ['float'], 'float' ],
214 SDL_log10 => [ ['double'], 'double' ],
215 SDL_log10f => [ ['float'], 'float' ],
216 SDL_pow => [ [ 'double', 'double' ], 'double' ],
217 SDL_powf => [ [ 'float', 'float' ], 'float' ],
218 SDL_round => [ ['double'], 'double' ],
219 SDL_roundf => [ ['float'], 'float' ],
220 SDL_lround => [ ['double'], 'long' ],
221 SDL_lroundf => [ ['float'], 'long' ],
222 SDL_scalbn => [ [ 'double', 'int' ], 'double' ],
223 SDL_scalbnf => [ [ 'float', 'int' ], 'float' ],
224 SDL_sin => [ ['double'], 'double' ],
225 SDL_sinf => [ ['float'], 'float' ],
226 SDL_sqrt => [ ['double'], 'double' ],
227 SDL_sqrtf => [ ['float'], 'float' ],
228 SDL_tan => [ ['double'], 'double' ],
229 SDL_tanf => [ ['float'], 'float' ],
230 #
231 SDL_iconv_open => [ [ 'string', 'string' ], 'SDL_iconv_t' ],
232 SDL_iconv_close => [ ['SDL_iconv_t'], 'int' ],
233 SDL_iconv => [ [ 'SDL_iconv_t', 'string*', 'size_t*', 'string*', 'size_t*' ], 'size_t' ],
234 SDL_iconv_string => [ [ 'string', 'string', 'string', 'size_t' ], 'string' ]
235 };
236 define stdinc => [
237 [ SDL_zero => sub ($ptr) { SDL2::FFI::SDL_memset( $ptr, 0, length($ptr) ) } ],
238 [ SDL_sscanf => sub ( $buffer, $format, @args ) { # FIX: Breaks on string captures
239 my @types = SDL2::Utils::_tokenize_in($format);
240 my $retval
241 = ffi->function( SDL_sscanf => [ 'string', 'string' ] => [@types] => 'int' )
242 ->call( $buffer, $format, @args );
243 for my $i ( 0 .. $#args ) { # clean up c->perl
244 $_[ $i + 2 ] = pack 'W*', unpack 'L*', $args[$i] if $types[$i] eq 'wide_string';
245 $_[ $i + 2 ] = unpack 'Z*', $args[$i] if $types[$i] eq 'string';
246 }
247 $retval;
248 }
249 ],
250 [ SDL_vsscanf => sub ( $buffer, $format, @args ) { SDL2::FFI::SDL_sscanf(@_) } ],
251 [ SDL_snprintf => sub ( $buffer, $maxlen, $format, @args ) {
252 $buffer = "\0" x $maxlen; # Just to be safe since we know $maxlen
253 my @types = SDL2::Utils::_tokenize_out( $format, 0 );
254  
255 #use Data::Dump;ddx \@types;
256 my $retval
257 = ffi->function(
258 SDL_snprintf => [ 'string', 'size_t', 'string' ] => [@types] => 'int' )
259 ->call( $buffer, $maxlen, $format, @args );
260 $_[0] = unpack 'Z*', $buffer;
261 $retval;
262 }
263 ],
264 [ SDL_vsnprintf =>
265 sub ( $buffer, $maxlen, $format, @args ) { SDL2::FFI::SDL_snprintf(@_) }
266 ],
267  
268 # math for morons
269 [ M_PI => '3.14159265358979323846264338327950288' ],
270  
271 # iconv
272 [ SDL_ICONV_ERROR => -1 ],
273 [ SDL_ICONV_E2BIG => -2 ],
274 [ SDL_ICONV_EILSEQ => -3 ],
275 [ SDL_ICONV_EINVAL => -4 ],
276 #
277 [ SDL_iconv_utf8_locale => sub ($s) {
278 SDL2::FFI::SDL_iconv_string( "", "UTF-8", $s, SDL2::FFI::SDL_strlen($s) + 1 );
279 }
280 ],
281  
282 #[SDL_iconv_utf8_ucs2 => sub ($s) { SDL2::FFI::SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", $s, SDL2::FFI::SDL_strlen($s)+1 )}],
283 #[SDL_iconv_utf8_ucs4 => sub ($s) { SDL2::FFI::SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", $s, SDL2::FFI::SDL_strlen($s)+1 )}]
284 ];
285  
286 =encoding utf-8
287  
288 =head1 NAME
289  
290 SDL2::stdinc - General C Language Support Functions
291  
292 =head1 SYNOPSIS
293  
294 use SDL2 qw[:stdinc];
295  
296 =head1 DESCRIPTION
297  
298 This is a general package that includes C language support where platform
299 differences are abstracted away.
300  
301 =head1 Functions
302  
303 These functions likely will not be used in end-user code but may be imported
304 with the C<:stdinc> tag.
305  
306 =head2 C<SDL_malloc( ... )>
307  
308 Wraps the standard memory allocation functions for the specific platform.
309  
310 Expected parameters include:
311  
312 =over
313  
314 =item C<size> - size of the allocated memory
315  
316 =back
317  
318 Returns a pointer to the memory.
319  
320 =head2 C<SDL_calloc( ... )>
321  
322 Allocates memory for an array of num objects of size and initializes all bytes
323 in the allocated storage to zero.
324  
325 Expected parameters include:
326  
327 =over
328  
329 =item C<num> - number of objects
330  
331 =item C<size> - size of each object
332  
333 =back
334  
335 Returns a pointer to the memory.
336  
337 =head2 C<SDL_realloc( ... )>
338  
339 Reallocates the given area of memory.
340  
341 Expected parameters include:
342  
343 =over
344  
345 =item C<ptr> - pointer to the memory area to be reallocated
346  
347 =item C<new_size> - new size of the array in bytes
348  
349 =back
350  
351 =head2 C<SDL_free( ... )>
352  
353 Frees allocated memory.
354  
355  
356 Expected parameters include:
357  
358 =over
359  
360 =item C<ptr> - pointer to the memory area to be freed
361  
362 =back
363  
364 =head2 C<SDL_GetMemoryFunctions( ... )>
365  
366 Get the current set of SDL memory functions.
367  
368 SDL_GetMemoryFunctions( \my $malloc, \my $calloc, \my $realloc, \my $free );
369 my $mem = $malloc->(100);
370 # Do odd, low level things with your memory
371 $free->($mem);
372  
373 Expected parameters include:
374  
375 =over
376  
377 =item C<malloc_func> - pointer which will be filled with a C<SDL_malloc_func>
378  
379 =item C<calloc_func> - pointer which will be filled with a C<SDL_calloc_func>
380  
381 =item C<realloc_func> - pointer which will be filled with a C<SDL_realloc_func>
382  
383 =item C<free_func> - pointer which will be filled with a C<SDL_free_func>
384  
385 =back
386  
387 =head2 C<SDL_SetMemoryFunctions( ... )>
388  
389 Replace SDL's memory allocation functions with a custom set.
390  
391 use Data::Dump;
392 SDL_SetMemoryFunctions( # poor example but I have no idea
393 sub { ddx \@_; ... }, # why you're doing this anyway
394 sub { ddx \@_; ... },
395 sub { ddx \@_; ... },
396 sub { ddx \@_; ... },
397 );
398  
399 Note: If you are replacing SDL's memory functions, you should call L<<
400 C<SDL_GetNumAllocations( )>|/C<SDL_GetNumAllocations( )> >> and be very careful
401 if it returns non-zero. That means that your free function will be called with
402 memory allocated by the previous memory allocation functions.
403  
404 Expected parameters include:
405  
406 =over
407  
408 =item C<malloc_func> - a C<SDL_malloc_func> closure
409  
410 =item C<calloc_func> - a C<SDL_calloc_func> closure
411  
412 =item C<realloc_func> - a C<SDL_realloc_func> closure
413  
414 =item C<free_func> - a C<SDL_free_func> closure
415  
416 =back
417  
418 If you pass a simple code reference to any of the parameters, they'll be
419 wrapped in a closure and made sticky
420  
421 =head2 C<SDL_GetNumAllocations( )>
422  
423 Get the number of outstanding (unfreed) allocations.
424  
425 my $leaks = SDL_GetNumAllocations( );
426  
427 Returns an integer.
428  
429 =head2 C<SDL_getenv( ... )>
430  
431 Get environment variable's value.
432  
433 my $path = SDL_getenv( 'PATH' );
434  
435 Expected parameters include:
436  
437 =over
438  
439 =item C<name> - the name of the environment variable to query
440  
441 =back
442  
443 Returns the value if defined.
444  
445 =head2 C<SDL_setenv( ... )>
446  
447 Set environment variable's value.
448  
449 SDL_setenv( 'Perl_SDL_pocket', 'store something here', 1 );
450  
451 Expected parameters include:
452  
453 =over
454  
455 =item C<name> - the name of the environment variable to set
456  
457 =item C<value> - the new value to set the given environment variable to
458  
459 =item C<overwrite> - a boolean value; if true, the value is updated if already defined
460  
461 =back
462  
463 Returns C<1> if the environment variable has been changed; otherwise C<0>.
464  
465 =head2 C<SDL_qsort( ... )>
466  
467 A polymorphic sorting algorithm for arrays of arbitrary objects according to a
468 user-provided comparison function.
469  
470 Expected parameters include:
471  
472 =over
473  
474 =item C<base> - pointer to the array to sort
475  
476 =item C<count> - number of elements in the array
477  
478 =item C<size> - size of each element in the array in bytes
479  
480 =item C<comp> - comparison function which returns ​a negative integer value if the first argument is less than the second, a positive integer value if the first argument is greater than the second and zero if the arguments are equivalent.
481  
482 The signature of the comparison function should be equivalent to the following:
483  
484 int cmp(const void *a, const void *b);
485 # for FFI::Platypus->type: '(opaque,opaque)->int'
486  
487 If the function is a code reference and not a closure, it will be wrapped
488 automatically and temporarily made sticky.
489  
490 The function must not modify the objects passed to it and must return
491 consistent results when called for the same objects, regardless of their
492 positions in the array.
493  
494 =back
495  
496 See also: L<https://en.cppreference.com/w/c/algorithm/qsort>
497  
498 =head2 C<SDL_abs( ... )>
499  
500 Standard C<abs( ... )> function.
501  
502 my $zero = SDL_abs( -459 ); # Ha
503  
504 Expected parameters include:
505  
506 =over
507  
508 =item C<x> - integer value
509  
510 =back
511  
512 Returns the absolute value of C<x>.
513  
514 =head2 C<SDL_isalpha( ... )>
515  
516 Checks if the given character is an alphabetic character, i.e. either an
517 uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), or a lowercase letter
518 (abcdefghijklmnopqrstuvwxyz).
519  
520 Expected parameters include:
521  
522 =over
523  
524 =item C<ch> - character to classify
525  
526 =back
527  
528 Returns non-zero value if the character is an alphabetic character, zero
529 otherwise.
530  
531 =head2 C<SDL_isalnum( ... )>
532  
533 Checks if the given character is an alphanumeric character as classified by the
534 current C locale. In the default locale, the following characters are
535 alphanumeric:
536  
537 =over
538  
539 =item * digits (0123456789)
540  
541 =item * uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ)
542  
543 =item * lowercase letters (abcdefghijklmnopqrstuvwxyz)
544  
545 =back
546  
547 Expected parameters include:
548  
549 =over
550  
551 =item C<ch> - character to classify
552  
553 =back
554  
555 Returns non-zero value if the character is an alphanumeric character, zero
556 otherwise.
557  
558 =head2 C<SDL_isblank( ... )>
559  
560 Checks if the given character is a blank character in the current C locale.
561  
562 Expected parameters include:
563  
564 =over
565  
566 =item C<ch> - character to classify
567  
568 =back
569  
570 Returns non-zero value if the character is a blank character, zero otherwise.
571  
572 =head2 C<SDL_iscntrl( ... )>
573  
574 Checks if the given character is a control character, i.e. codes 0x00-0x1F and
575 0x7F.
576  
577 Expected parameters include:
578  
579 =over
580  
581 =item C<ch> - character to classify
582  
583 =back
584  
585 Returns non-zero value if the character is a control character, zero otherwise.
586  
587 =head2 C<SDL_isdigit( ... )>
588  
589 Checks if the given character is a numeric character (0123456789).
590  
591 Expected parameters include:
592  
593 =over
594  
595 =item C<ch> - character to classify
596  
597 =back
598  
599 Returns non-zero value if the character is a numeric character, zero otherwise.
600  
601 =head2 C<SDL_isxdigit( ... )>
602  
603 Checks if the given character is a hexadecimal numeric character
604 (0123456789abcdefABCDEF) or is classified as a hexadecimal character.
605  
606 Expected parameters include:
607  
608 =over
609  
610 =item C<ch> - character to classify
611  
612 =back
613  
614 Returns non-zero value if the character is an hexadecimal numeric character,
615 zero otherwise.
616  
617 =head2 C<SDL_ispunct( ... )>
618  
619 Checks if the given character is a punctuation character in the current C
620 locale. The default C locale classifies the characters
621 !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ as punctuation.
622  
623 Expected parameters include:
624  
625 =over
626  
627 =item C<ch> - character to classify
628  
629 =back
630  
631 Returns non-zero value if the character is a punctuation character, zero
632 otherwise.
633  
634 =head2 C<SDL_isspace( ... )>
635  
636 Checks if the given character is a whitespace character, i.e. either space
637 (0x20), form feed (0x0c), line feed (0x0a), carriage return (0x0d), horizontal
638 tab (0x09) or vertical tab (0x0b).
639  
640 Expected parameters include:
641  
642 =over
643  
644 =item C<ch> - character to classify
645  
646 =back
647  
648 Returns non-zero value if the character is a whitespace character, zero
649 otherwise.
650  
651 =head2 C<SDL_isupper( ... )>
652  
653 Checks if the given character is an uppercase character according to the
654 current C locale. In the default "C" locale, isupper returns true only for the
655 uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ).
656  
657 Expected parameters include:
658  
659 =over
660  
661 =item C<ch> - character to classify
662  
663 =back
664  
665 Returns non-zero value if the character is an uppercase letter, zero otherwise.
666  
667 =head2 C<SDL_islower( ... )>
668  
669 Checks if the given character is classified as a lowercase character according
670 to the current C locale. In the default "C" locale, islower returns true only
671 for the lowercase letters (abcdefghijklmnopqrstuvwxyz).
672  
673 Expected parameters include:
674  
675 =over
676  
677 =item C<ch> - character to classify
678  
679 =back
680  
681 Returns non-zero value if the character is a lowercase letter, zero otherwise.
682  
683 =head2 C<SDL_isprint( ... )>
684  
685 Checks if the given character can be printed, i.e. it is either a number
686 (0123456789), an uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), a lowercase
687 letter (abcdefghijklmnopqrstuvwxyz), a punctuation
688 character(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~), or space, or any character
689 classified as printable by the current C locale.
690  
691 Expected parameters include:
692  
693 =over
694  
695 =item C<ch> - character to classify
696  
697 =back
698  
699 Returns non-zero value if the character can be printed, zero otherwise.
700  
701 =head2 C<SDL_isgraph( ... )>
702  
703 Checks if the given character has a graphical representation, i.e. it is either
704 a number (0123456789), an uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), a
705 lowercase letter (abcdefghijklmnopqrstuvwxyz), or a punctuation
706 character(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~), or any graphical character
707 specific to the current C locale.
708  
709 Expected parameters include:
710  
711 =over
712  
713 =item C<ch> - character to classify
714  
715 =back
716  
717 Returns non-zero value if the character has a graphical representation
718 character, zero otherwise.
719  
720 =head2 C<SDL_toupper( ... )>
721  
722 Converts the given character to uppercase according to the character conversion
723 rules defined by the currently installed C locale.
724  
725 In the default "C" locale, the following lowercase letters
726 abcdefghijklmnopqrstuvwxyz are replaced with respective uppercase letters
727 ABCDEFGHIJKLMNOPQRSTUVWXYZ.
728  
729 Expected parameters include:
730  
731 =over
732  
733 =item C<ch> - character to convert
734  
735 =back
736  
737 Returns uppercase version of C<ch> or unmodified C<ch> if no uppercase version
738 is defined by the current C locale.
739  
740 =head2 C<SDL_tolower( ... )>
741  
742 Converts the given character to lowercase according to the character conversion
743 rules defined by the currently installed C locale.
744  
745 In the default "C" locale, the following uppercase letters
746 ABCDEFGHIJKLMNOPQRSTUVWXYZ are replaced with respective lowercase letters
747 abcdefghijklmnopqrstuvwxyz. Expected parameters include:
748  
749 =over
750  
751 =item C<ch> - character to convert
752  
753 =back
754  
755 Returns lowercase version of C<ch> or unmodified C<ch> if no lowercase version
756 is listed in the current C locale.
757  
758 =head2 C<SDL_crc32( ... )>
759  
760 This runs through a practical algorithm for the CRC-32 variant of CRC.
761  
762 warn SDL_crc32( 0, "123456789", 9);
763 warn SDL_crc32( 0, "123456789");
764 warn 0xCBF43926;
765  
766 Expected parameters include:
767  
768 =over
769  
770 =item C<crc> - pointer to context variable
771  
772 =item C<data> - input buffer to checksum
773  
774 =item C<len> - length of C<data> (this is optional)
775  
776 =back
777  
778 The checksum is returned.
779  
780 =head2 C<SDL_memset( ... )>
781  
782 Fill a block of memory.
783  
784 my $str = 'almost every programmer should know memset!';
785 SDL_memset($str, '-', 6);
786 print $str; # '------ every programmer should know memset!'
787  
788 Expected parameters include:
789  
790 =over
791  
792 =item C<ptr> - Pointer to the block of memory to fill.
793  
794 =item C<value> - Value to set.
795  
796 =item C<num> - Number of bytes to be set to C<value>
797  
798 =back
799  
800 The C<ptr> is returned.
801  
802 =head2 C<SDL_zero)( ... )>
803  
804 Fill a block of memory with zeros.
805  
806 Expected parameters include:
807  
808 =over
809  
810 =item C<ptr> - Pointer to the block of memory to fill.
811  
812 =back
813  
814 The C<ptr> is returned.
815  
816 =head2 C<SDL_memcpy( ... )>
817  
818 Copies C<count> bytes from the object pointed to by C<src> to the object
819 pointed to by C<dest>. Both objects are reinterpreted as arrays of C<unsigned
820 char>.
821  
822 my $source = 'once upon a midnight dreary...';
823 my $dest = 'xxxx';
824 SDL_memcpy(\$dest, \$source, 4);
825  
826 Expected parameters include:
827  
828 =over
829  
830 =item C<dest> - pointer to the memory location to copy to
831  
832 =item C<src> - pointer to the memory location to copy from
833  
834 =item C<count> - number of bytes to copy
835  
836 =back
837  
838 C<dest> is returned.
839  
840 =begin internals
841  
842 # Make this work without isCow flag
843  
844 use Devel::Peek; my $source = 'once upon a midnight dreary...';
845  
846 # my $dest = 'xxxx'; Devel::Peek::Dump( $dest ); SDL_memcpy($dest, $source, 4);
847 warn $dest;
848  
849 # $dest = 'x' x 4; # Does not work Devel::Peek::Dump( $dest );
850 SDL_memcpy($dest, $source, 4); warn $dest;
851  
852 =end internals
853  
854 =head2 C<SDL_memmove( ... )>
855  
856 Copies C<count> bytes from the object pointed to by C<src> to the object
857 pointed to by C<dest>. Both objects are reinterpreted as arrays of C<unsigned
858 char>.
859  
860 my $source = 'once upon a midnight dreary...';
861 my $dest = 'xxxx';
862 SDL_memmove(\$dest, \$source, 4);
863 print $dest; # once
864  
865 ...or...
866  
867 use FFI::Platypus::Buffer qw[scalar_to_pointer];
868 my $str = '1234567890';
869 SDL_memmove( scalar_to_pointer($str) + 4, scalar_to_pointer($str) + 3, 3 )
870 ; # copies from [4, 5, 6] to [5, 6, 7]
871 print $str; # 1234456890
872  
873 Expected parameters include:
874  
875 =over
876  
877 =item C<dest> - pointer to the memory location to copy to
878  
879 =item C<src> - pointer to the memory location to copy from
880  
881 =item C<count> - number of bytes to copy
882  
883 =back
884  
885 C<dest> is returned.
886  
887 =head2 C<SDL_memcmp( ... )>
888  
889 Reinterprets the objects pointed to by lhs and rhs as arrays of unsigned char
890 and compares the first count characters of these arrays. The comparison is done
891 lexicographically.
892  
893 sub demo ( $lhs, $rhs, $sz ) {
894 print substr( $lhs, 0, $sz );
895 my $rc = SDL_memcmp( \$lhs, \$rhs, $sz );
896 print $rc == 0 ? ' compares equal to ' :
897 $rc < 0 ? ' precedes ' :
898 $rc > 0 ? ' follows ' :
899 '';
900 print substr( $rhs, 0, $sz ) . " in lexicographical order\n";
901 }
902 #
903 my $a1 = 'abc';
904 my $a2 = 'abd';
905 demo( $a1, $a2, length $a1 ); # abc precedes abd in lexicographical order
906 demo( $a2, $a1, length $a1 ); # abd follows abc in lexicographical order
907 demo( $a1, $a1, length $a1 ); # abc compares equal to abc in lexicographical order
908  
909 Expected parameters include:
910  
911 =over
912  
913 =item C<lhs> - pointer to memory to compare
914  
915 =item C<rhs> - pointer to memory to compare
916  
917 =item C<len> - number of bytes to examine
918  
919 =back
920  
921 Returns a negative value if the first differing byte (reinterpreted as unsigned
922 char) in lhs is less than the corresponding byte in C<rhs>.
923  
924 ​C<0​> if all count bytes of C<lhs> and C<rhs> are equal.
925  
926 Positive value if the first differing byte in <lhs> is greater than the
927 corresponding byte in C<rhs>.
928  
929 =head2 C<SDL_wcslen( ... )>
930  
931 Returns the length of a wide string, that is the number of non-null wide
932 characters that precede the terminating null wide character.
933  
934 use utf8;
935 my $str = "木之本 桜";
936 binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
937 print "The length of '$str' is " . SDL_wcslen($str) . "\n";
938 # The length of '木之本 桜' is 5
939  
940 Expected parameters include:
941  
942 =over
943  
944 =item C<str> - pointer to the wide string to be examined
945  
946 =back
947  
948 =head2 C<SDL_wcslcpy( ... )>
949  
950 Copies at most C<count> characters of the wide string pointed to by C<src>
951 (including the terminating null wide character) to wide character array pointed
952 to by C<dest>.
953  
954 Expected parameters include:
955  
956 =over
957  
958 =item C<dest> - pointer to the wide character array to copy to
959  
960 =item C<src> - pointer to the wide string to copy from
961  
962 =item C<count> - maximum number of wide characters to copy
963  
964 =back
965  
966 Returns C<dest>.
967  
968 =head2 C<SDL_wcslcat( )>
969  
970 Appends at most C<count> wide characters from the wide string pointed to by
971 C<src>, stopping if the null terminator is copied, to the end of the character
972 string pointed to by C<dest>. The wide character src[0] replaces the null
973 terminator at the end of dest. The null terminator is always appended in the
974 end (so the maximum number of wide characters the function may write is
975 C<count>+1).
976  
977 Expected parameters include:
978  
979 =over
980  
981 =item C<dest> - pointer to the null-terminated wide string to append to
982  
983 =item C<src> - pointer to the null-terminated wide string to copy from
984  
985 =item C<count> - maximum number of wide characters to copy
986  
987 =back
988  
989 Returns zero on success, returns non-zero on error.
990  
991 =head2 C<SDL_wcsdup( ... )>
992  
993 Duplicate a wide character string.
994  
995 Expected parameters include:
996  
997 =over
998  
999 =item C<wstr> - wide character string to duplicate
1000  
1001 =back
1002  
1003 Returns a newly allocated wide character string on success.
1004  
1005 =head2 C<SDL_wcsstr( ... )>
1006  
1007 Finds the first occurrence of the wide string C<src> in the wide string pointed
1008 to by C<dest>. The terminating null characters are not compared.
1009  
1010 use utf8;
1011 binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
1012 my $origin = "アルファ, ベータ, ガンマ, アルファ, ベータ, ガンマ.";
1013 my $target = "ベータ";
1014 my $result = $origin;
1015 print "Substring to find: \"$target\"\nString to search: \"$origin\"\n\n";
1016 for ( ; ( $result = SDL_wcsstr( $result, $target ) ); $result = substr $result, 1 ) {
1017 print "Found: \"$result\"\n";
1018 }
1019  
1020 Expected parameters include:
1021  
1022 =over
1023  
1024 =item C<dest> - pointer to the null-terminated wide string to examine
1025  
1026 =item C<src> - pointer to the null-terminated wide string to search for
1027  
1028 =back
1029  
1030 Returns a pointer to the first character of the found substring in C<dest>, or
1031 a null pointer if no such substring is found. If C<src> points to an empty
1032 string, C<dest> is returned.
1033  
1034 =head2 C<SDL_wcscmp( ... )>
1035  
1036 Compares two null-terminated wide strings lexicographically.
1037  
1038 use utf8;
1039 binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
1040 my $string = "どうもありがとうございます";
1041 demo( $string, "どうも" );
1042 demo( $string, "助かった" );
1043 demo( substr( $string, 9 ), substr( "ありがとうございます", 6 ) );
1044  
1045 sub demo ( $lhs, $rhs ) {
1046 my $rc = SDL_wcscmp( $lhs, $rhs );
1047 my $rel = $rc < 0 ? 'precedes' : $rc > 0 ? 'follows' : 'equals';
1048 printf( "[%ls] %s [%ls]\n", $lhs, $rel, $rhs );
1049 }
1050  
1051 Expected parameters include:
1052  
1053 =over
1054  
1055 =item C<lhs> - pointer to a wide string
1056  
1057 =item C<rhs> - pointer to a wide string
1058  
1059 =back
1060  
1061 Returns a negative value if C<lhs> appears before C<rhs> in lexicographical
1062 order.
1063  
1064 Returns zero if C<lhs> and C<rhs> compare equal.
1065  
1066 Returns a positive value if C<lhs> appears after C<rhs> in lexicographical
1067 order.
1068  
1069 =head2 C<SDL_wcsncmp( ... )>
1070  
1071 Compares at most C<count> wide characters of two null-terminated wide strings.
1072 The comparison is done lexicographically.
1073  
1074 use utf8;
1075 binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
1076 my $str1 = "안녕하세요";
1077 my $str2 = "안녕히 가십시오";
1078 demo( $str1, $str2, 5 );
1079 demo( $str2, $str1, 8 );
1080 demo( $str1, $str2, 2 );
1081  
1082 sub demo ( $lhs, $rhs, $sz ) {
1083 my $rc = SDL_wcsncmp( $lhs, $rhs, $sz );
1084 my $rel = $rc < 0 ? 'precede' : $rc > 0 ? 'follow' : 'equal';
1085 printf( "First %d characters of [%ls] %s [%ls]\n", $sz, $lhs, $rel, $rhs );
1086 }
1087  
1088 Expected parameters include:
1089  
1090 =over
1091  
1092 =item C<lhs> - pointer to a wide string
1093  
1094 =item C<rhs> - pointer to a wide string
1095  
1096 =item C<count> - maximum number of characters to compare
1097  
1098 =back
1099  
1100 Returns a negative value if C<lhs> appears before C<rhs> in lexicographical
1101 order.
1102  
1103 Returns zero if C<lhs> and C<rhs> compare equal.
1104  
1105 Returns a positive value if C<lhs> appears after C<rhs> in lexicographical
1106 order.
1107  
1108 =head2 C<SDL_wcscasecmp( ... )>
1109  
1110 Compares at wide characters of two null-terminated wide strings.
1111  
1112 use utf8;
1113 binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
1114 my $str1 = "안녕하세요";
1115 my $str2 = "안녕히 가십시오";
1116 demo( $str1, $str2, 5 );
1117 demo( $str2, $str1, 8 );
1118 demo( $str1, $str2, 2 );
1119  
1120 sub demo ( $lhs, $rhs, $sz ) {
1121 my $rc = SDL_wcscasecmp( $lhs, $rhs );
1122 my $rel = $rc < 0 ? 'precede' : $rc > 0 ? 'follow' : 'equal';
1123 printf( "First %d characters of [%ls] %s [%ls]\n", $sz, $lhs, $rel, $rhs );
1124 }
1125  
1126 Expected parameters include:
1127  
1128 =over
1129  
1130 =item C<lhs> - pointer to a wide string
1131  
1132 =item C<rhs> - pointer to a wide string
1133  
1134 =back
1135  
1136 Returns a negative value if C<lhs> appears before C<rhs> in lexicographical
1137 order.
1138  
1139 Returns zero if C<lhs> and C<rhs> compare equal.
1140  
1141 Returns a positive value if C<lhs> appears after C<rhs> in lexicographical
1142 order.
1143  
1144  
1145 =head2 C<SDL_wcsncasecmp( ... )>
1146  
1147 Compares at most C<count> wide characters of two null-terminated wide strings
1148 while ignoring case.
1149  
1150 use utf8;
1151 binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
1152 my $str1 = "안녕하세요";
1153 my $str2 = "안녕히 가십시오";
1154 demo( $str1, $str2, 5 );
1155 demo( $str2, $str1, 8 );
1156 demo( $str1, $str2, 2 );
1157  
1158 sub demo ( $lhs, $rhs, $sz ) {
1159 my $rc = SDL_wcsncasecmp( $lhs, $rhs, $sz );
1160 my $rel = $rc < 0 ? 'precede' : $rc > 0 ? 'follow' : 'equal';
1161 printf( "First %d characters of [%ls] %s [%ls]\n", $sz, $lhs, $rel, $rhs );
1162 }
1163  
1164 Expected parameters include:
1165  
1166 =over
1167  
1168 =item C<lhs> - pointer to a wide string
1169  
1170 =item C<rhs> - pointer to a wide string
1171  
1172 =item C<count> - maximum number of characters to compare
1173  
1174 =back
1175  
1176 Returns a negative value if C<lhs> appears before C<rhs> in lexicographical
1177 order.
1178  
1179 Returns zero if C<lhs> and C<rhs> compare equal.
1180  
1181 Returns a positive value if C<lhs> appears after C<rhs> in lexicographical
1182 order.
1183  
1184 =head2 C<SDL_strlen( ... )>
1185  
1186 Returns the length of the given byte string, that is, the number of characters
1187 in a character array whose first element is pointed to by C<str> up to and not
1188 including the first null character. The behavior is undefined if there is no
1189 null character in the character array pointed to by C<str>.
1190  
1191 my $str = "How many characters does this string contain?\0";
1192 printf "without null character: %d\nwith null character: %d", SDL_strlen($str), length $str;
1193  
1194 Expected parameters include:
1195  
1196 =over
1197  
1198 =item <str> - string to be examined
1199  
1200 =back
1201  
1202 Returns the length of C<str>.
1203  
1204 =head2 C<SDL_strlcpy( ... )>
1205  
1206 Copies the character string pointed to by C<src>, including the null
1207 terminator, to the character array whose first element is pointed to by
1208 C<dest>.
1209  
1210 Expected parameters include:
1211  
1212 =over
1213  
1214 =item C<dest> - destination string
1215  
1216 =item C<src> - string to copy from
1217  
1218 =item C<max> - maximum number of characters to copy
1219  
1220 =back
1221  
1222 Returns the new length of the entire string.
1223  
1224 =head2 C<SDL_utf8strlcpy( ... )>
1225  
1226 Copies the character string pointed to by C<src>, including the null
1227 terminator, to the character array whose first element is pointed to by
1228 C<dest>.
1229  
1230 Expected parameters include:
1231  
1232 =over
1233  
1234 =item C<dest> - destination string
1235  
1236 =item C<src> - string to copy from
1237  
1238 =item C<max> - maximum number of bytes to copy
1239  
1240 =back
1241  
1242 Returns the new length of the entire string.
1243  
1244  
1245 =head2 C<SDL_strlcat( ... )>
1246  
1247 Copies the character string pointed to by C<src>, including the null
1248 terminator, to the character array whose first element is pointed to by
1249 C<dest>.
1250  
1251 Expected parameters include:
1252  
1253 =over
1254  
1255 =item C<dest> - destination string
1256  
1257 =item C<src> - string to copy from
1258  
1259 =item C<max> - maximum number of bytes to copy
1260  
1261 =back
1262  
1263 Returns the new length of the entire string.
1264  
1265 =head2 C<SDL_strdup( ... )>
1266  
1267 Duplicate a string.
1268  
1269 Expected parameters include:
1270  
1271 =over
1272  
1273 =item C<str> - string to duplicate
1274  
1275 =back
1276  
1277 Returns the new string.
1278  
1279 =head2 C<SDL_strrev( ... )>
1280  
1281 Reverses a string.
1282  
1283 Expected parameters include:
1284  
1285 =over
1286  
1287 =item C<str> - string to reverse
1288  
1289 =back
1290  
1291 Returns the given string in reverse.
1292  
1293 =head2 C<SDL_strupr( ... )>
1294  
1295 Get a string in uppercase.
1296  
1297 Expected parameters include:
1298  
1299 =over
1300  
1301 =item C<str> - string to make uppercase
1302  
1303 =back
1304  
1305 Returns the given string in uppercase.
1306  
1307 =head2 C<SDL_strlwr( ... )>
1308  
1309 Get a string in lowercase.
1310  
1311 Expected parameters include:
1312  
1313 =over
1314  
1315 =item C<str> - string to make lowercase
1316  
1317 =back
1318  
1319 Returns the given string in lowercase.
1320  
1321 =head2 C<SDL_strchr( ... )>
1322  
1323 Finds the first occurrence of C<ch> (after conversion to C<char> as if by
1324 C<(char)ch> in C) in the null-terminated byte string pointed to by C<str> (each
1325 character interpreted as C<unsigned char>). The terminating null character is
1326 considered to be a part of the string and can be found when searching for
1327 'C<\0>'.
1328  
1329 my $str = "Try not. Do, or do not. There is no try.";
1330 my $target = 'T';
1331 my $result = $str;
1332 while ( ( $result = SDL_strchr( $result, $target ) ) ) {
1333 printf "Found '%s' starting at '%s'\n", $target, $result;
1334 $result = substr $result,
1335 1; # Increment result, otherwise we'll find target at the same location
1336 }
1337  
1338 Expected parameters include:
1339  
1340 =over
1341  
1342 =item C<str> - byte string to be analyzed
1343  
1344 =item C<ch> - character to search for
1345  
1346 =back
1347  
1348 Returns a pointer to the found character in C<str>, or null if no such
1349 character is found.
1350  
1351 =head2 C<SDL_strrchr( ... )>
1352  
1353 my $szSomeFileName = "foo/bar/foobar.txt";
1354 my $pLastSlash = SDL_strrchr( $szSomeFileName, '/' );
1355 my $pszBaseName = $pLastSlash ? substr $pLastSlash, 1 : $szSomeFileName;
1356 printf "Base Name: %s", $pszBaseName;
1357  
1358 Finds the last occurrence of C<ch> (after conversion to C<char> as if by
1359 C<(char)ch> in C) in the null-terminated byte string pointed to by C<str> (each
1360 character interpreted as C<unsigned char>). The terminating null character is
1361 considered to be a part of the string and can be found when searching for
1362 'C<\0>'.
1363  
1364 Expected parameters include:
1365  
1366 =over
1367  
1368 =item C<str> - string to be analyzed
1369  
1370 =item C<ch> - character to search for
1371  
1372 =back
1373  
1374 Returns pointer to the found character in C<str>, or null if no such character
1375 is found.
1376  
1377 =head2 C<SDL_strstr( ... )>
1378  
1379 Finds the first occurrence of the null-terminated byte string pointed to by
1380 C<substr> in the null-terminated byte string pointed to by C<str>. The
1381 terminating null characters are not compared.
1382  
1383 sub find_str ( $str, $substr ) {
1384 my $pos = SDL_strstr( $str, $substr );
1385 if ($pos) {
1386 printf "found the string '%s' in '%s' at position: %ld\n", $substr, $str,
1387 length($str) - length($pos);
1388 }
1389 else {
1390 printf( "the string '%s' was not found in '%s'\n", $substr, $str );
1391 }
1392 }
1393 my $str = "one two three";
1394 find_str( $str, "two" );
1395 find_str( $str, "" );
1396 find_str( $str, "nine" );
1397 find_str( $str, "n" );
1398  
1399 Expected parameters include:
1400  
1401 =over
1402  
1403 =item C<str> - byte string to examine
1404  
1405 =item C<substr> - byte string to search for
1406  
1407 =back
1408  
1409 Returns pointer to the first character of the found substring in C<str>, or a
1410 null pointer if such substring is not found. If C<substr> points to an empty
1411 string, C<str> is returned.
1412  
1413 =head2 C<SDL_strtokr( ... )>
1414  
1415 Finds the next token in a null-terminated byte string pointed to by C<str>. The
1416 separator characters are identified by null-terminated byte string pointed to
1417 by C<delim>.
1418  
1419 This function is designed to be called multiple times to obtain successive
1420 tokens from the same string.
1421  
1422 Expected parameters include:
1423  
1424 =over
1425  
1426 =item C<str> - byte string to tokenize
1427  
1428 =item C<delim> - string identifying delimiters
1429  
1430 =item C<saveptr> - pointer to a string used internally to maintain context
1431  
1432 =back
1433  
1434 Returns a pointer to the beginning of then ext token or null if there are no
1435 more tokens.
1436  
1437 =head2 C<SDL_utf8strlen( ... )>
1438  
1439 Find the length of a UTF-8 character string
1440  
1441 Expected parameters include:
1442  
1443 =over
1444  
1445 =item C<str> - a UTF-8 string
1446  
1447 =back
1448  
1449 Returns the number of UTF-8 characters in C<str>.
1450  
1451 =head2 C<SDL_itoa( ... )>
1452  
1453 Converts an integer C<value> to a null-terminated string using the specified
1454 C<base> and stores the result in the array given by C<str> parameter.
1455  
1456 my $i = 1750;
1457 my $buffer = ' ';
1458 printf "decimal: %s\n", SDL_itoa( $i, $buffer, 10 );
1459 printf "hexadecimal: %s\n", SDL_itoa( $i, $buffer, 16 );
1460 printf "binary: %s\n", SDL_itoa( $i, $buffer, 2 );
1461  
1462 Expected parameters include:
1463  
1464 =over
1465  
1466 =item C<value> - value to be converted to a string
1467  
1468 =item C<str> - location to store result
1469  
1470 =item C<base> - numerical base used to represent the value as a string, between 2 and 36, where 10 means decimal base, 16 hexadecimal, 8 octal, and 2 binary.
1471  
1472 =back
1473  
1474 Returns a pointer to the resulting string; same as C<str>.
1475  
1476 =head2 C<SDL_uitoa( ... )>
1477  
1478 Converts an unsigned integer C<value> to a null-terminated string using the
1479 specified C<base> and stores the result in the array given by C<str> parameter.
1480  
1481 my $i = 1750;
1482 my $buffer = ' ';
1483 printf "decimal: %s\n", SDL_uitoa( $i, $buffer, 10 );
1484 printf "hexadecimal: %s\n", SDL_uitoa( $i, $buffer, 16 );
1485 printf "binary: %s\n", SDL_uitoa( $i, $buffer, 2 );
1486  
1487 Expected parameters include:
1488  
1489 =over
1490  
1491 =item C<value> - value to be converted to a string
1492  
1493 =item C<str> - location to store result
1494  
1495 =item C<base> - numerical base used to represent the value as a string, between 2 and 36, where 10 means decimal base, 16 hexadecimal, 8 octal, and 2 binary.
1496  
1497 =back
1498  
1499 Returns a pointer to the resulting string; same as C<str>.
1500  
1501 =head2 C<SDL_ltoa( ... )>
1502  
1503 Converts an long C<value> to a null-terminated string using the specified
1504 C<base> and stores the result in the array given by C<str> parameter.
1505  
1506 my $i = 1750;
1507 my $buffer = ' ';
1508 printf "decimal: %s\n", SDL_ltoa( $i, $buffer, 10 );
1509 printf "hexadecimal: %s\n", SDL_ltoa( $i, $buffer, 16 );
1510 printf "binary: %s\n", SDL_ltoa( $i, $buffer, 2 );
1511  
1512 Expected parameters include:
1513  
1514 =over
1515  
1516 =item C<value> - value to be converted to a string
1517  
1518 =item C<str> - location to store result
1519  
1520 =item C<base> - numerical base used to represent the value as a string, between 2 and 36, where 10 means decimal base, 16 hexadecimal, 8 octal, and 2 binary.
1521  
1522 =back
1523  
1524 Returns a pointer to the resulting string; same as C<str>.
1525  
1526 =head2 C<SDL_ultoa( ... )>
1527  
1528 Converts an unsigned long C<value> to a null-terminated string using the
1529 specified C<base> and stores the result in the array given by C<str> parameter.
1530  
1531 my $i = 1750;
1532 my $buffer = ' ';
1533 printf "decimal: %s\n", SDL_ultoa( $i, $buffer, 10 );
1534 printf "hexadecimal: %s\n", SDL_ultoa( $i, $buffer, 16 );
1535 printf "binary: %s\n", SDL_ultoa( $i, $buffer, 2 );
1536  
1537 Expected parameters include:
1538  
1539 =over
1540  
1541 =item C<value> - value to be converted to a string
1542  
1543 =item C<str> - location to store result
1544  
1545 =item C<base> - numerical base used to represent the value as a string, between 2 and 36, where 10 means decimal base, 16 hexadecimal, 8 octal, and 2 binary.
1546  
1547 =back
1548  
1549 Returns a pointer to the resulting string; same as C<str>.
1550  
1551 =head2 C<SDL_lltoa( ... )>
1552  
1553 Converts an 64-bit C<value> to a null-terminated string using the specified
1554 C<base> and stores the result in the array given by C<str> parameter.
1555  
1556 my $i = 1750;
1557 my $buffer = ' ';
1558 printf "decimal: %s\n", SDL_lltoa( $i, $buffer, 10 );
1559 printf "hexadecimal: %s\n", SDL_lltoa( $i, $buffer, 16 );
1560 printf "binary: %s\n", SDL_lltoa( $i, $buffer, 2 );
1561  
1562 Expected parameters include:
1563  
1564 =over
1565  
1566 =item C<value> - value to be converted to a string
1567  
1568 =item C<str> - location to store result
1569  
1570 =item C<base> - numerical base used to represent the value as a string, between 2 and 36, where 10 means decimal base, 16 hexadecimal, 8 octal, and 2 binary.
1571  
1572 =back
1573  
1574 Returns a pointer to the resulting string; same as C<str>.
1575  
1576 =head2 C<SDL_ulltoa( ... )>
1577  
1578 Converts an unsigned 64-bit C<value> to a null-terminated string using the
1579 specified C<base> and stores the result in the array given by C<str> parameter.
1580  
1581 my $i = 1750;
1582 my $buffer = ' ';
1583 printf "decimal: %s\n", SDL_ulltoa( $i, $buffer, 10 );
1584 printf "hexadecimal: %s\n", SDL_ulltoa( $i, $buffer, 16 );
1585 printf "binary: %s\n", SDL_ulltoa( $i, $buffer, 2 );
1586  
1587 Expected parameters include:
1588  
1589 =over
1590  
1591 =item C<value> - value to be converted to a string
1592  
1593 =item C<str> - location to store result
1594  
1595 =item C<base> - numerical base used to represent the value as a string, between 2 and 36, where 10 means decimal base, 16 hexadecimal, 8 octal, and 2 binary.
1596  
1597 =back
1598  
1599 Returns a pointer to the resulting string; same as C<str>.
1600  
1601 =head2 C<SDL_atoi( ... )>
1602  
1603 Interprets an integer value in a byte string pointed to by str.
1604  
1605 for my $str ( "42", "3.14159", "31337 with words", "words and 2" ) {
1606 printf "SDL_atoi('%s') is %s\n", $str, SDL_atoi($str);
1607 }
1608  
1609 Discards any whitespace characters until the first non-whitespace character is
1610 found, then takes as many characters as possible to form a valid integer number
1611 representation and converts them to an integer value. The valid integer value
1612 consists of the following parts:
1613  
1614 =over
1615  
1616 =item optional plus or minus sign
1617  
1618 =item numeric digits
1619  
1620 =back
1621  
1622  
1623 Expected parameters include:
1624  
1625 =over
1626  
1627 =item C<str> - byte string to be interpreted
1628  
1629 =back
1630  
1631 Returns an integer value corresponding to the contents of C<str> on success. If
1632 the converted value falls out of range of corresponding return type, the return
1633 value is undefined. If no conversion can be performed, ​C<0​> is returned.
1634  
1635 =head2 C<SDL_atof( ... )>
1636  
1637 Interprets a floating point value in a byte string pointed to by C<str>.
1638  
1639 for my $str ( "0.0000000123", "0.012", "15e16", "-0x1afp-2", "inF", "Nan", "invalid" ) {
1640 printf "SDL_atof('%s') is %s\n", $str, SDL_atof($str);
1641 }
1642  
1643 Function discards any whitespace characters until first non-whitespace
1644 character is found. Then it takes as many characters as possible to form a
1645 valid floating-point representation and converts them to a floating-point
1646 value. The valid floating-point value can be one of the following:
1647  
1648 =over
1649  
1650 =item decimal floating-point expression. It consists of the following parts:
1651  
1652 =over
1653  
1654 =item (optional) plus or minus sign
1655  
1656 =item nonempty sequence of decimal digits optionally containing decimal-point character (as determined by the current C locale) (defines significand)
1657  
1658 =item (optional) C<e> or C<E> followed with optional minus or plus sign and nonempty sequence of decimal digits (defines exponent to base 10)
1659  
1660 =back
1661  
1662 =back
1663  
1664 Expected parameters include:
1665  
1666 =over
1667  
1668 =item C<str> - byte string to be interpreted
1669  
1670 =back
1671  
1672 Returns a double value corresponding to the contents of C<str> on success. If
1673 the converted value falls out of range of the return type, the return value is
1674 undefined. If no conversion can be performed, C<0.0> is returned.
1675  
1676  
1677 =head2 C<SDL_strtol( ... )>
1678  
1679 Interprets an integer value in a byte string pointed to by C<str>.
1680  
1681 my $p = "10 200000000000000000000000000000 30 -40 junk";
1682 printf( "Parsing '%s':\n", $p );
1683 while (1) {
1684 my $i = SDL_strtol( $p, \my $end, 10 );
1685 last if $p eq $end;
1686 printf( "Extracted '%s', SDL_strtol returned %ld.", $p, $i );
1687 $p = $end;
1688 print "\n";
1689 }
1690 printf( "Unextracted leftover: '%s'\n\n", $p );
1691  
1692 # parsing without error handling
1693 printf( "\"1010\" in binary --> %ld\n", SDL_strtol( "1010", undef, 2 ) );
1694 printf( "\"12\" in octal --> %ld\n", SDL_strtol( "12", undef, 8 ) );
1695 printf( "\"A\" in hex --> %ld\n", SDL_strtol( "A", undef, 16 ) );
1696 printf( "\"junk\" in base-36 --> %ld\n", SDL_strtol( "junk", undef, 36 ) );
1697 printf( "\"012\" in auto-detected base --> %ld\n", SDL_strtol( "012", undef, 0 ) );
1698 printf( "\"0xA\" in auto-detected base --> %ld\n", SDL_strtol( "0xA", undef, 0 ) );
1699 printf( "\"junk\" in auto-detected base --> %ld\n", SDL_strtol( "junk", undef, 0 ) );
1700  
1701 Expected parameters include:
1702  
1703 =over
1704  
1705 =item C<str> - byte string to be interpreted
1706  
1707 =item C<str_end> - pointer to a pointer to character
1708  
1709 =item C<base> - base of the interpreted integer value
1710  
1711 =back
1712  
1713 Returns an integer value corresponding to the contents of C<str> if successful.
1714 Otherwise, C<0> is returned.
1715  
1716 =head2 C<SDL_strtoul( ... )>
1717  
1718 Interprets an unsigned integer value in a byte string pointed to by C<str>.
1719  
1720 my $p = "10 200000000000000000000000000000 30 -40";
1721 printf( "Parsing '%s':\n", $p );
1722 for ( my $i = SDL_strtoul( $p, \my $end, 10 ); $p ne $end; $i = SDL_strtoul( $p, \$end, 10 ) ) {
1723 printf( "'%s' -> ", $p );
1724 $p = $end;
1725 printf( "%lu\n", $i );
1726 }
1727  
1728 Expected parameters include:
1729  
1730 =over
1731  
1732 =item C<str> - byte string to be interpreted
1733  
1734 =item C<str_end> - pointer to a pointer to character
1735  
1736 =item C<base> - base of the interpreted integer value
1737  
1738 =back
1739  
1740 Returns an integer value corresponding to the contents of C<str> if successful.
1741 Otherwise, C<0> is returned.
1742  
1743 =head2 C<SDL_strtoll( ... )>
1744  
1745 Interprets a 64-bit integer value in a byte string pointed to by C<str>.
1746  
1747 Expected parameters include:
1748  
1749 =over
1750  
1751 =item C<str> - byte string to be interpreted
1752  
1753 =item C<str_end> - pointer to a pointer to character
1754  
1755 =item C<base> - base of the interpreted integer value
1756  
1757 =back
1758  
1759 Returns an integer value corresponding to the contents of C<str> if successful.
1760 Otherwise, C<0> is returned.
1761  
1762 =head2 C<SDL_strtoull( ... )>
1763  
1764 Interprets an unsigned 64-bit integer value in a byte string pointed to by
1765 C<str>.
1766  
1767 Expected parameters include:
1768  
1769 =over
1770  
1771 =item C<str> - byte string to be interpreted
1772  
1773 =item C<str_end> - pointer to a pointer to character
1774  
1775 =item C<base> - base of the interpreted integer value
1776  
1777 =back
1778  
1779 Returns an integer value corresponding to the contents of C<str> if successful.
1780 Otherwise, C<0> is returned.
1781  
1782 =head2 C<SDL_strtod( ... )>
1783  
1784 Interprets a floating-point value in a byte string pointed to by C<str>.
1785  
1786  
1787  
1788 Expected parameters include:
1789  
1790 =over
1791  
1792 =item C<str> - byte string to be interpreted
1793  
1794 =item C<str_end> - pointer to a pointer to character
1795  
1796 =back
1797  
1798 Returns an floating point value corresponding to the contents of C<str> if
1799 successful. Otherwise, C<0> is returned.
1800  
1801 =head2 C<SDL_strcmp( ... )>
1802  
1803 Compares two null-terminated byte strings lexicographically.
1804  
1805 sub demo ( $lhs, $rhs ) {
1806 my $rc = SDL_strcmp( $lhs, $rhs );
1807 my $rel = $rc < 0 ? "precedes" : $rc > 0 ? "follows" : "equals";
1808 printf( "[%s] %s [%s]\n", $lhs, $rel, $rhs );
1809 }
1810 my $string = "Hello World!";
1811 demo( $string, "Hello!" );
1812 demo( $string, "Hello" );
1813 demo( $string, "Hello there" );
1814 demo( substr( "Hello, everybody!", 12 ), substr "Hello, somebody!", 11 );
1815  
1816 Expected parameters include:
1817  
1818 =over
1819  
1820 =item C<lhs> - byte string to compare
1821  
1822 =item C<rhs> - byte string to compare
1823  
1824 =back
1825  
1826 Returns a negative value if C<lhs> appears before C<rhs> in lexicographical
1827 order.
1828  
1829 Returns zero if C<lhs> and C<rhs> compare equal.
1830  
1831 Returns a positive value if C<lhs> appears after C<rhs> in lexicographical
1832 order.
1833  
1834 =head2 C<SDL_strncmp( ... )>
1835  
1836 Compares at most count characters of two possibly null-terminated arrays. The
1837 comparison is done lexicographically. Characters following the null character
1838 are not compared.
1839  
1840 sub demo ( $lhs, $rhs, $sz ) {
1841 my $rc = SDL_strncmp( $lhs, $rhs, $sz );
1842 my $rel = $rc < 0 ? "precedes" : $rc > 0 ? "follows" : "equals";
1843 printf( "First %d chars of [%s] %s [%s]\n", $sz, $lhs, $rel, $rhs );
1844 }
1845 my $string = "Hello World!";
1846 demo( $string, "Hello!", 5 );
1847 demo( $string, "Hello", 10 );
1848 demo( $string, "Hello there", 10 );
1849 demo( substr( "Hello, everybody!", 12 ), substr( "Hello, somebody!", 11 ), 5 );
1850  
1851 Expected parameters include:
1852  
1853 =over
1854  
1855 =item C<lhs> - byte string to compare
1856  
1857 =item C<rhs> - byte string to compare
1858  
1859 =item C<count> - maximum number of characters to compare
1860  
1861 =back
1862  
1863 Returns a negative value if C<lhs> appears before C<rhs> in lexicographical
1864 order.
1865  
1866 Returns zero if C<lhs> and C<rhs> compare equal, or if C<count> is zero.
1867  
1868 Returns a positive value if C<lhs> appears after C<rhs> in lexicographical
1869 order.
1870  
1871 =head2 C<SDL_strcasecmp( ... )>
1872  
1873 Compares characters of two possibly strings. The comparison is done
1874 lexicographically. Characters following the null character are not compared.
1875  
1876 Expected parameters include:
1877  
1878 =over
1879  
1880 =item C<lhs> - byte string to compare
1881  
1882 =item C<rhs> - byte string to compare
1883  
1884 =back
1885  
1886 Returns a negative value if C<lhs> appears before C<rhs> in lexicographical
1887 order.
1888  
1889 Returns zero if C<lhs> and C<rhs> compare equal, or if C<count> is zero.
1890  
1891 Returns a positive value if C<lhs> appears after C<rhs> in lexicographical
1892 order.
1893  
1894 =head2 C<SDL_strncasecmp( ... )>
1895  
1896 Compares up to C<count> characters of two possibly strings ignoring case. The
1897 comparison is done lexicographically. Characters following the null character
1898 are not compared.
1899  
1900 Expected parameters include:
1901  
1902 =over
1903  
1904 =item C<lhs> - byte string to compare
1905  
1906 =item C<rhs> - byte string to compare
1907  
1908 =item C<count> - maximum number of characters to compare
1909  
1910 =back
1911  
1912 Returns a negative value if C<lhs> appears before C<rhs> in lexicographical
1913 order.
1914  
1915 Returns zero if C<lhs> and C<rhs> compare equal, or if C<count> is zero.
1916  
1917 Returns a positive value if C<lhs> appears after C<rhs> in lexicographical
1918 order.
1919  
1920 =head2 C<SDL_sscanf( ... )>
1921  
1922 Reads data from a variety of sources, interprets it according to C<format> and
1923 stores the results into given locations.
1924  
1925 my ( $i, $j ); # int
1926 my ( $x, $y ); # float
1927 my $str1 = ' ' x 10; # You *must* pre-define strings for length
1928 my $str2 = ' ' x 4;
1929 my $warr = ' ' x 8; # Don't forget wide chars
1930 my $input = '25 54.32E-1 Thompson 56789 0123 56ß水';
1931  
1932 # parses as follows:
1933 # %d: an integer
1934 # %f: a floating-point value
1935 # %9s: a string of at most 9 non-whitespace characters
1936 # %2d: two-digit integer (dig7its 5 and 6)
1937 # %f: a floating-point value (digits 7, 8, 9)
1938 # %*d an integer which isn't stored anywhere
1939 # ' ': all consecutive whitespace
1940 # %3[0-9]: a string of at most 3 digits (digits 5 and 6)
1941 # %2lc: two wide characters, using multibyte to wide conversion
1942 my $ret = SDL_sscanf( $input, "%d%f%9s%2d%f%*d %3[0-9]%2lc", \$i, \$x, $str1, \$j, \$y, $str2,
1943 $warr );
1944 printf << '', $ret, $i, $x, $str1, $j, $y, $str2, unpack 'WW', $warr;
1945 Converted %d fields:
1946 i = %d
1947 x = %f
1948 str1 = %s
1949 j = %s
1950 y = %f
1951 str2 = %s
1952 warr[0] = U+%x warr[1] = U+%x
1953  
1954 Expected parameters include:
1955  
1956 =over
1957  
1958 =item C<buffer> - string to read from
1959  
1960 =item C<format> - string similar to C<printf>
1961  
1962 =item C<vars> - list of storage locations
1963  
1964 =back
1965  
1966 Returns the number of receiving arguments successfully assigned (which may be
1967 zero in case a matching failure occurred before the first receiving argument
1968 was assigned), or EOF if input failure occurs before the first receiving
1969 argument was assigned.
1970  
1971 =head2 C<SDL_vsscanf( ... )>
1972  
1973 Reads data from a string, interprets it according to C<format> and stores the
1974 results into locations defined by C<vlist>.
1975  
1976 my ( $n, $m );
1977 printf "Parsing '1 2'...%s\n",
1978 SDL_vsscanf( '1 2', '%d %d', \$n, \$m ) == 2 ? 'success' : 'failure';
1979 printf "Parsing '1 a'...%s\n",
1980 SDL_vsscanf( '1 a', '%d %s', \$n, \$m ) == 2 ? 'success' : 'failure';
1981  
1982 Expected parameters include:
1983  
1984 =over
1985  
1986 =item C<buffer> - string to read from
1987  
1988 =item C<format> - string specifying how to read the input
1989  
1990 =item C<vlist> - variable argument list containing the receiving arguments
1991  
1992 =back
1993  
1994 Returns the number of arguments successfully read or C<EOF> if failure occurs.
1995  
1996 =head2 C<SDL_snprintf( ... )>
1997  
1998 Loads the data from the given locations, converts them to character string
1999 equivalents and writes the results to a string buffer.
2000  
2001 print "Strings:\n";
2002 my $s = 'Hello';
2003 SDL_snprintf( my $output, 128, "\t[%10s]\n\t[%-10s]\n\t[%*s]\n\t[%-10.*s]\n\t[%-*.*s]\n",
2004 $s, $s, 10, $s, 4, $s, 10, 4, $s );
2005 print $output;
2006 SDL_snprintf( $output, 100, "Characters:\t%c %%\n", 65 );
2007 print $output;
2008 print "Integers\n";
2009 SDL_snprintf( $output, 100, "Decimal:\t%i %d %.6i %i %.0i %+i %i\n", 1, 2, 3, 0, 0, 4, -4 );
2010 print $output;
2011 SDL_snprintf( $output, 100, "Hexadecimal:\t%x %x %X %#x\n", 5, 10, 10, 6 );
2012 print $output;
2013 SDL_snprintf( $output, 100, "Octal:\t%o %#o %#o\n", 10, 10, 4 );
2014 print $output;
2015 print "Floating point\n";
2016 SDL_snprintf( $output, 100, "Rounding:\t%f %.0f %.32f\n", 1.5, 1.5, 1.3 );
2017 print $output;
2018 SDL_snprintf( $output, 100, "Padding:\t%05.2f %.2f %5.2f\n", 1.5, 1.5, 1.5 );
2019 print $output;
2020 SDL_snprintf( $output, 100, "Scientific:\t%E %e\n", 1.5, 1.5 );
2021 print $output;
2022 SDL_snprintf( $output, 100, "Hexadecimal:\t%a %A\n", 1.5, 1.5 );
2023 print $output;
2024 print "Variable width control:\n";
2025 SDL_snprintf( $output, 100, "right-justified variable width: '%*c'\n", 5, ord 'x' );
2026 print $output;
2027 my $r = SDL_snprintf( $output, 100, "left-justified variable width : '%*c'\n", -5, ord 'x' );
2028 print $output;
2029 SDL_snprintf( $output, 100, "(the last printf printed %d characters)\n", $r );
2030 print $output;
2031  
2032 # fixed-width types
2033 my $val = 2**32 - 1;
2034 SDL_snprintf( $output, 100, "Largest 32-bit value is %u or %#x\n", $val, $val );
2035 print $output;
2036  
2037 Expected parameters include:
2038  
2039 =over
2040  
2041 =item C<buffer> - string to write to
2042  
2043 =item C<buf_size> - maximum number of characters which may be written
2044  
2045 =item C<format> - string specifying how to interpret the data
2046  
2047 =item C<...> - arguments specifying data to print
2048  
2049 =back
2050  
2051 Returns the number of characters written on success.
2052  
2053 =head2 C<SDL_vsnprintf( ... )>
2054  
2055 Loads the data from the given locations, converts them to character string
2056 equivalents and writes the results to a string buffer.
2057  
2058 Expected parameters include:
2059  
2060 =over
2061  
2062 =item C<buffer> - string to write to
2063  
2064 =item C<buf_size> - maximum number of characters which may be written
2065  
2066 =item C<format> - string specifying how to interpret the data
2067  
2068 =item C<...> - arguments specifying data to print
2069  
2070 =back
2071  
2072 Returns the number of characters written on success.
2073  
2074 =head2 C<SDL_acos( ... )>
2075  
2076 Computes the principal value of the arc cosine of C<arg>.
2077  
2078 printf
2079 "acos(-1) = %f\nacos(0.0) = %f 2*acos(0.0) = %f\nacos(0.5) = %f 3*acos(0.5) = %f\nacos(1) = %f\n",
2080 SDL_acos(-1), SDL_acos(0.0), 2 * SDL_acos(0), SDL_acos(0.5), 3 * SDL_acos(0.5),
2081 SDL_acos(1);
2082  
2083 Expected parameters include:
2084  
2085 =over
2086  
2087 =item C<arg> - value of a floating point or integral type
2088  
2089 =back
2090  
2091 If no errors occur, the arc cosine of C<arg> in the range C<[0 , π]>, is
2092 returned.
2093  
2094 =head2 C<SDL_acosf( ... )>
2095  
2096 Computes the principal value of the arc cosine of C<arg>.
2097  
2098  
2099 Expected parameters include:
2100  
2101 =over
2102  
2103 =item C<arg> - value of a floating point or integral type
2104  
2105 =back
2106  
2107 If no errors occur, the arc cosine of C<arg> in the range C<[0 , π]>, is
2108 returned.
2109  
2110 =head2 C<SDL_asin( ... )>
2111  
2112 Computes the principal values of the arc sine of C<arg>.
2113  
2114 printf "SDL_asin( 1.0) = %+f, 2*SDL_asin( 1.0)=%+f\n", SDL_asin(1), 2 * SDL_asin(1);
2115 printf "SDL_asin(-0.5) = %+f, 6*SDL_asin(-0.5)=%+f\n", SDL_asin(-0.5), 6 * SDL_asin(-0.5);
2116  
2117 # special values
2118 printf "SDL_asin(0.0) = %1f, SDL_asin(-0.0)=%f\n", SDL_asin(+0.0), SDL_asin(-0.0);
2119 printf "SDL_asin(1.1) = %f\n", SDL_asin(1.1);
2120  
2121 Expected parameters include:
2122  
2123 =over
2124  
2125 =item C<arg> - floating point value
2126  
2127 =back
2128  
2129 If no errors occur, the arc sine of C<arg> in the range C<[-π/2,+π/2]>, is
2130 returned.
2131  
2132 =head2 C<SDL_asinf( ... )>
2133  
2134 Computes the principal values of the arc sine of C<arg>.
2135  
2136 Expected parameters include:
2137  
2138 =over
2139  
2140 =item C<arg> - floating point value
2141  
2142 =back
2143  
2144 If no errors occur, the arc sine of C<arg> in the range C<[-π/2,+π/2]>, is
2145 returned.
2146  
2147 =head2 C<SDL_atan( ... )>
2148  
2149 Computes the principal value of the arc tangent of C<arg>.
2150  
2151 printf( "SDL_atan(1) = %f, 4*SDL_atan(1)=%f\n", SDL_atan(1), 4 * SDL_atan(1) );
2152  
2153 # special values
2154 use bigrat; # inf
2155 printf( "SDL_atan(Inf) = %f, 2*SDL_atan(Inf) = %f\n", SDL_atan(inf), 2 * SDL_atan(inf) );
2156 printf( "SDL_atan(-0.0) = %+f, SDL_atan(+0.0) = %+f\n", SDL_atan(-0.0), SDL_atan(0) );
2157  
2158 Expected parameters include:
2159  
2160 =over
2161  
2162 =item C<arg> - floating point value
2163  
2164 =back
2165  
2166 If no errors occur, the arc tangent of C<arg> in the range C<[-π/2,+π/2]>
2167 radians, is returned.
2168  
2169 =head2 C<SDL_atanf( ... )>
2170  
2171 Computes the principal value of the arc tangent of C<arg>.
2172  
2173 Expected parameters include:
2174  
2175 =over
2176  
2177 =item C<arg> - floating point value
2178  
2179 =back
2180  
2181 If no errors occur, the arc tangent of C<arg> in the range C<[-π/2 ; +π/2]>
2182 radians, is returned.
2183  
2184 =head2 C<SDL_atan2( ... )>
2185  
2186 Computes the arc tangent of C<y/x> using the signs of arguments to determine
2187 the correct quadrant.
2188  
2189 use Math::AnyNum qw[hypot];
2190  
2191 # normal usage: the signs of the two arguments determine the quadrant
2192 # atan2(1,1) = +pi/4, Quad I
2193 printf( "(+1,+1) cartesian is (%f,%f) polar\n", hypot( 1, 1 ), SDL_atan2( 1, 1 ) );
2194  
2195 # atan2(1, -1) = +3pi/4, Quad II
2196 printf( "(+1,-1) cartesian is (%f,%f) polar\n", hypot( 1, -1 ), SDL_atan2( 1, -1 ) );
2197  
2198 # atan2(-1,-1) = -3pi/4, Quad III
2199 printf( "(-1,-1) cartesian is (%f,%f) polar\n", hypot( -1, -1 ), SDL_atan2( -1, -1 ) );
2200  
2201 # atan2(-1,-1) = -pi/4, Quad IV
2202 printf( "(-1,+1) cartesian is (%f,%f) polar\n", hypot( -1, 1 ), SDL_atan2( -1, 1 ) );
2203  
2204 # special values
2205 printf( "SDL_atan2(0, 0) = %f SDL_atan2(0, -0)=%f\n", SDL_atan2( 0, 0 ), SDL_atan2( 0, -0.0 ) );
2206 printf( "SDL_atan2(7, 0) = %f SDL_atan2(7, -0)=%f\n", SDL_atan2( 7, 0 ), SDL_atan2( 7, -0.0 ) );
2207  
2208 Expected parameters include:
2209  
2210 =over
2211  
2212 =item C<x> - floating point value
2213  
2214 =item C<y> - floating point value
2215  
2216 =back
2217  
2218 If no errors occur, the arc tangent of C<y/x> in the range C<[-π ; +π]>
2219 radians, is returned.
2220  
2221 =head2 C<SDL_atan2f( ... )>
2222  
2223 Computes the arc tangent of C<y/x> using the signs of arguments to determine
2224 the correct quadrant.
2225  
2226 Expected parameters include:
2227  
2228 =over
2229  
2230 =item C<x> - floating point value
2231  
2232 =item C<y> - floating point value
2233  
2234 =back
2235  
2236 If no errors occur, the arc tangent of C<y/x> in the range C<[-π ; +π]>
2237 radians, is returned.
2238  
2239 =head2 C<SDL_ceil( ... )>
2240  
2241 Computes the smallest integer value not less than C<arg>.
2242  
2243 printf"SDL_ceil(+2.4) = %+.1f\n", SDL_ceil(2.4);
2244 printf"SDL_ceil(-2.4) = %+.1f\n", SDL_ceil(-2.4);
2245 printf"SDL_ceil(-0.0) = %+.1f\n", SDL_ceil(-0.0);
2246 use bigrat; # inf
2247 printf"SDL_ceil(-Inf) = %+f\n", SDL_ceil(-inf);
2248  
2249 Expected parameters include:
2250  
2251 =over
2252  
2253 =item C<arg> - floating point value
2254  
2255 =back
2256  
2257 If no errors occur, the smallest integer value not less than C<arg>, that is
2258 C<⌈arg⌉>, is returned.
2259  
2260 =head2 C<SDL_ceilf( ... )>
2261  
2262 Computes the smallest integer value not less than C<arg>.
2263  
2264 Expected parameters include:
2265  
2266 =over
2267  
2268 =item C<arg> - floating point value
2269  
2270 =back
2271  
2272 If no errors occur, the smallest integer value not less than C<arg>, that is
2273 C<⌈arg⌉>, is returned.
2274  
2275 =head2 C<SDL_copysign( ... )>
2276  
2277 Composes a floating point value with the magnitude of C<mag> and the sign of
2278 C<sgn>.
2279  
2280 printf "SDL_copysign(1.0,+2.0) = %+f\n", SDL_copysign( 1.0, +2.0 );
2281 printf "SDL_copysign(1.0,-2.0) = %+f\n", SDL_copysign( 1.0, -2.0 );
2282 use bigrat;
2283 printf "SDL_copysign(inf,-2.0) = %+f\n", SDL_copysign( inf, -2.0 );
2284 printf "SDL_copysign(NaN,-2.0) = %+f\n", SDL_copysign( NaN, -2.0 );
2285  
2286 Expected parameters include:
2287  
2288 =over
2289  
2290 =item C<mag> - floating point value
2291  
2292 =item C<sgn> - floating point value
2293  
2294 =back
2295  
2296 If no errors occur, the floating point value with the magnitude of C<mag> and
2297 the sign of C<sgn> is returned.
2298  
2299 If C<mag> is C<NaN>, then C<NaN> with the sign of C<sgn> is returned however
2300 perl cannot properly express C<-NaN>.
2301  
2302 If C<sgn> is C<-0>, the result is only negative if the implementation supports
2303 the signed zero consistently in arithmetic operations.
2304  
2305 =head2 C<SDL_copysignf( ... )>
2306  
2307 Expected parameters include:
2308  
2309 =over
2310  
2311 =item C<mag> - floating point value
2312  
2313 =item C<sgn> - floating point value
2314  
2315 =back
2316  
2317 If no errors occur, the floating point value with the magnitude of C<mag> and
2318 the sign of C<sgn> is returned.
2319  
2320 If C<mag> is C<NaN>, then C<NaN> with the sign of C<sgn> is returned however
2321 perl cannot properly express C<-NaN>.
2322  
2323 If C<sgn> is C<-0>, the result is only negative if the implementation supports
2324 the signed zero consistently in arithmetic operations.
2325  
2326  
2327 =head2 C<SDL_cos( ... )>
2328  
2329 Computes the cosine of C<arg> (measured in radians).
2330  
2331 my $pi = M_PI;
2332  
2333 # typical usage
2334 printf "SDL_cos(pi/3) = %f\n", SDL_cos( $pi / 3 );
2335 printf "SDL_cos(pi/2) = %f\n", SDL_cos( $pi / 2 );
2336 printf "SDL_cos(-3*pi/4) = %f\n", SDL_cos( -3 * $pi / 4 );
2337  
2338 # special values
2339 printf "SDL_cos(+0) = %f\n", SDL_cos(0.0);
2340 printf "SDL_cos(-0) = %f\n", SDL_cos(-0.0);
2341 use bigrat;
2342 printf "SDL_cos(INFINITY) = %f\n", SDL_cos(inf);
2343  
2344 Expected parameters include:
2345  
2346 =over
2347  
2348 =item C<arg> - floating point value representing angle in radians
2349  
2350 =back
2351  
2352 If no errors occur, the cosine of C<arg> in the range C<[-1 ; +1]>, is
2353 returned.
2354  
2355 =head2 C<SDL_cosf( ... )>
2356  
2357 Computes the cosine of C<arg> (measured in radians).
2358  
2359 Expected parameters include:
2360  
2361 =over
2362  
2363 =item C<arg> - floating point value representing angle in radians
2364  
2365 =back
2366  
2367 If no errors occur, the cosine of C<arg> in the range C<[-1 ; +1]>, is
2368 returned.
2369  
2370 =head2 C<SDL_exp( ... )>
2371  
2372 Computes the C<e> (Euler's number, C<2.7182818>) raised to the given power
2373 C<arg>.
2374  
2375 printf "SDL_exp(1) = %f\n", SDL_exp(1);
2376 printf "FV of \$100, continuously compounded at 3%% for 1 year = %f\n", 100 * SDL_exp(0.03);
2377  
2378 # special values
2379 printf "SDL_exp(-0) = %f\n", SDL_exp(-0.0);
2380 printf "SDL_exp(-Inf) = %f\n", SDL_exp( -inf );
2381  
2382 # overflow
2383 printf "SDL_exp(710) = %f\n", SDL_exp(710);
2384  
2385 Expected parameters include:
2386  
2387 =over
2388  
2389 =item C<arg> - floating point value
2390  
2391 =back
2392  
2393 If no errors occur, the base-e exponential of C<arg> is returned.
2394  
2395 =head2 C<SDL_expf( ... )>
2396  
2397 Computes the C<e> (Euler's number, C<2.7182818>) raised to the given power
2398 C<arg>.
2399  
2400 Expected parameters include:
2401  
2402 =over
2403  
2404 =item C<arg> - floating point value
2405  
2406 =back
2407  
2408 If no errors occur, the base-e exponential of C<arg> is returned.
2409  
2410 =head2 C<SDL_fabs( ... )>
2411  
2412 Computes the absolute value of a floating point value C<arg>.
2413  
2414 printf( "SDL_fabs(+3) = %f\n", SDL_fabs(+3.0) );
2415 printf( "SDL_fabs(-3) = %f\n", SDL_fabs(-3.0) );
2416  
2417 # special values
2418 printf( "SDL_fabs(-0) = %f\n", SDL_fabs(-0.0) );
2419 printf( "SDL_fabs(-Inf) = %f\n", SDL_fabs( -inf ) );
2420 printf( "%f\n", num_int( 0.0, 2 * M_PI, 100000 ) );
2421  
2422 sub num_int ( $a, $b, $n ) { # assumes all area is positive
2423 return 0.0 if $a == $b;
2424 $n ||= 1; # avoid division by zero
2425 my $h = ( $b - $a ) / $n;
2426 my $sum = 0.0;
2427 for ( my $k = 0; $k < $n; ++$k ) {
2428 $sum += $h * SDL_fabs( sin( $a + $k * $h ) );
2429 }
2430 return $sum;
2431 }
2432  
2433 Expected parameters include:
2434  
2435 =over
2436  
2437 =item C<arg> - floating point value
2438  
2439 =back
2440  
2441 If successful, returns the absolute value of C<arg> (C<|arg|>). The value
2442 returned is exact and does not depend on any rounding modes.
2443  
2444 =head2 C<SDL_fabsf( ... )>
2445  
2446 Computes the absolute value of a floating point value C<arg>.
2447  
2448 Expected parameters include:
2449  
2450 =over
2451  
2452 =item C<arg> - floating point value
2453  
2454 =back
2455  
2456 If successful, returns the absolute value of C<arg> (C<|arg|>). The value
2457 returned is exact and does not depend on any rounding modes.
2458  
2459 =head2 C<SDL_floor( ... )>
2460  
2461 Computes the largest integer value not greater than C<arg>.
2462  
2463 printf "SDL_floor(+2.7) = %+.1f\n", SDL_floor(2.7);
2464 printf "SDL_floor(-2.7) = %+.1f\n", SDL_floor(-2.7);
2465 printf "SDL_floor(-0.0) = %+.1f\n", SDL_floor(-0.0);
2466 printf "SDL_floor(-Inf) = %+f\n", SDL_floor( -INFINITY );
2467  
2468 Expected parameters include:
2469  
2470 =over
2471  
2472 =item C<arg> - floating point value
2473  
2474 =back
2475  
2476 If no errors occur, the largest integer value not greater than C<arg>, that is
2477 C<⌊arg⌋>, is returned.
2478  
2479 =head2 C<SDL_floorf( ... )>
2480  
2481 Computes the largest integer value not greater than C<arg>.
2482  
2483 Expected parameters include:
2484  
2485 =over
2486  
2487 =item C<arg> - floating point value
2488  
2489 =back
2490  
2491 If no errors occur, the largest integer value not greater than C<arg>, that is
2492 C<⌊arg⌋>, is returned.
2493  
2494 =head2 C<SDL_trunc( ... )>
2495  
2496 Computes the nearest integer not greater in magnitude than C<arg>.
2497  
2498 printf "SDL_trunc(+2.7) = %+.1f\n", SDL_trunc(2.7);
2499 printf "SDL_trunc(-2.7) = %+.1f\n", SDL_trunc(-2.7);
2500 printf "SDL_trunc(-0.0) = %+.1f\n", SDL_trunc(-0.0);
2501 printf "SDL_trunc(-Inf) = %+f\n", SDL_trunc( -INFINITY );
2502  
2503 Expected parameters include:
2504  
2505 =over
2506  
2507 =item C<arg> - floating point value
2508  
2509 =back
2510  
2511 If no errors occur, the nearest integer value not greater in magnitude than
2512 C<arg> (in other words, C<arg> rounded towards zero), is returned.
2513  
2514 =head2 C<SDL_truncf( ... )>
2515  
2516 Computes the nearest integer not greater in magnitude than C<arg>.
2517  
2518 Expected parameters include:
2519  
2520 =over
2521  
2522 =item C<arg> - floating point value
2523  
2524 =back
2525  
2526 If no errors occur, the nearest integer value not greater in magnitude than
2527 C<arg> (in other words, C<arg> rounded towards zero), is returned.
2528  
2529 =head2 C<SDL_fmod( ... )>
2530  
2531 Computes the floating-point remainder of the division operation C<x/y>.
2532  
2533 printf "SDL_fmod(+5.1, +3.0) = %.1f\n", SDL_fmod( 5.1, 3 );
2534 printf "SDL_fmod(-5.1, +3.0) = %.1f\n", SDL_fmod( -5.1, 3 );
2535 printf "SDL_fmod(+5.1, -3.0) = %.1f\n", SDL_fmod( 5.1, -3 );
2536 printf "SDL_fmod(-5.1, -3.0) = %.1f\n", SDL_fmod( -5.1, -3 );
2537  
2538 # special values
2539 printf "SDL_fmod(+0.0, 1.0) = %.1f\n", SDL_fmod( 0, 1 );
2540 printf "SDL_fmod(-0.0, 1.0) = %.1f\n", SDL_fmod( -0.0, 1 );
2541 printf "SDL_fmod(+5.1, Inf) = %.1f\n", SDL_fmod( 5.1, 'INFINITY' );
2542  
2543 # error handling
2544 printf "SDL_fmod(+5.1, 0) = %.1f\n", SDL_fmod( 5.1, 0 );
2545  
2546 Expected parameters include:
2547  
2548 =over
2549  
2550 =item C<x> - floating point value
2551  
2552 =item C<y> - floating point value
2553  
2554 =back
2555  
2556 If successful, returns the floating-point remainder of the division C<x/y> as
2557 defined above.
2558  
2559 =head2 C<SDL_fmodf( ... )>
2560  
2561 Computes the floating-point remainder of the division operation C<x/y>.
2562  
2563 Expected parameters include:
2564  
2565 =over
2566  
2567 =item C<x> - floating point value
2568  
2569 =item C<y> - floating point value
2570  
2571 =back
2572  
2573 If successful, returns the floating-point remainder of the division C<x/y> as
2574 defined above.
2575  
2576 =head2 C<SDL_log( ... )>
2577  
2578 Computes the natural (base e) logarithm of C<arg>.
2579  
2580 printf "SDL_log(1) = %f\n", SDL_log(1);
2581 printf "base-5 logarithm of 125 = %f\n", SDL_log(125) / SDL_log(5);
2582  
2583 # special values
2584 printf "SDL_log(1) = %f\n", SDL_log(1);
2585 printf "SDL_log(+Inf) = %f\n", SDL_log('INFINITY');
2586  
2587 #error handling
2588 printf "SDL_log(0) = %f\n", SDL_log(0);
2589  
2590 Expected parameters include:
2591  
2592 =over
2593  
2594 =item C<arg> - floating point value
2595  
2596 =back
2597  
2598 If no errors occur, the natural (base-e) logarithm of C<arg> is returned.
2599  
2600 =head2 C<SDL_logf( ... )>
2601  
2602 Computes the natural (base e) logarithm of C<arg>.
2603  
2604 Expected parameters include:
2605  
2606 =over
2607  
2608 =item C<arg> - floating point value
2609  
2610 =back
2611  
2612 If no errors occur, the natural (base-e) logarithm of C<arg> is returned.
2613  
2614 =head2 C<SDL_log10( ... )>
2615  
2616 Computes the common (base-10) logarithm of C<arg>.
2617  
2618 printf "SDL_log10(1000) = %f\n", SDL_log10(1000);
2619 printf "log10(0.001) = %f\n", SDL_log10(0.001);
2620 printf "base-5 logarithm of 125 = %f\n", SDL_log10(125) / SDL_log10(5);
2621  
2622 # special values
2623 printf "SDL_log10(1) = %f\n", SDL_log10(1);
2624 printf "SDL_log10(+Inf) = %f\n", SDL_log10('INFINITY');
2625  
2626 # error handling
2627 printf "SDL_log10(0) = %f\n", SDL_log10(0);
2628  
2629 Expected parameters include:
2630  
2631 =over
2632  
2633 =item C<arg> - value of floating point or integral type
2634  
2635 =back
2636  
2637 If no errors occur, the common (base-10) logarithm of C<arg> is returned.
2638  
2639 =head2 C<SDL_log10f( ... )>
2640  
2641 Computes the common (base-10) logarithm of C<arg>.
2642  
2643 Expected parameters include:
2644  
2645 =over
2646  
2647 =item C<arg> - value of floating point or integral type
2648  
2649 =back
2650  
2651 If no errors occur, the common (base-10) logarithm of C<arg> is returned.
2652  
2653 =head2 C<SDL_pow( ... )>
2654  
2655 Computes the value of C<base> raised to the power C<exponent>.
2656  
2657 # typical usage
2658 printf "SDL_pow(2, 10) = %f\n", SDL_pow( 2, 10 );
2659 printf "SDL_pow(2, 0.5) = %f\n", SDL_pow( 2, 0.5 );
2660 printf "SDL_pow(-2, -3) = %f\n", SDL_pow( -2, -3 );
2661  
2662 # special values
2663 printf "SDL_pow(-1, NAN) = %f\n", SDL_pow( -1, 'NaN' );
2664 printf "SDL_pow(+1, NAN) = %f\n", SDL_pow( +1, 'NaN' );
2665 printf "SDL_pow(INFINITY, 2) = %f\n", SDL_pow( 'INFINITY', 2 );
2666 printf "SDL_pow(INFINITY, -1) = %f\n", SDL_pow( 'INFINITY', -1 );
2667  
2668 # error handling
2669 printf "SDL_pow(-1, 1/3) = %f\n", SDL_pow( -1, 1.0 / 3 );
2670 printf "SDL_pow(-0, -3) = %f\n", SDL_pow( -0.0, -3 );
2671  
2672 Expected parameters include:
2673  
2674 =over
2675  
2676 =item C<base> - floating point value
2677  
2678 =item C<exponent> - floating point value
2679  
2680 =back
2681  
2682 If no errors occur, C<base> raised to the power of C<exponent> is returned.
2683  
2684 =head2 C<SDL_powf( ... )>
2685  
2686 Computes the value of C<base> raised to the power C<exponent>.
2687  
2688 Expected parameters include:
2689  
2690 =over
2691  
2692 =item C<base> - floating point value
2693  
2694 =item C<exponent> - floating point value
2695  
2696 =back
2697  
2698 If no errors occur, C<base> raised to the power of C<exponent> is returned.
2699  
2700 =head2 C<SDL_round( ... )>
2701  
2702 Computes the nearest integer value to C<arg> (in floating-point format),
2703 rounding halfway cases away from zero, regardless of the current rounding mode.
2704  
2705 printf 'SDL_round(+2.3) = %+.1f ', SDL_round(2.3);
2706 printf 'SDL_round(+2.5) = %+.1f ', SDL_round(2.5);
2707 printf "SDL_round(+2.7) = %+.1f\n", SDL_round(2.7);
2708 printf 'SDL_round(-2.3) = %+.1f ', SDL_round(-2.3);
2709 printf 'SDL_round(-2.5) = %+.1f ', SDL_round(-2.5);
2710 printf "SDL_round(-2.7) = %+.1f\n", SDL_round(-2.7);
2711 printf "SDL_round(-0.0) = %+.1f\n", SDL_round(-.0);
2712 printf "SDL_round(-Inf) = %+f\n", SDL_round('-INFINITY');
2713  
2714 Expected parameters include:
2715  
2716 =over
2717  
2718 =item C<arg> - floating point value
2719  
2720 =back
2721  
2722 If no errors occur, the nearest integer value to C<arg>, rounding halfway cases
2723 away from zero, is returned.
2724  
2725 =head2 C<SDL_roundf( ... )>
2726  
2727 Computes the nearest integer value to C<arg> (in floating-point format),
2728 rounding halfway cases away from zero, regardless of the current rounding mode.
2729  
2730 Expected parameters include:
2731  
2732 =over
2733  
2734 =item C<arg> - floating point value
2735  
2736 =back
2737  
2738 If no errors occur, the nearest integer value to C<arg>, rounding halfway cases
2739 away from zero, is returned.
2740  
2741 =head2 C<SDL_lround( ... )>
2742  
2743 Computes the nearest integer value to C<arg> (in integer format), rounding
2744 halfway cases away from zero, regardless of the current rounding mode.
2745  
2746 printf 'SDL_lround(+2.3) = %ld ', SDL_lround(2.3);
2747 printf 'SDL_lround(+2.5) = %ld ', SDL_lround(2.5);
2748 printf "SDL_lround(+2.7) = %ld\n", SDL_lround(2.7);
2749 printf 'SDL_lround(-2.3) = %ld ', SDL_lround(-2.3);
2750 printf 'SDL_lround(-2.5) = %ld ', SDL_lround(-2.5);
2751 printf "SDL_lround(-2.7) = %ld\n", SDL_lround(-2.7);
2752 printf "SDL_lround(-0.0) = %ld\n", SDL_lround(-.0);
2753 printf "SDL_lround(-Inf) = %ld\n", SDL_lround('-INFINITY'); # FE_INVALID raised
2754  
2755 Expected parameters include:
2756  
2757 =over
2758  
2759 =item C<arg> - floating point value
2760  
2761 =back
2762  
2763 If no errors occur, the nearest integer value to C<arg>, rounding halfway cases
2764 away from zero, is returned.
2765  
2766  
2767 =head2 C<SDL_lroundf( ... )>
2768  
2769 Computes the nearest integer value to C<arg> (in integer format), rounding
2770 halfway cases away from zero, regardless of the current rounding mode.
2771  
2772 Expected parameters include:
2773  
2774 =over
2775  
2776 =item C<arg> - floating point value
2777  
2778 =back
2779  
2780 If no errors occur, the nearest integer value to C<arg>, rounding halfway cases
2781 away from zero, is returned.
2782  
2783 =head2 C<SDL_scalbn( ... )>
2784  
2785 Multiplies a floating point value C<arg> by C<FLT_RADIX> (the radix (integer
2786 base) used by the representation of all three floating-point types) raised to
2787 power C<exp>.
2788  
2789 printf "SDL_scalbn(7, -4) = %f\n", SDL_scalbn( 7, -4 );
2790 printf "SDL_scalbn(1, -1074) = %g (minimum positive subnormal double)\n",
2791 SDL_scalbn( 1, -1074 );
2792 printf "SDL_scalbn(.9999999999999999, 1024) = %g (largest finite double)\n",
2793 SDL_scalbn( 0.99999999999999989, 1024 );
2794  
2795 # special values
2796 printf "SDL_scalbn(-0, 10) = %f\n", SDL_scalbn( -.0, 10 );
2797 printf "SDL_scalbn(-Inf, -1) = %f\n", SDL_scalbn( '-INFINITY', -1 );
2798  
2799 # error handling
2800 printf "SDL_scalbn(1, 1024) = %f\n", SDL_scalbn( 1, 1024 );
2801  
2802 Expected parameters include:
2803  
2804 =over
2805  
2806 =item C<arg> - floating point value
2807  
2808 =item C<exp> - integer value
2809  
2810 =back
2811  
2812 If no errors occur, C<arg> multiplied by C<FLT_RADIX> to the power of C<exp> is
2813 returned.
2814  
2815 =head2 C<SDL_scalbnf( ... )>
2816  
2817 Multiplies a floating point value C<arg> by C<FLT_RADIX> (the radix (integer
2818 base) used by the representation of all three floating-point types) raised to
2819 power C<exp>.
2820  
2821 Expected parameters include:
2822  
2823 =over
2824  
2825 =item C<arg> - floating point value
2826  
2827 =item C<exp> - integer value
2828  
2829 =back
2830  
2831 If no errors occur, C<arg> multiplied by C<FLT_RADIX> to the power of C<exp> is
2832 returned.
2833  
2834 =head2 C<SDL_sin( ... )>
2835  
2836 Computes the sine of C<arg> (measured in radians).
2837  
2838 my $pi = SDL_acos(-1);
2839  
2840 # typical usage
2841 printf "SDL_sin(pi/6) = %f\n", SDL_sin( $pi / 6 );
2842 printf "SDL_sin(pi/2) = %f\n", SDL_sin( $pi / 2 );
2843 printf "SDL_sin(-3*pi/4) = %f\n", SDL_sin( -3 * $pi / 4 );
2844  
2845 # special values
2846 printf "SDL_sin(+0) = %f\n", SDL_sin(0);
2847 printf "SDL_sin(-0) = %f\n", SDL_sin(-.0);
2848 printf "SDL_sin(INFINITY) = %f\n", SDL_sin('INFINITY');
2849  
2850 Expected parameters include:
2851  
2852 =over
2853  
2854 =item C<arg> - floating point value representing an angle in radians
2855  
2856 =back
2857  
2858 If no errors occur, the sine of C<arg> in the range [-1 ; +1], is returned.
2859  
2860 =head2 C<SDL_sinf( ... )>
2861  
2862 Computes the sine of C<arg> (measured in radians).
2863  
2864 Expected parameters include:
2865  
2866 =over
2867  
2868 =item C<arg> - floating point value representing an angle in radians
2869  
2870 =back
2871  
2872 If no errors occur, the sine of C<arg> in the range [-1 ; +1], is returned.
2873  
2874 =head2 C<SDL_sqrt( ... )>
2875  
2876 Computes square root of C<arg>.
2877  
2878 # normal use
2879 printf "SDL_sqrt(100) = %f\n", SDL_sqrt(100);
2880 printf "SDL_sqrt(2) = %f\n", SDL_sqrt(2);
2881 printf "golden ratio = %f\n", ( 1 + SDL_sqrt(5) ) / 2;
2882  
2883 # special values
2884 printf "SDL_sqrt(-0) = %f\n", SDL_sqrt(-0.0);
2885  
2886 # error handling
2887 printf "SDL_sqrt(-1.0) = %f\n", SDL_sqrt(-1);
2888  
2889 Expected parameters include:
2890  
2891 =over
2892  
2893 =item C<arg> - floating point value
2894  
2895 =back
2896  
2897 If no errors occur, square root of Carg> (C<√arg>), is returned.
2898  
2899 =head2 C<SDL_sqrtf( ... )>
2900  
2901 Computes square root of C<arg>.
2902  
2903 Expected parameters include:
2904  
2905 =over
2906  
2907 =item C<arg> - floating point value
2908  
2909 =back
2910  
2911 If no errors occur, square root of Carg> (C<√arg>), is returned.
2912  
2913 =head2 C<SDL_tan( ... )>
2914  
2915 Computes the tangent of C<arg> (measured in radians).
2916  
2917 my $pi = SDL_acos(-1);
2918  
2919 # typical usage
2920 printf "SDL_tan (pi/4) = %+f\n", SDL_tan( $pi / 4 ); # 45 deg
2921 printf "SDL_tan(3*pi/4) = %+f\n", SDL_tan( 3 * $pi / 4 ); # 135 deg
2922 printf "SDL_tan(5*pi/4) = %+f\n", SDL_tan( 5 * $pi / 4 ); # -135 deg
2923 printf "SDL_tan(7*pi/4) = %+f\n", SDL_tan( 7 * $pi / 4 ); # -45 deg
2924  
2925 # special values
2926 printf "SDL_tan(+0) = %+f\n", SDL_tan(0.0);
2927 printf "SDL_tan(-0) = %+f\n", SDL_tan(-0.0);
2928  
2929 # error handling
2930 printf "SDL_tan(INFINITY) = %f\n", SDL_tan('INFINITY');
2931  
2932 Expected parameters include:
2933  
2934 =over
2935  
2936 =item C<arg> - floating point value representing angle in radians
2937  
2938 =back
2939  
2940 If no errors occur, the tangent of C<arg> is returned.
2941  
2942 =head2 C<SDL_tanf( ... )>
2943  
2944 Computes the tangent of C<arg> (measured in radians).
2945  
2946 Expected parameters include:
2947  
2948 =over
2949  
2950 =item C<arg> - floating point value representing angle in radians
2951  
2952 =back
2953  
2954 If no errors occur, the tangent of C<arg> is returned.
2955  
2956 =head2 C<SDL_iconv_open( ... )>
2957  
2958 Allocate descriptor for character set conversion.
2959  
2960 Expected parameters include:
2961  
2962 =over
2963  
2964 =item C<tocode> - name of the destination encoding
2965  
2966 =item C<fromcode> - name of the source encoding
2967  
2968 =back
2969  
2970 The values permitted for fromcode and tocode and the supported combinations are
2971 system-dependent. For the GNU C library, the permitted values are listed by the
2972 C<`iconv --list`> command, and all combinations of the listed values are
2973 supported.
2974  
2975 Returns a new L<SDL2::iconv_t> object.
2976  
2977 =head2 C<SDL_iconv_close( ... )>
2978  
2979 Deallocate descriptor for character set conversion.
2980  
2981 Expected parameters include:
2982  
2983 =over
2984  
2985 =item C<cd> - L<SDL2::iconv_t> object
2986  
2987 =back
2988  
2989 Returns C<0> on success; otherwise returns C<-1>.
2990  
2991 =head2 C<SDL_iconv( ... )>
2992  
2993 Converts a stream of data between encodings.
2994  
2995 Expected parameters include:
2996  
2997 =over
2998  
2999 =item C<cd> - L<SDL2::iconv_t> object
3000  
3001 =item C<inbuf> - pointer to a buffer
3002  
3003 =item C<inbytesleft> - pointer to an integer
3004  
3005 =item C<outbuf> - pointer to a buffer
3006  
3007 =item C<outbytesleft> - pointer to an integer
3008  
3009 =back
3010  
3011 Returns an L<< C<iconv( )> error code|/C<iconv( )> error codes >>.
3012  
3013 =head2 C<SDL_iconv_string( ... )>
3014  
3015 Converts a string between encodings in one pass.
3016  
3017 Expected parameters include:
3018  
3019 =over
3020  
3021 =item C<tocode> - encoding of the outcome of this conversion
3022  
3023 =item C<fromcode> - encoding of the encoding text
3024  
3025 =item C<inbuf> - input buffer
3026  
3027 =item C<inbytesleft> - number of characters left to encode
3028  
3029 =back
3030  
3031  
3032 Returns a string that must be freed with C<SDL_free( ... )> on success; undef
3033 on error.
3034  
3035 =head2 C<SDL_iconv_utf8_locale( ... )>
3036  
3037 Converts string from UTF-8 to the local encoding.
3038  
3039 Expected parameters include:
3040  
3041 =over
3042  
3043 =item C<string> - UTF-8 encoded string
3044  
3045 =back
3046  
3047 Returns the re-encoded string.
3048  
3049 =head1 Defined values and Enumerations
3050  
3051 These might actually be useful and may be imported with the listed tags.
3052  
3053 =head2 C<SDL_bool>
3054  
3055 Basic boolean values for added sugar. Imported with the C<:bool> tag.
3056  
3057 =over
3058  
3059 =item C<SDL_TRUE> - not false
3060  
3061 =item C<SDL_FALSE> - not true
3062  
3063 =back
3064  
3065 =head2 C<M_PI>
3066  
3067 Pi in a pinch.
3068  
3069 =head2 Memory allocation callbacks
3070  
3071 Not sure why you'd ever want to do this, but you may override SDL's internal
3072 memory handling with these closure types.
3073  
3074 =head3 C<SDL_malloc_func>
3075  
3076 Parameters to expect:
3077  
3078 =over
3079  
3080 =item C<size> - C<size_t> type
3081  
3082 =back
3083  
3084 You must return a pointer to allocated memory.
3085  
3086 =head3 C<SDL_calloc_func>
3087  
3088 Parameters to expect:
3089  
3090 =over
3091  
3092 =item C<nmemb> - number of members in the array
3093  
3094 =item C<size> - C<size_t> type indicating the size of the members
3095  
3096 =back
3097  
3098 You must return a pointer to allocated memory.
3099  
3100 =head3 C<SDL_realloc_func>
3101  
3102 Parameters to expect:
3103  
3104 =over
3105  
3106 =item C<mem> - an opaque pointer to allocated memory
3107  
3108 =item C<size> - C<size_t> type indicating how much memory to allocate
3109  
3110 =back
3111  
3112 You must return a pointer to allocated memory.
3113  
3114 =head3 C<SDL_free_func>
3115  
3116 Parameters to expect:
3117  
3118 =over
3119  
3120 =item C<mem> - opaque pointer to allocated memory which will be freed
3121  
3122 =back
3123  
3124 =head2 C<iconv( )> error codes
3125  
3126 The SDL implementation of C<iconv( )> returns these error codes:
3127  
3128 =over
3129  
3130 =item C<SDL_ICONV_ERROR>
3131  
3132 =item C<SDL_ICONV_E2BIG>
3133  
3134 =item C<SDL_ICONV_EILSEQ>
3135  
3136 =item C<SDL_ICONV_EINVAL>
3137  
3138 =back
3139  
3140 =head1 LICENSE
3141  
3142 Copyright (C) Sanko Robinson.
3143  
3144 This library is free software; you can redistribute it and/or modify it under
3145 the terms found in the Artistic License 2. Other copyrights, terms, and
3146 conditions may apply to data transmitted through this module.
3147  
3148 =head1 AUTHOR
3149  
3150 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
3151  
3152 =begin stopwords
3153  
3154 whitespace abcdefghijklmnopqrstuvwxyz (0123456789abcdefABCDEF) checksum isupper
3155 significand islower lhs rhs dest tokenize ext fromcode tocode src
3156  
3157 =end stopwords
3158  
3159 =cut
3160  
3161 };
3162 1;