NAME
SDL2::stdinc - General C Language Support Functions
SYNOPSIS
use SDL2 qw[:stdinc];
DESCRIPTION
This is a general package that includes C language support where platform differences are abstracted away.
Functions
These functions likely will not be used in end-user code but may be imported with the :stdinc
tag.
SDL_malloc( ... )
Wraps the standard memory allocation functions for the specific platform.
Expected parameters include:
Returns a pointer to the memory.
SDL_calloc( ... )
Allocates memory for an array of num objects of size and initializes all bytes in the allocated storage to zero.
Expected parameters include:
Returns a pointer to the memory.
SDL_realloc( ... )
Reallocates the given area of memory.
Expected parameters include:
SDL_free( ... )
Frees allocated memory.
Expected parameters include:
SDL_GetMemoryFunctions( ... )
Get the current set of SDL memory functions.
SDL_GetMemoryFunctions( \my $malloc, \my $calloc, \my $realloc, \my $free );
my $mem = $malloc->(100);
# Do odd, low level things with your memory
$free->($mem);
Expected parameters include:
malloc_func
- pointer which will be filled with aSDL_malloc_func
calloc_func
- pointer which will be filled with aSDL_calloc_func
realloc_func
- pointer which will be filled with aSDL_realloc_func
free_func
- pointer which will be filled with aSDL_free_func
SDL_SetMemoryFunctions( ... )
Replace SDL's memory allocation functions with a custom set.
use Data::Dump;
SDL_SetMemoryFunctions( # poor example but I have no idea
sub { ddx \@_; ... }, # why you're doing this anyway
sub { ddx \@_; ... },
sub { ddx \@_; ... },
sub { ddx \@_; ... },
);
Note: If you are replacing SDL's memory functions, you should call SDL_GetNumAllocations( )
and be very careful if it returns non-zero. That means that your free function will be called with memory allocated by the previous memory allocation functions.
Expected parameters include:
malloc_func
- aSDL_malloc_func
closurecalloc_func
- aSDL_calloc_func
closurerealloc_func
- aSDL_realloc_func
closurefree_func
- aSDL_free_func
closure
If you pass a simple code reference to any of the parameters, they'll be wrapped in a closure and made sticky
SDL_GetNumAllocations( )
Get the number of outstanding (unfreed) allocations.
my $leaks = SDL_GetNumAllocations( );
Returns an integer.
SDL_getenv( ... )
Get environment variable's value.
my $path = SDL_getenv( 'PATH' );
Expected parameters include:
Returns the value if defined.
SDL_setenv( ... )
Set environment variable's value.
SDL_setenv( 'Perl_SDL_pocket', 'store something here', 1 );
Expected parameters include:
name
- the name of the environment variable to setvalue
- the new value to set the given environment variable tooverwrite
- a boolean value; if true, the value is updated if already defined
Returns 1
if the environment variable has been changed; otherwise 0
.
SDL_qsort( ... )
A polymorphic sorting algorithm for arrays of arbitrary objects according to a user-provided comparison function.
Expected parameters include:
base
- pointer to the array to sortcount
- number of elements in the arraysize
- size of each element in the array in bytescomp
- 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.-
The signature of the comparison function should be equivalent to the following:
int cmp(const void *a, const void *b); # for FFI::Platypus->type: '(opaque,opaque)->int'
If the function is a code reference and not a closure, it will be wrapped automatically and temporarily made sticky.
The function must not modify the objects passed to it and must return consistent results when called for the same objects, regardless of their positions in the array.
See also: https://en.cppreference.com/w/c/algorithm/qsort
SDL_abs( ... )
Standard abs( ... )
function.
my $zero = SDL_abs( -459 ); # Ha
Expected parameters include:
Returns the absolute value of x
.
SDL_isalpha( ... )
Checks if the given character is an alphabetic character, i.e. either an uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), or a lowercase letter (abcdefghijklmnopqrstuvwxyz).
Expected parameters include:
Returns non-zero value if the character is an alphabetic character, zero otherwise.
SDL_isalnum( ... )
Checks if the given character is an alphanumeric character as classified by the current C locale. In the default locale, the following characters are alphanumeric:
digits (0123456789)
uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ)
lowercase letters (abcdefghijklmnopqrstuvwxyz)
Expected parameters include:
Returns non-zero value if the character is an alphanumeric character, zero otherwise.
SDL_isblank( ... )
Checks if the given character is a blank character in the current C locale.
Expected parameters include:
Returns non-zero value if the character is a blank character, zero otherwise.
SDL_iscntrl( ... )
Checks if the given character is a control character, i.e. codes 0x00-0x1F and 0x7F.
Expected parameters include:
Returns non-zero value if the character is a control character, zero otherwise.
SDL_isdigit( ... )
Checks if the given character is a numeric character (0123456789).
Expected parameters include:
Returns non-zero value if the character is a numeric character, zero otherwise.
SDL_isxdigit( ... )
Checks if the given character is a hexadecimal numeric character (0123456789abcdefABCDEF) or is classified as a hexadecimal character.
Expected parameters include:
Returns non-zero value if the character is an hexadecimal numeric character, zero otherwise.
SDL_ispunct( ... )
Checks if the given character is a punctuation character in the current C locale. The default C locale classifies the characters !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ as punctuation.
Expected parameters include:
Returns non-zero value if the character is a punctuation character, zero otherwise.
SDL_isspace( ... )
Checks if the given character is a whitespace character, i.e. either space (0x20), form feed (0x0c), line feed (0x0a), carriage return (0x0d), horizontal tab (0x09) or vertical tab (0x0b).
Expected parameters include:
Returns non-zero value if the character is a whitespace character, zero otherwise.
SDL_isupper( ... )
Checks if the given character is an uppercase character according to the current C locale. In the default "C" locale, isupper returns true only for the uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ).
Expected parameters include:
Returns non-zero value if the character is an uppercase letter, zero otherwise.
SDL_islower( ... )
Checks if the given character is classified as a lowercase character according to the current C locale. In the default "C" locale, islower returns true only for the lowercase letters (abcdefghijklmnopqrstuvwxyz).
Expected parameters include:
Returns non-zero value if the character is a lowercase letter, zero otherwise.
SDL_isprint( ... )
Checks if the given character can be printed, i.e. it is either a number (0123456789), an uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), a lowercase letter (abcdefghijklmnopqrstuvwxyz), a punctuation character(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~), or space, or any character classified as printable by the current C locale.
Expected parameters include:
Returns non-zero value if the character can be printed, zero otherwise.
SDL_isgraph( ... )
Checks if the given character has a graphical representation, i.e. it is either a number (0123456789), an uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), a lowercase letter (abcdefghijklmnopqrstuvwxyz), or a punctuation character(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~), or any graphical character specific to the current C locale.
Expected parameters include:
Returns non-zero value if the character has a graphical representation character, zero otherwise.
SDL_toupper( ... )
Converts the given character to uppercase according to the character conversion rules defined by the currently installed C locale.
In the default "C" locale, the following lowercase letters abcdefghijklmnopqrstuvwxyz are replaced with respective uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ.
Expected parameters include:
Returns uppercase version of ch
or unmodified ch
if no uppercase version is defined by the current C locale.
SDL_tolower( ... )
Converts the given character to lowercase according to the character conversion rules defined by the currently installed C locale.
In the default "C" locale, the following uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ are replaced with respective lowercase letters abcdefghijklmnopqrstuvwxyz. Expected parameters include:
Returns lowercase version of ch
or unmodified ch
if no lowercase version is listed in the current C locale.
SDL_crc32( ... )
This runs through a practical algorithm for the CRC-32 variant of CRC.
warn SDL_crc32( 0, "123456789", 9);
warn SDL_crc32( 0, "123456789");
warn 0xCBF43926;
Expected parameters include:
crc
- pointer to context variabledata
- input buffer to checksumlen
- length ofdata
(this is optional)
The checksum is returned.
SDL_memset( ... )
Fill a block of memory.
my $str = 'almost every programmer should know memset!';
SDL_memset($str, '-', 6);
print $str; # '------ every programmer should know memset!'
Expected parameters include:
ptr
- Pointer to the block of memory to fill.value
- Value to set.num
- Number of bytes to be set tovalue
The ptr
is returned.
SDL_zero)( ... )
Fill a block of memory with zeros.
Expected parameters include:
The ptr
is returned.
SDL_memcpy( ... )
Copies count
bytes from the object pointed to by src
to the object pointed to by dest
. Both objects are reinterpreted as arrays of unsigned char
.
my $source = 'once upon a midnight dreary...';
my $dest = 'xxxx';
SDL_memcpy(\$dest, \$source, 4);
Expected parameters include:
dest
- pointer to the memory location to copy tosrc
- pointer to the memory location to copy fromcount
- number of bytes to copy
dest
is returned.
SDL_memmove( ... )
Copies count
bytes from the object pointed to by src
to the object pointed to by dest
. Both objects are reinterpreted as arrays of unsigned char
.
my $source = 'once upon a midnight dreary...';
my $dest = 'xxxx';
SDL_memmove(\$dest, \$source, 4);
print $dest; # once
...or...
use FFI::Platypus::Buffer qw[scalar_to_pointer];
my $str = '1234567890';
SDL_memmove( scalar_to_pointer($str) + 4, scalar_to_pointer($str) + 3, 3 )
; # copies from [4, 5, 6] to [5, 6, 7]
print $str; # 1234456890
Expected parameters include:
dest
- pointer to the memory location to copy tosrc
- pointer to the memory location to copy fromcount
- number of bytes to copy
dest
is returned.
SDL_memcmp( ... )
Reinterprets the objects pointed to by lhs and rhs as arrays of unsigned char and compares the first count characters of these arrays. The comparison is done lexicographically.
sub demo ( $lhs, $rhs, $sz ) {
print substr( $lhs, 0, $sz );
my $rc = SDL_memcmp( \$lhs, \$rhs, $sz );
print $rc == 0 ? ' compares equal to ' :
$rc < 0 ? ' precedes ' :
$rc > 0 ? ' follows ' :
'';
print substr( $rhs, 0, $sz ) . " in lexicographical order\n";
}
#
my $a1 = 'abc';
my $a2 = 'abd';
demo( $a1, $a2, length $a1 ); # abc precedes abd in lexicographical order
demo( $a2, $a1, length $a1 ); # abd follows abc in lexicographical order
demo( $a1, $a1, length $a1 ); # abc compares equal to abc in lexicographical order
Expected parameters include:
lhs
- pointer to memory to comparerhs
- pointer to memory to comparelen
- number of bytes to examine
Returns a negative value if the first differing byte (reinterpreted as unsigned char) in lhs is less than the corresponding byte in rhs
.
0
if all count bytes of lhs
and rhs
are equal.
Positive value if the first differing byte in <lhs> is greater than the corresponding byte in rhs
.
SDL_wcslen( ... )
Returns the length of a wide string, that is the number of non-null wide characters that precede the terminating null wide character.
use utf8;
my $str = "木之本 桜";
binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
print "The length of '$str' is " . SDL_wcslen($str) . "\n";
# The length of '木之本 桜' is 5
Expected parameters include:
SDL_wcslcpy( ... )
Copies at most count
characters of the wide string pointed to by src
(including the terminating null wide character) to wide character array pointed to by dest
.
Expected parameters include:
dest
- pointer to the wide character array to copy tosrc
- pointer to the wide string to copy fromcount
- maximum number of wide characters to copy
Returns dest
.
SDL_wcslcat( )
Appends at most count
wide characters from the wide string pointed to by src
, stopping if the null terminator is copied, to the end of the character string pointed to by dest
. The wide character src[0] replaces the null terminator at the end of dest. The null terminator is always appended in the end (so the maximum number of wide characters the function may write is count
+1).
Expected parameters include:
dest
- pointer to the null-terminated wide string to append tosrc
- pointer to the null-terminated wide string to copy fromcount
- maximum number of wide characters to copy
Returns zero on success, returns non-zero on error.
SDL_wcsdup( ... )
Duplicate a wide character string.
Expected parameters include:
Returns a newly allocated wide character string on success.
SDL_wcsstr( ... )
Finds the first occurrence of the wide string src
in the wide string pointed to by dest
. The terminating null characters are not compared.
use utf8;
binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
my $origin = "アルファ, ベータ, ガンマ, アルファ, ベータ, ガンマ.";
my $target = "ベータ";
my $result = $origin;
print "Substring to find: \"$target\"\nString to search: \"$origin\"\n\n";
for ( ; ( $result = SDL_wcsstr( $result, $target ) ); $result = substr $result, 1 ) {
print "Found: \"$result\"\n";
}
Expected parameters include:
dest
- pointer to the null-terminated wide string to examinesrc
- pointer to the null-terminated wide string to search for
Returns a pointer to the first character of the found substring in dest
, or a null pointer if no such substring is found. If src
points to an empty string, dest
is returned.
SDL_wcscmp( ... )
Compares two null-terminated wide strings lexicographically.
use utf8;
binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
my $string = "どうもありがとうございます";
demo( $string, "どうも" );
demo( $string, "助かった" );
demo( substr( $string, 9 ), substr( "ありがとうございます", 6 ) );
sub demo ( $lhs, $rhs ) {
my $rc = SDL_wcscmp( $lhs, $rhs );
my $rel = $rc < 0 ? 'precedes' : $rc > 0 ? 'follows' : 'equals';
printf( "[%ls] %s [%ls]\n", $lhs, $rel, $rhs );
}
Expected parameters include:
Returns a negative value if lhs
appears before rhs
in lexicographical order.
Returns zero if lhs
and rhs
compare equal.
Returns a positive value if lhs
appears after rhs
in lexicographical order.
SDL_wcsncmp( ... )
Compares at most count
wide characters of two null-terminated wide strings. The comparison is done lexicographically.
use utf8;
binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
my $str1 = "안녕하세요";
my $str2 = "안녕히 가십시오";
demo( $str1, $str2, 5 );
demo( $str2, $str1, 8 );
demo( $str1, $str2, 2 );
sub demo ( $lhs, $rhs, $sz ) {
my $rc = SDL_wcsncmp( $lhs, $rhs, $sz );
my $rel = $rc < 0 ? 'precede' : $rc > 0 ? 'follow' : 'equal';
printf( "First %d characters of [%ls] %s [%ls]\n", $sz, $lhs, $rel, $rhs );
}
Expected parameters include:
lhs
- pointer to a wide stringrhs
- pointer to a wide stringcount
- maximum number of characters to compare
Returns a negative value if lhs
appears before rhs
in lexicographical order.
Returns zero if lhs
and rhs
compare equal.
Returns a positive value if lhs
appears after rhs
in lexicographical order.
SDL_wcscasecmp( ... )
Compares at wide characters of two null-terminated wide strings.
use utf8;
binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
my $str1 = "안녕하세요";
my $str2 = "안녕히 가십시오";
demo( $str1, $str2, 5 );
demo( $str2, $str1, 8 );
demo( $str1, $str2, 2 );
sub demo ( $lhs, $rhs, $sz ) {
my $rc = SDL_wcscasecmp( $lhs, $rhs );
my $rel = $rc < 0 ? 'precede' : $rc > 0 ? 'follow' : 'equal';
printf( "First %d characters of [%ls] %s [%ls]\n", $sz, $lhs, $rel, $rhs );
}
Expected parameters include:
Returns a negative value if lhs
appears before rhs
in lexicographical order.
Returns zero if lhs
and rhs
compare equal.
Returns a positive value if lhs
appears after rhs
in lexicographical order.
SDL_wcsncasecmp( ... )
Compares at most count
wide characters of two null-terminated wide strings while ignoring case.
use utf8;
binmode STDOUT, ":utf8"; # or `perl -CS file.pl` to avoid 'Wide character' noise
my $str1 = "안녕하세요";
my $str2 = "안녕히 가십시오";
demo( $str1, $str2, 5 );
demo( $str2, $str1, 8 );
demo( $str1, $str2, 2 );
sub demo ( $lhs, $rhs, $sz ) {
my $rc = SDL_wcsncasecmp( $lhs, $rhs, $sz );
my $rel = $rc < 0 ? 'precede' : $rc > 0 ? 'follow' : 'equal';
printf( "First %d characters of [%ls] %s [%ls]\n", $sz, $lhs, $rel, $rhs );
}
Expected parameters include:
lhs
- pointer to a wide stringrhs
- pointer to a wide stringcount
- maximum number of characters to compare
Returns a negative value if lhs
appears before rhs
in lexicographical order.
Returns zero if lhs
and rhs
compare equal.
Returns a positive value if lhs
appears after rhs
in lexicographical order.
SDL_strlen( ... )
Returns the length of the given byte string, that is, the number of characters in a character array whose first element is pointed to by str
up to and not including the first null character. The behavior is undefined if there is no null character in the character array pointed to by str
.
my $str = "How many characters does this string contain?\0";
printf "without null character: %d\nwith null character: %d", SDL_strlen($str), length $str;
Expected parameters include:
Returns the length of str
.
SDL_strlcpy( ... )
Copies the character string pointed to by src
, including the null terminator, to the character array whose first element is pointed to by dest
.
Expected parameters include:
Returns the new length of the entire string.
SDL_utf8strlcpy( ... )
Copies the character string pointed to by src
, including the null terminator, to the character array whose first element is pointed to by dest
.
Expected parameters include:
Returns the new length of the entire string.
SDL_strlcat( ... )
Copies the character string pointed to by src
, including the null terminator, to the character array whose first element is pointed to by dest
.
Expected parameters include:
Returns the new length of the entire string.
SDL_strdup( ... )
Duplicate a string.
Expected parameters include:
Returns the new string.
SDL_strrev( ... )
Reverses a string.
Expected parameters include:
Returns the given string in reverse.
SDL_strupr( ... )
Get a string in uppercase.
Expected parameters include:
Returns the given string in uppercase.
SDL_strlwr( ... )
Get a string in lowercase.
Expected parameters include:
Returns the given string in lowercase.
SDL_strchr( ... )
Finds the first occurrence of ch
(after conversion to char
as if by (char)ch
in C) in the null-terminated byte string pointed to by str
(each character interpreted as unsigned char
). The terminating null character is considered to be a part of the string and can be found when searching for '\0
'.
my $str = "Try not. Do, or do not. There is no try.";
my $target = 'T';
my $result = $str;
while ( ( $result = SDL_strchr( $result, $target ) ) ) {
printf "Found '%s' starting at '%s'\n", $target, $result;
$result = substr $result,
1; # Increment result, otherwise we'll find target at the same location
}
Expected parameters include:
Returns a pointer to the found character in str
, or null if no such character is found.
SDL_strrchr( ... )
my $szSomeFileName = "foo/bar/foobar.txt";
my $pLastSlash = SDL_strrchr( $szSomeFileName, '/' );
my $pszBaseName = $pLastSlash ? substr $pLastSlash, 1 : $szSomeFileName;
printf "Base Name: %s", $pszBaseName;
Finds the last occurrence of ch
(after conversion to char
as if by (char)ch
in C) in the null-terminated byte string pointed to by str
(each character interpreted as unsigned char
). The terminating null character is considered to be a part of the string and can be found when searching for '\0
'.
Expected parameters include:
Returns pointer to the found character in str
, or null if no such character is found.
SDL_strstr( ... )
Finds the first occurrence of the null-terminated byte string pointed to by substr
in the null-terminated byte string pointed to by str
. The terminating null characters are not compared.
sub find_str ( $str, $substr ) {
my $pos = SDL_strstr( $str, $substr );
if ($pos) {
printf "found the string '%s' in '%s' at position: %ld\n", $substr, $str,
length($str) - length($pos);
}
else {
printf( "the string '%s' was not found in '%s'\n", $substr, $str );
}
}
my $str = "one two three";
find_str( $str, "two" );
find_str( $str, "" );
find_str( $str, "nine" );
find_str( $str, "n" );
Expected parameters include:
Returns pointer to the first character of the found substring in str
, or a null pointer if such substring is not found. If substr
points to an empty string, str
is returned.
SDL_strtokr( ... )
Finds the next token in a null-terminated byte string pointed to by str
. The separator characters are identified by null-terminated byte string pointed to by delim
.
This function is designed to be called multiple times to obtain successive tokens from the same string.
Expected parameters include:
str
- byte string to tokenizedelim
- string identifying delimiterssaveptr
- pointer to a string used internally to maintain context
Returns a pointer to the beginning of then ext token or null if there are no more tokens.
SDL_utf8strlen( ... )
Find the length of a UTF-8 character string
Expected parameters include:
Returns the number of UTF-8 characters in str
.
SDL_itoa( ... )
Converts an integer value
to a null-terminated string using the specified base
and stores the result in the array given by str
parameter.
my $i = 1750;
my $buffer = ' ';
printf "decimal: %s\n", SDL_itoa( $i, $buffer, 10 );
printf "hexadecimal: %s\n", SDL_itoa( $i, $buffer, 16 );
printf "binary: %s\n", SDL_itoa( $i, $buffer, 2 );
Expected parameters include:
value
- value to be converted to a stringstr
- location to store resultbase
- 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.
Returns a pointer to the resulting string; same as str
.
SDL_uitoa( ... )
Converts an unsigned integer value
to a null-terminated string using the specified base
and stores the result in the array given by str
parameter.
my $i = 1750;
my $buffer = ' ';
printf "decimal: %s\n", SDL_uitoa( $i, $buffer, 10 );
printf "hexadecimal: %s\n", SDL_uitoa( $i, $buffer, 16 );
printf "binary: %s\n", SDL_uitoa( $i, $buffer, 2 );
Expected parameters include:
value
- value to be converted to a stringstr
- location to store resultbase
- 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.
Returns a pointer to the resulting string; same as str
.
SDL_ltoa( ... )
Converts an long value
to a null-terminated string using the specified base
and stores the result in the array given by str
parameter.
my $i = 1750;
my $buffer = ' ';
printf "decimal: %s\n", SDL_ltoa( $i, $buffer, 10 );
printf "hexadecimal: %s\n", SDL_ltoa( $i, $buffer, 16 );
printf "binary: %s\n", SDL_ltoa( $i, $buffer, 2 );
Expected parameters include:
value
- value to be converted to a stringstr
- location to store resultbase
- 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.
Returns a pointer to the resulting string; same as str
.
SDL_ultoa( ... )
Converts an unsigned long value
to a null-terminated string using the specified base
and stores the result in the array given by str
parameter.
my $i = 1750;
my $buffer = ' ';
printf "decimal: %s\n", SDL_ultoa( $i, $buffer, 10 );
printf "hexadecimal: %s\n", SDL_ultoa( $i, $buffer, 16 );
printf "binary: %s\n", SDL_ultoa( $i, $buffer, 2 );
Expected parameters include:
value
- value to be converted to a stringstr
- location to store resultbase
- 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.
Returns a pointer to the resulting string; same as str
.
SDL_lltoa( ... )
Converts an 64-bit value
to a null-terminated string using the specified base
and stores the result in the array given by str
parameter.
my $i = 1750;
my $buffer = ' ';
printf "decimal: %s\n", SDL_lltoa( $i, $buffer, 10 );
printf "hexadecimal: %s\n", SDL_lltoa( $i, $buffer, 16 );
printf "binary: %s\n", SDL_lltoa( $i, $buffer, 2 );
Expected parameters include:
value
- value to be converted to a stringstr
- location to store resultbase
- 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.
Returns a pointer to the resulting string; same as str
.
SDL_ulltoa( ... )
Converts an unsigned 64-bit value
to a null-terminated string using the specified base
and stores the result in the array given by str
parameter.
my $i = 1750;
my $buffer = ' ';
printf "decimal: %s\n", SDL_ulltoa( $i, $buffer, 10 );
printf "hexadecimal: %s\n", SDL_ulltoa( $i, $buffer, 16 );
printf "binary: %s\n", SDL_ulltoa( $i, $buffer, 2 );
Expected parameters include:
value
- value to be converted to a stringstr
- location to store resultbase
- 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.
Returns a pointer to the resulting string; same as str
.
SDL_atoi( ... )
Interprets an integer value in a byte string pointed to by str.
for my $str ( "42", "3.14159", "31337 with words", "words and 2" ) {
printf "SDL_atoi('%s') is %s\n", $str, SDL_atoi($str);
}
Discards any whitespace characters until the first non-whitespace character is found, then takes as many characters as possible to form a valid integer number representation and converts them to an integer value. The valid integer value consists of the following parts:
Expected parameters include:
Returns an integer value corresponding to the contents of str
on success. If the converted value falls out of range of corresponding return type, the return value is undefined. If no conversion can be performed, 0
is returned.
SDL_atof( ... )
Interprets a floating point value in a byte string pointed to by str
.
for my $str ( "0.0000000123", "0.012", "15e16", "-0x1afp-2", "inF", "Nan", "invalid" ) {
printf "SDL_atof('%s') is %s\n", $str, SDL_atof($str);
}
Function discards any whitespace characters until first non-whitespace character is found. Then it takes as many characters as possible to form a valid floating-point representation and converts them to a floating-point value. The valid floating-point value can be one of the following:
- decimal floating-point expression. It consists of the following parts:
-
- (optional) plus or minus sign
- nonempty sequence of decimal digits optionally containing decimal-point character (as determined by the current C locale) (defines significand)
- (optional)
e
orE
followed with optional minus or plus sign and nonempty sequence of decimal digits (defines exponent to base 10)
Expected parameters include:
Returns a double value corresponding to the contents of str
on success. If the converted value falls out of range of the return type, the return value is undefined. If no conversion can be performed, 0.0
is returned.
SDL_strtol( ... )
Interprets an integer value in a byte string pointed to by str
.
my $p = "10 200000000000000000000000000000 30 -40 junk";
printf( "Parsing '%s':\n", $p );
while (1) {
my $i = SDL_strtol( $p, \my $end, 10 );
last if $p eq $end;
printf( "Extracted '%s', SDL_strtol returned %ld.", $p, $i );
$p = $end;
print "\n";
}
printf( "Unextracted leftover: '%s'\n\n", $p );
# parsing without error handling
printf( "\"1010\" in binary --> %ld\n", SDL_strtol( "1010", undef, 2 ) );
printf( "\"12\" in octal --> %ld\n", SDL_strtol( "12", undef, 8 ) );
printf( "\"A\" in hex --> %ld\n", SDL_strtol( "A", undef, 16 ) );
printf( "\"junk\" in base-36 --> %ld\n", SDL_strtol( "junk", undef, 36 ) );
printf( "\"012\" in auto-detected base --> %ld\n", SDL_strtol( "012", undef, 0 ) );
printf( "\"0xA\" in auto-detected base --> %ld\n", SDL_strtol( "0xA", undef, 0 ) );
printf( "\"junk\" in auto-detected base --> %ld\n", SDL_strtol( "junk", undef, 0 ) );
Expected parameters include:
str
- byte string to be interpretedstr_end
- pointer to a pointer to characterbase
- base of the interpreted integer value
Returns an integer value corresponding to the contents of str
if successful. Otherwise, 0
is returned.
SDL_strtoul( ... )
Interprets an unsigned integer value in a byte string pointed to by str
.
my $p = "10 200000000000000000000000000000 30 -40";
printf( "Parsing '%s':\n", $p );
for ( my $i = SDL_strtoul( $p, \my $end, 10 ); $p ne $end; $i = SDL_strtoul( $p, \$end, 10 ) ) {
printf( "'%s' -> ", $p );
$p = $end;
printf( "%lu\n", $i );
}
Expected parameters include:
str
- byte string to be interpretedstr_end
- pointer to a pointer to characterbase
- base of the interpreted integer value
Returns an integer value corresponding to the contents of str
if successful. Otherwise, 0
is returned.
SDL_strtoll( ... )
Interprets a 64-bit integer value in a byte string pointed to by str
.
Expected parameters include:
str
- byte string to be interpretedstr_end
- pointer to a pointer to characterbase
- base of the interpreted integer value
Returns an integer value corresponding to the contents of str
if successful. Otherwise, 0
is returned.
SDL_strtoull( ... )
Interprets an unsigned 64-bit integer value in a byte string pointed to by str
.
Expected parameters include:
str
- byte string to be interpretedstr_end
- pointer to a pointer to characterbase
- base of the interpreted integer value
Returns an integer value corresponding to the contents of str
if successful. Otherwise, 0
is returned.
SDL_strtod( ... )
Interprets a floating-point value in a byte string pointed to by str
.
Expected parameters include:
Returns an floating point value corresponding to the contents of str
if successful. Otherwise, 0
is returned.
SDL_strcmp( ... )
Compares two null-terminated byte strings lexicographically.
sub demo ( $lhs, $rhs ) {
my $rc = SDL_strcmp( $lhs, $rhs );
my $rel = $rc < 0 ? "precedes" : $rc > 0 ? "follows" : "equals";
printf( "[%s] %s [%s]\n", $lhs, $rel, $rhs );
}
my $string = "Hello World!";
demo( $string, "Hello!" );
demo( $string, "Hello" );
demo( $string, "Hello there" );
demo( substr( "Hello, everybody!", 12 ), substr "Hello, somebody!", 11 );
Expected parameters include:
Returns a negative value if lhs
appears before rhs
in lexicographical order.
Returns zero if lhs
and rhs
compare equal.
Returns a positive value if lhs
appears after rhs
in lexicographical order.
SDL_strncmp( ... )
Compares at most count characters of two possibly null-terminated arrays. The comparison is done lexicographically. Characters following the null character are not compared.
sub demo ( $lhs, $rhs, $sz ) {
my $rc = SDL_strncmp( $lhs, $rhs, $sz );
my $rel = $rc < 0 ? "precedes" : $rc > 0 ? "follows" : "equals";
printf( "First %d chars of [%s] %s [%s]\n", $sz, $lhs, $rel, $rhs );
}
my $string = "Hello World!";
demo( $string, "Hello!", 5 );
demo( $string, "Hello", 10 );
demo( $string, "Hello there", 10 );
demo( substr( "Hello, everybody!", 12 ), substr( "Hello, somebody!", 11 ), 5 );
Expected parameters include:
lhs
- byte string to comparerhs
- byte string to comparecount
- maximum number of characters to compare
Returns a negative value if lhs
appears before rhs
in lexicographical order.
Returns zero if lhs
and rhs
compare equal, or if count
is zero.
Returns a positive value if lhs
appears after rhs
in lexicographical order.
SDL_strcasecmp( ... )
Compares characters of two possibly strings. The comparison is done lexicographically. Characters following the null character are not compared.
Expected parameters include:
Returns a negative value if lhs
appears before rhs
in lexicographical order.
Returns zero if lhs
and rhs
compare equal, or if count
is zero.
Returns a positive value if lhs
appears after rhs
in lexicographical order.
SDL_strncasecmp( ... )
Compares up to count
characters of two possibly strings ignoring case. The comparison is done lexicographically. Characters following the null character are not compared.
Expected parameters include:
lhs
- byte string to comparerhs
- byte string to comparecount
- maximum number of characters to compare
Returns a negative value if lhs
appears before rhs
in lexicographical order.
Returns zero if lhs
and rhs
compare equal, or if count
is zero.
Returns a positive value if lhs
appears after rhs
in lexicographical order.
SDL_sscanf( ... )
Reads data from a variety of sources, interprets it according to format
and stores the results into given locations.
my ( $i, $j ); # int
my ( $x, $y ); # float
my $str1 = ' ' x 10; # You *must* pre-define strings for length
my $str2 = ' ' x 4;
my $warr = ' ' x 8; # Don't forget wide chars
my $input = '25 54.32E-1 Thompson 56789 0123 56ß水';
# parses as follows:
# %d: an integer
# %f: a floating-point value
# %9s: a string of at most 9 non-whitespace characters
# %2d: two-digit integer (dig7its 5 and 6)
# %f: a floating-point value (digits 7, 8, 9)
# %*d an integer which isn't stored anywhere
# ' ': all consecutive whitespace
# %3[0-9]: a string of at most 3 digits (digits 5 and 6)
# %2lc: two wide characters, using multibyte to wide conversion
my $ret = SDL_sscanf( $input, "%d%f%9s%2d%f%*d %3[0-9]%2lc", \$i, \$x, $str1, \$j, \$y, $str2,
$warr );
printf << '', $ret, $i, $x, $str1, $j, $y, $str2, unpack 'WW', $warr;
Converted %d fields:
i = %d
x = %f
str1 = %s
j = %s
y = %f
str2 = %s
warr[0] = U+%x warr[1] = U+%x
Expected parameters include:
Returns the number of receiving arguments successfully assigned (which may be zero in case a matching failure occurred before the first receiving argument was assigned), or EOF if input failure occurs before the first receiving argument was assigned.
SDL_vsscanf( ... )
Reads data from a string, interprets it according to format
and stores the results into locations defined by vlist
.
my ( $n, $m );
printf "Parsing '1 2'...%s\n",
SDL_vsscanf( '1 2', '%d %d', \$n, \$m ) == 2 ? 'success' : 'failure';
printf "Parsing '1 a'...%s\n",
SDL_vsscanf( '1 a', '%d %s', \$n, \$m ) == 2 ? 'success' : 'failure';
Expected parameters include:
buffer
- string to read fromformat
- string specifying how to read the inputvlist
- variable argument list containing the receiving arguments
Returns the number of arguments successfully read or EOF
if failure occurs.
SDL_snprintf( ... )
Loads the data from the given locations, converts them to character string equivalents and writes the results to a string buffer.
print "Strings:\n";
my $s = 'Hello';
SDL_snprintf( my $output, 128, "\t[%10s]\n\t[%-10s]\n\t[%*s]\n\t[%-10.*s]\n\t[%-*.*s]\n",
$s, $s, 10, $s, 4, $s, 10, 4, $s );
print $output;
SDL_snprintf( $output, 100, "Characters:\t%c %%\n", 65 );
print $output;
print "Integers\n";
SDL_snprintf( $output, 100, "Decimal:\t%i %d %.6i %i %.0i %+i %i\n", 1, 2, 3, 0, 0, 4, -4 );
print $output;
SDL_snprintf( $output, 100, "Hexadecimal:\t%x %x %X %#x\n", 5, 10, 10, 6 );
print $output;
SDL_snprintf( $output, 100, "Octal:\t%o %#o %#o\n", 10, 10, 4 );
print $output;
print "Floating point\n";
SDL_snprintf( $output, 100, "Rounding:\t%f %.0f %.32f\n", 1.5, 1.5, 1.3 );
print $output;
SDL_snprintf( $output, 100, "Padding:\t%05.2f %.2f %5.2f\n", 1.5, 1.5, 1.5 );
print $output;
SDL_snprintf( $output, 100, "Scientific:\t%E %e\n", 1.5, 1.5 );
print $output;
SDL_snprintf( $output, 100, "Hexadecimal:\t%a %A\n", 1.5, 1.5 );
print $output;
print "Variable width control:\n";
SDL_snprintf( $output, 100, "right-justified variable width: '%*c'\n", 5, ord 'x' );
print $output;
my $r = SDL_snprintf( $output, 100, "left-justified variable width : '%*c'\n", -5, ord 'x' );
print $output;
SDL_snprintf( $output, 100, "(the last printf printed %d characters)\n", $r );
print $output;
# fixed-width types
my $val = 2**32 - 1;
SDL_snprintf( $output, 100, "Largest 32-bit value is %u or %#x\n", $val, $val );
print $output;
Expected parameters include:
buffer
- string to write tobuf_size
- maximum number of characters which may be writtenformat
- string specifying how to interpret the data...
- arguments specifying data to print
Returns the number of characters written on success.
SDL_vsnprintf( ... )
Loads the data from the given locations, converts them to character string equivalents and writes the results to a string buffer.
Expected parameters include:
buffer
- string to write tobuf_size
- maximum number of characters which may be writtenformat
- string specifying how to interpret the data...
- arguments specifying data to print
Returns the number of characters written on success.
SDL_acos( ... )
Computes the principal value of the arc cosine of arg
.
printf
"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",
SDL_acos(-1), SDL_acos(0.0), 2 * SDL_acos(0), SDL_acos(0.5), 3 * SDL_acos(0.5),
SDL_acos(1);
Expected parameters include:
If no errors occur, the arc cosine of arg
in the range [0 , π]
, is returned.
SDL_acosf( ... )
Computes the principal value of the arc cosine of arg
.
Expected parameters include:
If no errors occur, the arc cosine of arg
in the range [0 , π]
, is returned.
SDL_asin( ... )
Computes the principal values of the arc sine of arg
.
printf "SDL_asin( 1.0) = %+f, 2*SDL_asin( 1.0)=%+f\n", SDL_asin(1), 2 * SDL_asin(1);
printf "SDL_asin(-0.5) = %+f, 6*SDL_asin(-0.5)=%+f\n", SDL_asin(-0.5), 6 * SDL_asin(-0.5);
# special values
printf "SDL_asin(0.0) = %1f, SDL_asin(-0.0)=%f\n", SDL_asin(+0.0), SDL_asin(-0.0);
printf "SDL_asin(1.1) = %f\n", SDL_asin(1.1);
Expected parameters include:
If no errors occur, the arc sine of arg
in the range [-π/2,+π/2]
, is returned.
SDL_asinf( ... )
Computes the principal values of the arc sine of arg
.
Expected parameters include:
If no errors occur, the arc sine of arg
in the range [-π/2,+π/2]
, is returned.
SDL_atan( ... )
Computes the principal value of the arc tangent of arg
.
printf( "SDL_atan(1) = %f, 4*SDL_atan(1)=%f\n", SDL_atan(1), 4 * SDL_atan(1) );
# special values
use bigrat; # inf
printf( "SDL_atan(Inf) = %f, 2*SDL_atan(Inf) = %f\n", SDL_atan(inf), 2 * SDL_atan(inf) );
printf( "SDL_atan(-0.0) = %+f, SDL_atan(+0.0) = %+f\n", SDL_atan(-0.0), SDL_atan(0) );
Expected parameters include:
If no errors occur, the arc tangent of arg
in the range [-π/2,+π/2]
radians, is returned.
SDL_atanf( ... )
Computes the principal value of the arc tangent of arg
.
Expected parameters include:
If no errors occur, the arc tangent of arg
in the range [-π/2 ; +π/2]
radians, is returned.
SDL_atan2( ... )
Computes the arc tangent of y/x
using the signs of arguments to determine the correct quadrant.
use Math::AnyNum qw[hypot];
# normal usage: the signs of the two arguments determine the quadrant
# atan2(1,1) = +pi/4, Quad I
printf( "(+1,+1) cartesian is (%f,%f) polar\n", hypot( 1, 1 ), SDL_atan2( 1, 1 ) );
# atan2(1, -1) = +3pi/4, Quad II
printf( "(+1,-1) cartesian is (%f,%f) polar\n", hypot( 1, -1 ), SDL_atan2( 1, -1 ) );
# atan2(-1,-1) = -3pi/4, Quad III
printf( "(-1,-1) cartesian is (%f,%f) polar\n", hypot( -1, -1 ), SDL_atan2( -1, -1 ) );
# atan2(-1,-1) = -pi/4, Quad IV
printf( "(-1,+1) cartesian is (%f,%f) polar\n", hypot( -1, 1 ), SDL_atan2( -1, 1 ) );
# special values
printf( "SDL_atan2(0, 0) = %f SDL_atan2(0, -0)=%f\n", SDL_atan2( 0, 0 ), SDL_atan2( 0, -0.0 ) );
printf( "SDL_atan2(7, 0) = %f SDL_atan2(7, -0)=%f\n", SDL_atan2( 7, 0 ), SDL_atan2( 7, -0.0 ) );
Expected parameters include:
If no errors occur, the arc tangent of y/x
in the range [-π ; +π]
radians, is returned.
SDL_atan2f( ... )
Computes the arc tangent of y/x
using the signs of arguments to determine the correct quadrant.
Expected parameters include:
If no errors occur, the arc tangent of y/x
in the range [-π ; +π]
radians, is returned.
SDL_ceil( ... )
Computes the smallest integer value not less than arg
.
printf"SDL_ceil(+2.4) = %+.1f\n", SDL_ceil(2.4);
printf"SDL_ceil(-2.4) = %+.1f\n", SDL_ceil(-2.4);
printf"SDL_ceil(-0.0) = %+.1f\n", SDL_ceil(-0.0);
use bigrat; # inf
printf"SDL_ceil(-Inf) = %+f\n", SDL_ceil(-inf);
Expected parameters include:
If no errors occur, the smallest integer value not less than arg
, that is ⌈arg⌉
, is returned.
SDL_ceilf( ... )
Computes the smallest integer value not less than arg
.
Expected parameters include:
If no errors occur, the smallest integer value not less than arg
, that is ⌈arg⌉
, is returned.
SDL_copysign( ... )
Composes a floating point value with the magnitude of mag
and the sign of sgn
.
printf "SDL_copysign(1.0,+2.0) = %+f\n", SDL_copysign( 1.0, +2.0 );
printf "SDL_copysign(1.0,-2.0) = %+f\n", SDL_copysign( 1.0, -2.0 );
use bigrat;
printf "SDL_copysign(inf,-2.0) = %+f\n", SDL_copysign( inf, -2.0 );
printf "SDL_copysign(NaN,-2.0) = %+f\n", SDL_copysign( NaN, -2.0 );
Expected parameters include:
If no errors occur, the floating point value with the magnitude of mag
and the sign of sgn
is returned.
If mag
is NaN
, then NaN
with the sign of sgn
is returned however perl cannot properly express -NaN
.
If sgn
is -0
, the result is only negative if the implementation supports the signed zero consistently in arithmetic operations.
SDL_copysignf( ... )
Expected parameters include:
If no errors occur, the floating point value with the magnitude of mag
and the sign of sgn
is returned.
If mag
is NaN
, then NaN
with the sign of sgn
is returned however perl cannot properly express -NaN
.
If sgn
is -0
, the result is only negative if the implementation supports the signed zero consistently in arithmetic operations.
SDL_cos( ... )
Computes the cosine of arg
(measured in radians).
my $pi = M_PI;
# typical usage
printf "SDL_cos(pi/3) = %f\n", SDL_cos( $pi / 3 );
printf "SDL_cos(pi/2) = %f\n", SDL_cos( $pi / 2 );
printf "SDL_cos(-3*pi/4) = %f\n", SDL_cos( -3 * $pi / 4 );
# special values
printf "SDL_cos(+0) = %f\n", SDL_cos(0.0);
printf "SDL_cos(-0) = %f\n", SDL_cos(-0.0);
use bigrat;
printf "SDL_cos(INFINITY) = %f\n", SDL_cos(inf);
Expected parameters include:
If no errors occur, the cosine of arg
in the range [-1 ; +1]
, is returned.
SDL_cosf( ... )
Computes the cosine of arg
(measured in radians).
Expected parameters include:
If no errors occur, the cosine of arg
in the range [-1 ; +1]
, is returned.
SDL_exp( ... )
Computes the e
(Euler's number, 2.7182818
) raised to the given power arg
.
printf "SDL_exp(1) = %f\n", SDL_exp(1);
printf "FV of \$100, continuously compounded at 3%% for 1 year = %f\n", 100 * SDL_exp(0.03);
# special values
printf "SDL_exp(-0) = %f\n", SDL_exp(-0.0);
printf "SDL_exp(-Inf) = %f\n", SDL_exp( -inf );
# overflow
printf "SDL_exp(710) = %f\n", SDL_exp(710);
Expected parameters include:
If no errors occur, the base-e exponential of arg
is returned.
SDL_expf( ... )
Computes the e
(Euler's number, 2.7182818
) raised to the given power arg
.
Expected parameters include:
If no errors occur, the base-e exponential of arg
is returned.
SDL_fabs( ... )
Computes the absolute value of a floating point value arg
.
printf( "SDL_fabs(+3) = %f\n", SDL_fabs(+3.0) );
printf( "SDL_fabs(-3) = %f\n", SDL_fabs(-3.0) );
# special values
printf( "SDL_fabs(-0) = %f\n", SDL_fabs(-0.0) );
printf( "SDL_fabs(-Inf) = %f\n", SDL_fabs( -inf ) );
printf( "%f\n", num_int( 0.0, 2 * M_PI, 100000 ) );
sub num_int ( $a, $b, $n ) { # assumes all area is positive
return 0.0 if $a == $b;
$n ||= 1; # avoid division by zero
my $h = ( $b - $a ) / $n;
my $sum = 0.0;
for ( my $k = 0; $k < $n; ++$k ) {
$sum += $h * SDL_fabs( sin( $a + $k * $h ) );
}
return $sum;
}
Expected parameters include:
If successful, returns the absolute value of arg
(|arg|
). The value returned is exact and does not depend on any rounding modes.
SDL_fabsf( ... )
Computes the absolute value of a floating point value arg
.
Expected parameters include:
If successful, returns the absolute value of arg
(|arg|
). The value returned is exact and does not depend on any rounding modes.
SDL_floor( ... )
Computes the largest integer value not greater than arg
.
printf "SDL_floor(+2.7) = %+.1f\n", SDL_floor(2.7);
printf "SDL_floor(-2.7) = %+.1f\n", SDL_floor(-2.7);
printf "SDL_floor(-0.0) = %+.1f\n", SDL_floor(-0.0);
printf "SDL_floor(-Inf) = %+f\n", SDL_floor( -INFINITY );
Expected parameters include:
If no errors occur, the largest integer value not greater than arg
, that is ⌊arg⌋
, is returned.
SDL_floorf( ... )
Computes the largest integer value not greater than arg
.
Expected parameters include:
If no errors occur, the largest integer value not greater than arg
, that is ⌊arg⌋
, is returned.
SDL_trunc( ... )
Computes the nearest integer not greater in magnitude than arg
.
printf "SDL_trunc(+2.7) = %+.1f\n", SDL_trunc(2.7);
printf "SDL_trunc(-2.7) = %+.1f\n", SDL_trunc(-2.7);
printf "SDL_trunc(-0.0) = %+.1f\n", SDL_trunc(-0.0);
printf "SDL_trunc(-Inf) = %+f\n", SDL_trunc( -INFINITY );
Expected parameters include:
If no errors occur, the nearest integer value not greater in magnitude than arg
(in other words, arg
rounded towards zero), is returned.
SDL_truncf( ... )
Computes the nearest integer not greater in magnitude than arg
.
Expected parameters include:
If no errors occur, the nearest integer value not greater in magnitude than arg
(in other words, arg
rounded towards zero), is returned.
SDL_fmod( ... )
Computes the floating-point remainder of the division operation x/y
.
printf "SDL_fmod(+5.1, +3.0) = %.1f\n", SDL_fmod( 5.1, 3 );
printf "SDL_fmod(-5.1, +3.0) = %.1f\n", SDL_fmod( -5.1, 3 );
printf "SDL_fmod(+5.1, -3.0) = %.1f\n", SDL_fmod( 5.1, -3 );
printf "SDL_fmod(-5.1, -3.0) = %.1f\n", SDL_fmod( -5.1, -3 );
# special values
printf "SDL_fmod(+0.0, 1.0) = %.1f\n", SDL_fmod( 0, 1 );
printf "SDL_fmod(-0.0, 1.0) = %.1f\n", SDL_fmod( -0.0, 1 );
printf "SDL_fmod(+5.1, Inf) = %.1f\n", SDL_fmod( 5.1, 'INFINITY' );
# error handling
printf "SDL_fmod(+5.1, 0) = %.1f\n", SDL_fmod( 5.1, 0 );
Expected parameters include:
If successful, returns the floating-point remainder of the division x/y
as defined above.
SDL_fmodf( ... )
Computes the floating-point remainder of the division operation x/y
.
Expected parameters include:
If successful, returns the floating-point remainder of the division x/y
as defined above.
SDL_log( ... )
Computes the natural (base e) logarithm of arg
.
printf "SDL_log(1) = %f\n", SDL_log(1);
printf "base-5 logarithm of 125 = %f\n", SDL_log(125) / SDL_log(5);
# special values
printf "SDL_log(1) = %f\n", SDL_log(1);
printf "SDL_log(+Inf) = %f\n", SDL_log('INFINITY');
#error handling
printf "SDL_log(0) = %f\n", SDL_log(0);
Expected parameters include:
If no errors occur, the natural (base-e) logarithm of arg
is returned.
SDL_logf( ... )
Computes the natural (base e) logarithm of arg
.
Expected parameters include:
If no errors occur, the natural (base-e) logarithm of arg
is returned.
SDL_log10( ... )
Computes the common (base-10) logarithm of arg
.
printf "SDL_log10(1000) = %f\n", SDL_log10(1000);
printf "log10(0.001) = %f\n", SDL_log10(0.001);
printf "base-5 logarithm of 125 = %f\n", SDL_log10(125) / SDL_log10(5);
# special values
printf "SDL_log10(1) = %f\n", SDL_log10(1);
printf "SDL_log10(+Inf) = %f\n", SDL_log10('INFINITY');
# error handling
printf "SDL_log10(0) = %f\n", SDL_log10(0);
Expected parameters include:
If no errors occur, the common (base-10) logarithm of arg
is returned.
SDL_log10f( ... )
Computes the common (base-10) logarithm of arg
.
Expected parameters include:
If no errors occur, the common (base-10) logarithm of arg
is returned.
SDL_pow( ... )
Computes the value of base
raised to the power exponent
.
# typical usage
printf "SDL_pow(2, 10) = %f\n", SDL_pow( 2, 10 );
printf "SDL_pow(2, 0.5) = %f\n", SDL_pow( 2, 0.5 );
printf "SDL_pow(-2, -3) = %f\n", SDL_pow( -2, -3 );
# special values
printf "SDL_pow(-1, NAN) = %f\n", SDL_pow( -1, 'NaN' );
printf "SDL_pow(+1, NAN) = %f\n", SDL_pow( +1, 'NaN' );
printf "SDL_pow(INFINITY, 2) = %f\n", SDL_pow( 'INFINITY', 2 );
printf "SDL_pow(INFINITY, -1) = %f\n", SDL_pow( 'INFINITY', -1 );
# error handling
printf "SDL_pow(-1, 1/3) = %f\n", SDL_pow( -1, 1.0 / 3 );
printf "SDL_pow(-0, -3) = %f\n", SDL_pow( -0.0, -3 );
Expected parameters include:
If no errors occur, base
raised to the power of exponent
is returned.
SDL_powf( ... )
Computes the value of base
raised to the power exponent
.
Expected parameters include:
If no errors occur, base
raised to the power of exponent
is returned.
SDL_round( ... )
Computes the nearest integer value to arg
(in floating-point format), rounding halfway cases away from zero, regardless of the current rounding mode.
printf 'SDL_round(+2.3) = %+.1f ', SDL_round(2.3);
printf 'SDL_round(+2.5) = %+.1f ', SDL_round(2.5);
printf "SDL_round(+2.7) = %+.1f\n", SDL_round(2.7);
printf 'SDL_round(-2.3) = %+.1f ', SDL_round(-2.3);
printf 'SDL_round(-2.5) = %+.1f ', SDL_round(-2.5);
printf "SDL_round(-2.7) = %+.1f\n", SDL_round(-2.7);
printf "SDL_round(-0.0) = %+.1f\n", SDL_round(-.0);
printf "SDL_round(-Inf) = %+f\n", SDL_round('-INFINITY');
Expected parameters include:
If no errors occur, the nearest integer value to arg
, rounding halfway cases away from zero, is returned.
SDL_roundf( ... )
Computes the nearest integer value to arg
(in floating-point format), rounding halfway cases away from zero, regardless of the current rounding mode.
Expected parameters include:
If no errors occur, the nearest integer value to arg
, rounding halfway cases away from zero, is returned.
SDL_lround( ... )
Computes the nearest integer value to arg
(in integer format), rounding halfway cases away from zero, regardless of the current rounding mode.
printf 'SDL_lround(+2.3) = %ld ', SDL_lround(2.3);
printf 'SDL_lround(+2.5) = %ld ', SDL_lround(2.5);
printf "SDL_lround(+2.7) = %ld\n", SDL_lround(2.7);
printf 'SDL_lround(-2.3) = %ld ', SDL_lround(-2.3);
printf 'SDL_lround(-2.5) = %ld ', SDL_lround(-2.5);
printf "SDL_lround(-2.7) = %ld\n", SDL_lround(-2.7);
printf "SDL_lround(-0.0) = %ld\n", SDL_lround(-.0);
printf "SDL_lround(-Inf) = %ld\n", SDL_lround('-INFINITY'); # FE_INVALID raised
Expected parameters include:
If no errors occur, the nearest integer value to arg
, rounding halfway cases away from zero, is returned.
SDL_lroundf( ... )
Computes the nearest integer value to arg
(in integer format), rounding halfway cases away from zero, regardless of the current rounding mode.
Expected parameters include:
If no errors occur, the nearest integer value to arg
, rounding halfway cases away from zero, is returned.
SDL_scalbn( ... )
Multiplies a floating point value arg
by FLT_RADIX
(the radix (integer base) used by the representation of all three floating-point types) raised to power exp
.
printf "SDL_scalbn(7, -4) = %f\n", SDL_scalbn( 7, -4 );
printf "SDL_scalbn(1, -1074) = %g (minimum positive subnormal double)\n",
SDL_scalbn( 1, -1074 );
printf "SDL_scalbn(.9999999999999999, 1024) = %g (largest finite double)\n",
SDL_scalbn( 0.99999999999999989, 1024 );
# special values
printf "SDL_scalbn(-0, 10) = %f\n", SDL_scalbn( -.0, 10 );
printf "SDL_scalbn(-Inf, -1) = %f\n", SDL_scalbn( '-INFINITY', -1 );
# error handling
printf "SDL_scalbn(1, 1024) = %f\n", SDL_scalbn( 1, 1024 );
Expected parameters include:
If no errors occur, arg
multiplied by FLT_RADIX
to the power of exp
is returned.
SDL_scalbnf( ... )
Multiplies a floating point value arg
by FLT_RADIX
(the radix (integer base) used by the representation of all three floating-point types) raised to power exp
.
Expected parameters include:
If no errors occur, arg
multiplied by FLT_RADIX
to the power of exp
is returned.
SDL_sin( ... )
Computes the sine of arg
(measured in radians).
my $pi = SDL_acos(-1);
# typical usage
printf "SDL_sin(pi/6) = %f\n", SDL_sin( $pi / 6 );
printf "SDL_sin(pi/2) = %f\n", SDL_sin( $pi / 2 );
printf "SDL_sin(-3*pi/4) = %f\n", SDL_sin( -3 * $pi / 4 );
# special values
printf "SDL_sin(+0) = %f\n", SDL_sin(0);
printf "SDL_sin(-0) = %f\n", SDL_sin(-.0);
printf "SDL_sin(INFINITY) = %f\n", SDL_sin('INFINITY');
Expected parameters include:
If no errors occur, the sine of arg
in the range [-1 ; +1], is returned.
SDL_sinf( ... )
Computes the sine of arg
(measured in radians).
Expected parameters include:
If no errors occur, the sine of arg
in the range [-1 ; +1], is returned.
SDL_sqrt( ... )
Computes square root of arg
.
# normal use
printf "SDL_sqrt(100) = %f\n", SDL_sqrt(100);
printf "SDL_sqrt(2) = %f\n", SDL_sqrt(2);
printf "golden ratio = %f\n", ( 1 + SDL_sqrt(5) ) / 2;
# special values
printf "SDL_sqrt(-0) = %f\n", SDL_sqrt(-0.0);
# error handling
printf "SDL_sqrt(-1.0) = %f\n", SDL_sqrt(-1);
Expected parameters include:
If no errors occur, square root of Carg> (√arg
), is returned.
SDL_sqrtf( ... )
Computes square root of arg
.
Expected parameters include:
If no errors occur, square root of Carg> (√arg
), is returned.
SDL_tan( ... )
Computes the tangent of arg
(measured in radians).
my $pi = SDL_acos(-1);
# typical usage
printf "SDL_tan (pi/4) = %+f\n", SDL_tan( $pi / 4 ); # 45 deg
printf "SDL_tan(3*pi/4) = %+f\n", SDL_tan( 3 * $pi / 4 ); # 135 deg
printf "SDL_tan(5*pi/4) = %+f\n", SDL_tan( 5 * $pi / 4 ); # -135 deg
printf "SDL_tan(7*pi/4) = %+f\n", SDL_tan( 7 * $pi / 4 ); # -45 deg
# special values
printf "SDL_tan(+0) = %+f\n", SDL_tan(0.0);
printf "SDL_tan(-0) = %+f\n", SDL_tan(-0.0);
# error handling
printf "SDL_tan(INFINITY) = %f\n", SDL_tan('INFINITY');
Expected parameters include:
If no errors occur, the tangent of arg
is returned.
SDL_tanf( ... )
Computes the tangent of arg
(measured in radians).
Expected parameters include:
If no errors occur, the tangent of arg
is returned.
SDL_iconv_open( ... )
Allocate descriptor for character set conversion.
Expected parameters include:
The values permitted for fromcode and tocode and the supported combinations are system-dependent. For the GNU C library, the permitted values are listed by the `iconv --list`
command, and all combinations of the listed values are supported.
Returns a new SDL2::iconv_t object.
SDL_iconv_close( ... )
Deallocate descriptor for character set conversion.
Expected parameters include:
cd
- SDL2::iconv_t object
Returns 0
on success; otherwise returns -1
.
SDL_iconv( ... )
Converts a stream of data between encodings.
Expected parameters include:
cd
- SDL2::iconv_t objectinbuf
- pointer to a bufferinbytesleft
- pointer to an integeroutbuf
- pointer to a bufferoutbytesleft
- pointer to an integer
Returns an iconv( )
error code.
SDL_iconv_string( ... )
Converts a string between encodings in one pass.
Expected parameters include:
tocode
- encoding of the outcome of this conversionfromcode
- encoding of the encoding textinbuf
- input bufferinbytesleft
- number of characters left to encode
Returns a string that must be freed with SDL_free( ... )
on success; undef on error.
SDL_iconv_utf8_locale( ... )
Converts string from UTF-8 to the local encoding.
Expected parameters include:
Returns the re-encoded string.
Defined values and Enumerations
These might actually be useful and may be imported with the listed tags.
SDL_bool
Basic boolean values for added sugar. Imported with the :bool
tag.
M_PI
Pi in a pinch.
Memory allocation callbacks
Not sure why you'd ever want to do this, but you may override SDL's internal memory handling with these closure types.
SDL_malloc_func
Parameters to expect:
You must return a pointer to allocated memory.
SDL_calloc_func
Parameters to expect:
You must return a pointer to allocated memory.
SDL_realloc_func
Parameters to expect:
mem
- an opaque pointer to allocated memorysize
-size_t
type indicating how much memory to allocate
You must return a pointer to allocated memory.
SDL_free_func
Parameters to expect:
iconv( )
error codes
The SDL implementation of iconv( )
returns these error codes:
SDL_ICONV_ERROR
SDL_ICONV_E2BIG
SDL_ICONV_EILSEQ
SDL_ICONV_EINVAL
LICENSE
Copyright (C) Sanko Robinson.
This library is free software; you can redistribute it and/or modify it under the terms found in the Artistic License 2. Other copyrights, terms, and conditions may apply to data transmitted through this module.
AUTHOR
Sanko Robinson <sanko@cpan.org>