SDL_stdinc.h 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_stdinc.h
  20. *
  21. * This is a general header that includes C language support. It implements
  22. * a subset of the C runtime: these should all behave the same way as their
  23. * C runtime equivalents, but with an SDL_ prefix.
  24. */
  25. #ifndef SDL_stdinc_h_
  26. #define SDL_stdinc_h_
  27. #include <SDL3/SDL_platform_defines.h>
  28. #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  29. #include <inttypes.h>
  30. #endif
  31. #include <stdarg.h>
  32. #include <stdint.h>
  33. #include <string.h>
  34. #include <wchar.h>
  35. #ifndef SDL_DISABLE_ALLOCA
  36. # ifndef alloca
  37. # ifdef HAVE_ALLOCA_H
  38. # include <alloca.h>
  39. # elif defined(SDL_PLATFORM_NETBSD)
  40. # if defined(__STRICT_ANSI__)
  41. # define SDL_DISABLE_ALLOCA
  42. # else
  43. # include <stdlib.h>
  44. # endif
  45. # elif defined(__GNUC__)
  46. # define alloca __builtin_alloca
  47. # elif defined(_MSC_VER)
  48. # include <malloc.h>
  49. # define alloca _alloca
  50. # elif defined(__WATCOMC__)
  51. # include <malloc.h>
  52. # elif defined(__BORLANDC__)
  53. # include <malloc.h>
  54. # elif defined(__DMC__)
  55. # include <stdlib.h>
  56. # elif defined(SDL_PLATFORM_AIX)
  57. # pragma alloca
  58. # elif defined(__MRC__)
  59. void *alloca(unsigned);
  60. # else
  61. char *alloca();
  62. # endif
  63. # endif
  64. #endif
  65. #ifdef SIZE_MAX
  66. # define SDL_SIZE_MAX SIZE_MAX
  67. #else
  68. # define SDL_SIZE_MAX ((size_t) -1)
  69. #endif
  70. /**
  71. * Check if the compiler supports a given builtin.
  72. * Supported by virtually all clang versions and recent gcc. Use this
  73. * instead of checking the clang version if possible.
  74. */
  75. #ifdef __has_builtin
  76. #define SDL_HAS_BUILTIN(x) __has_builtin(x)
  77. #else
  78. #define SDL_HAS_BUILTIN(x) 0
  79. #endif
  80. /**
  81. * The number of elements in an array.
  82. */
  83. #define SDL_arraysize(array) (sizeof(array)/sizeof(array[0]))
  84. #define SDL_TABLESIZE(table) SDL_arraysize(table)
  85. /**
  86. * Macro useful for building other macros with strings in them.
  87. *
  88. * For example:
  89. *
  90. * ```c
  91. * #define LOG_ERROR(X) OutputDebugString(SDL_STRINGIFY_ARG(__FUNCTION__) ": " X "\n")`
  92. * ```
  93. */
  94. #define SDL_STRINGIFY_ARG(arg) #arg
  95. /**
  96. * \name Cast operators
  97. *
  98. * Use proper C++ casts when compiled as C++ to be compatible with the option
  99. * -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
  100. */
  101. /* @{ */
  102. #ifdef __cplusplus
  103. #define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
  104. #define SDL_static_cast(type, expression) static_cast<type>(expression)
  105. #define SDL_const_cast(type, expression) const_cast<type>(expression)
  106. #else
  107. #define SDL_reinterpret_cast(type, expression) ((type)(expression))
  108. #define SDL_static_cast(type, expression) ((type)(expression))
  109. #define SDL_const_cast(type, expression) ((type)(expression))
  110. #endif
  111. /* @} *//* Cast operators */
  112. /* Define a four character code as a Uint32 */
  113. #define SDL_FOURCC(A, B, C, D) \
  114. ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
  115. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
  116. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
  117. (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
  118. /**
  119. * \name Basic data types
  120. */
  121. /* @{ */
  122. /**
  123. * A boolean type.
  124. */
  125. #define SDL_FALSE 0
  126. #define SDL_TRUE 1
  127. typedef int SDL_bool;
  128. /**
  129. * A signed 8-bit integer type.
  130. */
  131. #define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
  132. #define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
  133. typedef int8_t Sint8;
  134. /**
  135. * An unsigned 8-bit integer type.
  136. */
  137. #define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
  138. #define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
  139. typedef uint8_t Uint8;
  140. /**
  141. * A signed 16-bit integer type.
  142. */
  143. #define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
  144. #define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
  145. typedef int16_t Sint16;
  146. /**
  147. * An unsigned 16-bit integer type.
  148. */
  149. #define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
  150. #define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
  151. typedef uint16_t Uint16;
  152. /**
  153. * A signed 32-bit integer type.
  154. */
  155. #define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
  156. #define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
  157. typedef int32_t Sint32;
  158. /**
  159. * An unsigned 32-bit integer type.
  160. */
  161. #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
  162. #define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
  163. typedef uint32_t Uint32;
  164. /**
  165. * A signed 64-bit integer type.
  166. */
  167. #define SDL_MAX_SINT64 ((Sint64)0x7FFFFFFFFFFFFFFFll) /* 9223372036854775807 */
  168. #define SDL_MIN_SINT64 ((Sint64)(~0x7FFFFFFFFFFFFFFFll)) /* -9223372036854775808 */
  169. typedef int64_t Sint64;
  170. /**
  171. * An unsigned 64-bit integer type.
  172. */
  173. #define SDL_MAX_UINT64 ((Uint64)0xFFFFFFFFFFFFFFFFull) /* 18446744073709551615 */
  174. #define SDL_MIN_UINT64 ((Uint64)(0x0000000000000000ull)) /* 0 */
  175. typedef uint64_t Uint64;
  176. /**
  177. * SDL times are signed, 64-bit integers representing nanoseconds since the
  178. * Unix epoch (Jan 1, 1970).
  179. *
  180. * They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS()
  181. * and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with
  182. * SDL_TimeToWindows() and SDL_TimeFromWindows().
  183. */
  184. #define SDL_MAX_TIME SDL_MAX_SINT64
  185. #define SDL_MIN_TIME SDL_MIN_SINT64
  186. typedef Sint64 SDL_Time;
  187. /* @} *//* Basic data types */
  188. /**
  189. * \name Floating-point constants
  190. */
  191. /* @{ */
  192. #ifdef FLT_EPSILON
  193. #define SDL_FLT_EPSILON FLT_EPSILON
  194. #else
  195. #define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
  196. #endif
  197. /* @} *//* Floating-point constants */
  198. /* Make sure we have macros for printing width-based integers.
  199. * <stdint.h> should define these but this is not true all platforms.
  200. * (for example win32) */
  201. #ifndef SDL_PRIs64
  202. #ifdef PRIs64
  203. #define SDL_PRIs64 PRIs64
  204. #elif defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
  205. #define SDL_PRIs64 "I64d"
  206. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  207. #define SDL_PRIs64 "ld"
  208. #else
  209. #define SDL_PRIs64 "lld"
  210. #endif
  211. #endif
  212. #ifndef SDL_PRIu64
  213. #ifdef PRIu64
  214. #define SDL_PRIu64 PRIu64
  215. #elif defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
  216. #define SDL_PRIu64 "I64u"
  217. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  218. #define SDL_PRIu64 "lu"
  219. #else
  220. #define SDL_PRIu64 "llu"
  221. #endif
  222. #endif
  223. #ifndef SDL_PRIx64
  224. #ifdef PRIx64
  225. #define SDL_PRIx64 PRIx64
  226. #elif defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
  227. #define SDL_PRIx64 "I64x"
  228. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  229. #define SDL_PRIx64 "lx"
  230. #else
  231. #define SDL_PRIx64 "llx"
  232. #endif
  233. #endif
  234. #ifndef SDL_PRIX64
  235. #ifdef PRIX64
  236. #define SDL_PRIX64 PRIX64
  237. #elif defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
  238. #define SDL_PRIX64 "I64X"
  239. #elif defined(__LP64__) && !defined(SDL_PLATFORM_APPLE)
  240. #define SDL_PRIX64 "lX"
  241. #else
  242. #define SDL_PRIX64 "llX"
  243. #endif
  244. #endif
  245. #ifndef SDL_PRIs32
  246. #ifdef PRId32
  247. #define SDL_PRIs32 PRId32
  248. #else
  249. #define SDL_PRIs32 "d"
  250. #endif
  251. #endif
  252. #ifndef SDL_PRIu32
  253. #ifdef PRIu32
  254. #define SDL_PRIu32 PRIu32
  255. #else
  256. #define SDL_PRIu32 "u"
  257. #endif
  258. #endif
  259. #ifndef SDL_PRIx32
  260. #ifdef PRIx32
  261. #define SDL_PRIx32 PRIx32
  262. #else
  263. #define SDL_PRIx32 "x"
  264. #endif
  265. #endif
  266. #ifndef SDL_PRIX32
  267. #ifdef PRIX32
  268. #define SDL_PRIX32 PRIX32
  269. #else
  270. #define SDL_PRIX32 "X"
  271. #endif
  272. #endif
  273. /* Annotations to help code analysis tools */
  274. #ifdef SDL_DISABLE_ANALYZE_MACROS
  275. #define SDL_IN_BYTECAP(x)
  276. #define SDL_INOUT_Z_CAP(x)
  277. #define SDL_OUT_Z_CAP(x)
  278. #define SDL_OUT_CAP(x)
  279. #define SDL_OUT_BYTECAP(x)
  280. #define SDL_OUT_Z_BYTECAP(x)
  281. #define SDL_PRINTF_FORMAT_STRING
  282. #define SDL_SCANF_FORMAT_STRING
  283. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  284. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
  285. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  286. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
  287. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
  288. #define SDL_WSCANF_VARARG_FUNC( fmtargnumber )
  289. #else
  290. #if defined(_MSC_VER) && (_MSC_VER >= 1600) /* VS 2010 and above */
  291. #include <sal.h>
  292. #define SDL_IN_BYTECAP(x) _In_bytecount_(x)
  293. #define SDL_INOUT_Z_CAP(x) _Inout_z_cap_(x)
  294. #define SDL_OUT_Z_CAP(x) _Out_z_cap_(x)
  295. #define SDL_OUT_CAP(x) _Out_cap_(x)
  296. #define SDL_OUT_BYTECAP(x) _Out_bytecap_(x)
  297. #define SDL_OUT_Z_BYTECAP(x) _Out_z_bytecap_(x)
  298. #define SDL_PRINTF_FORMAT_STRING _Printf_format_string_
  299. #define SDL_SCANF_FORMAT_STRING _Scanf_format_string_impl_
  300. #else
  301. #define SDL_IN_BYTECAP(x)
  302. #define SDL_INOUT_Z_CAP(x)
  303. #define SDL_OUT_Z_CAP(x)
  304. #define SDL_OUT_CAP(x)
  305. #define SDL_OUT_BYTECAP(x)
  306. #define SDL_OUT_Z_BYTECAP(x)
  307. #define SDL_PRINTF_FORMAT_STRING
  308. #define SDL_SCANF_FORMAT_STRING
  309. #endif
  310. #ifdef __GNUC__
  311. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __printf__, fmtargnumber, fmtargnumber+1 )))
  312. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __printf__, fmtargnumber, 0 )))
  313. #define SDL_SCANF_VARARG_FUNC( fmtargnumber ) __attribute__ (( format( __scanf__, fmtargnumber, fmtargnumber+1 )))
  314. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber ) __attribute__(( format( __scanf__, fmtargnumber, 0 )))
  315. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wprintf__, fmtargnumber, fmtargnumber+1 ))) */
  316. #define SDL_WSCANF_VARARG_FUNC( fmtargnumber ) /* __attribute__ (( format( __wscanf__, fmtargnumber, fmtargnumber+1 ))) */
  317. #else
  318. #define SDL_PRINTF_VARARG_FUNC( fmtargnumber )
  319. #define SDL_PRINTF_VARARG_FUNCV( fmtargnumber )
  320. #define SDL_SCANF_VARARG_FUNC( fmtargnumber )
  321. #define SDL_SCANF_VARARG_FUNCV( fmtargnumber )
  322. #define SDL_WPRINTF_VARARG_FUNC( fmtargnumber )
  323. #define SDL_WSCANF_VARARG_FUNC( fmtargnumber )
  324. #endif
  325. #endif /* SDL_DISABLE_ANALYZE_MACROS */
  326. #ifndef SDL_COMPILE_TIME_ASSERT
  327. #ifdef __cplusplus
  328. #if (__cplusplus >= 201103L)
  329. #define SDL_COMPILE_TIME_ASSERT(name, x) static_assert(x, #x)
  330. #endif
  331. #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
  332. #define SDL_COMPILE_TIME_ASSERT(name, x) _Static_assert(x, #x)
  333. #endif
  334. #endif /* !SDL_COMPILE_TIME_ASSERT */
  335. #ifndef SDL_COMPILE_TIME_ASSERT
  336. /* universal, but may trigger -Wunused-local-typedefs */
  337. #define SDL_COMPILE_TIME_ASSERT(name, x) \
  338. typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]
  339. #endif
  340. /** \cond */
  341. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  342. SDL_COMPILE_TIME_ASSERT(uint8, sizeof(Uint8) == 1);
  343. SDL_COMPILE_TIME_ASSERT(sint8, sizeof(Sint8) == 1);
  344. SDL_COMPILE_TIME_ASSERT(uint16, sizeof(Uint16) == 2);
  345. SDL_COMPILE_TIME_ASSERT(sint16, sizeof(Sint16) == 2);
  346. SDL_COMPILE_TIME_ASSERT(uint32, sizeof(Uint32) == 4);
  347. SDL_COMPILE_TIME_ASSERT(sint32, sizeof(Sint32) == 4);
  348. SDL_COMPILE_TIME_ASSERT(uint64, sizeof(Uint64) == 8);
  349. SDL_COMPILE_TIME_ASSERT(sint64, sizeof(Sint64) == 8);
  350. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  351. /** \endcond */
  352. /* Check to make sure enums are the size of ints, for structure packing.
  353. For both Watcom C/C++ and Borland C/C++ the compiler option that makes
  354. enums having the size of an int must be enabled.
  355. This is "-b" for Borland C/C++ and "-ei" for Watcom C/C++ (v11).
  356. */
  357. /** \cond */
  358. #ifndef DOXYGEN_SHOULD_IGNORE_THIS
  359. #if !defined(SDL_PLATFORM_VITA) && !defined(SDL_PLATFORM_3DS)
  360. /* TODO: include/SDL_stdinc.h:390: error: size of array 'SDL_dummy_enum' is negative */
  361. typedef enum
  362. {
  363. DUMMY_ENUM_VALUE
  364. } SDL_DUMMY_ENUM;
  365. SDL_COMPILE_TIME_ASSERT(enum, sizeof(SDL_DUMMY_ENUM) == sizeof(int));
  366. #endif
  367. #endif /* DOXYGEN_SHOULD_IGNORE_THIS */
  368. /** \endcond */
  369. #include <SDL3/SDL_begin_code.h>
  370. /* Set up for C function definitions, even when using C++ */
  371. #ifdef __cplusplus
  372. extern "C" {
  373. #endif
  374. #ifndef SDL_DISABLE_ALLOCA
  375. #define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))
  376. #define SDL_stack_free(data)
  377. #else
  378. #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
  379. #define SDL_stack_free(data) SDL_free(data)
  380. #endif
  381. extern DECLSPEC SDL_MALLOC void *SDLCALL SDL_malloc(size_t size);
  382. extern DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
  383. extern DECLSPEC SDL_ALLOC_SIZE(2) void *SDLCALL SDL_realloc(void *mem, size_t size);
  384. extern DECLSPEC void SDLCALL SDL_free(void *mem);
  385. typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
  386. typedef void *(SDLCALL *SDL_calloc_func)(size_t nmemb, size_t size);
  387. typedef void *(SDLCALL *SDL_realloc_func)(void *mem, size_t size);
  388. typedef void (SDLCALL *SDL_free_func)(void *mem);
  389. /**
  390. * Get the original set of SDL memory functions.
  391. *
  392. * \param malloc_func filled with malloc function
  393. * \param calloc_func filled with calloc function
  394. * \param realloc_func filled with realloc function
  395. * \param free_func filled with free function
  396. *
  397. * \since This function is available since SDL 3.0.0.
  398. */
  399. extern DECLSPEC void SDLCALL SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
  400. SDL_calloc_func *calloc_func,
  401. SDL_realloc_func *realloc_func,
  402. SDL_free_func *free_func);
  403. /**
  404. * Get the current set of SDL memory functions.
  405. *
  406. * \param malloc_func filled with malloc function
  407. * \param calloc_func filled with calloc function
  408. * \param realloc_func filled with realloc function
  409. * \param free_func filled with free function
  410. *
  411. * \since This function is available since SDL 3.0.0.
  412. */
  413. extern DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func,
  414. SDL_calloc_func *calloc_func,
  415. SDL_realloc_func *realloc_func,
  416. SDL_free_func *free_func);
  417. /**
  418. * Replace SDL's memory allocation functions with a custom set.
  419. *
  420. * \param malloc_func custom malloc function
  421. * \param calloc_func custom calloc function
  422. * \param realloc_func custom realloc function
  423. * \param free_func custom free function
  424. * \returns 0 on success or a negative error code on failure; call
  425. * SDL_GetError() for more information.
  426. *
  427. * \since This function is available since SDL 3.0.0.
  428. */
  429. extern DECLSPEC int SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func,
  430. SDL_calloc_func calloc_func,
  431. SDL_realloc_func realloc_func,
  432. SDL_free_func free_func);
  433. /**
  434. * Allocate memory aligned to a specific value.
  435. *
  436. * If `alignment` is less than the size of `void *`, then it will be increased
  437. * to match that.
  438. *
  439. * The returned memory address will be a multiple of the alignment value, and
  440. * the amount of memory allocated will be a multiple of the alignment value.
  441. *
  442. * The memory returned by this function must be freed with SDL_aligned_free()
  443. *
  444. * \param alignment the alignment requested
  445. * \param size the size to allocate
  446. * \returns a pointer to the aligned memory
  447. *
  448. * \since This function is available since SDL 3.0.0.
  449. *
  450. * \sa SDL_aligned_free
  451. */
  452. extern DECLSPEC SDL_MALLOC void *SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);
  453. /**
  454. * Free memory allocated by SDL_aligned_alloc().
  455. *
  456. * \since This function is available since SDL 3.0.0.
  457. *
  458. * \sa SDL_aligned_alloc
  459. */
  460. extern DECLSPEC void SDLCALL SDL_aligned_free(void *mem);
  461. /**
  462. * Get the number of outstanding (unfreed) allocations.
  463. *
  464. * \returns the number of allocations
  465. *
  466. * \since This function is available since SDL 3.0.0.
  467. */
  468. extern DECLSPEC int SDLCALL SDL_GetNumAllocations(void);
  469. extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
  470. extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
  471. extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (SDLCALL *compare) (const void *, const void *));
  472. extern DECLSPEC void * SDLCALL SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (SDLCALL *compare) (const void *, const void *));
  473. extern DECLSPEC void SDLCALL SDL_qsort_r(void *base, size_t nmemb, size_t size, int (SDLCALL *compare) (void *, const void *, const void *), void *userdata);
  474. extern DECLSPEC void * SDLCALL SDL_bsearch_r(const void *key, const void *base, size_t nmemb, size_t size, int (SDLCALL *compare) (void *, const void *, const void *), void *userdata);
  475. extern DECLSPEC int SDLCALL SDL_abs(int x);
  476. /* NOTE: these double-evaluate their arguments, so you should never have side effects in the parameters */
  477. #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
  478. #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
  479. #define SDL_clamp(x, a, b) (((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))
  480. /**
  481. * Query if a character is alphabetic (a letter).
  482. *
  483. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  484. * for English 'a-z' and 'A-Z' as true.
  485. *
  486. * \param x character value to check.
  487. * \returns non-zero if x falls within the character class, zero otherwise.
  488. *
  489. * \threadsafety It is safe to call this function from any thread.
  490. *
  491. * \since This function is available since SDL 3.0.0.
  492. */
  493. extern DECLSPEC int SDLCALL SDL_isalpha(int x);
  494. /**
  495. * Query if a character is alphabetic (a letter) or a number.
  496. *
  497. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  498. * for English 'a-z', 'A-Z', and '0-9' as true.
  499. *
  500. * \param x character value to check.
  501. * \returns non-zero if x falls within the character class, zero otherwise.
  502. *
  503. * \threadsafety It is safe to call this function from any thread.
  504. *
  505. * \since This function is available since SDL 3.0.0.
  506. */
  507. extern DECLSPEC int SDLCALL SDL_isalnum(int x);
  508. /**
  509. * Report if a character is blank (a space or tab).
  510. *
  511. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  512. * 0x20 (space) or 0x9 (tab) as true.
  513. *
  514. * \param x character value to check.
  515. * \returns non-zero if x falls within the character class, zero otherwise.
  516. *
  517. * \threadsafety It is safe to call this function from any thread.
  518. *
  519. * \since This function is available since SDL 3.0.0.
  520. */
  521. extern DECLSPEC int SDLCALL SDL_isblank(int x);
  522. /**
  523. * Report if a character is a control character.
  524. *
  525. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  526. * 0 through 0x1F, and 0x7F, as true.
  527. *
  528. * \param x character value to check.
  529. * \returns non-zero if x falls within the character class, zero otherwise.
  530. *
  531. * \threadsafety It is safe to call this function from any thread.
  532. *
  533. * \since This function is available since SDL 3.0.0.
  534. */
  535. extern DECLSPEC int SDLCALL SDL_iscntrl(int x);
  536. /**
  537. * Report if a character is a numeric digit.
  538. *
  539. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  540. * '0' (0x30) through '9' (0x39), as true.
  541. *
  542. * \param x character value to check.
  543. * \returns non-zero if x falls within the character class, zero otherwise.
  544. *
  545. * \threadsafety It is safe to call this function from any thread.
  546. *
  547. * \since This function is available since SDL 3.0.0.
  548. */
  549. extern DECLSPEC int SDLCALL SDL_isdigit(int x);
  550. /**
  551. * Report if a character is a hexadecimal digit.
  552. *
  553. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  554. * 'A' through 'F', 'a' through 'f', and '0' through '9', as true.
  555. *
  556. * \param x character value to check.
  557. * \returns non-zero if x falls within the character class, zero otherwise.
  558. *
  559. * \threadsafety It is safe to call this function from any thread.
  560. *
  561. * \since This function is available since SDL 3.0.0.
  562. */
  563. extern DECLSPEC int SDLCALL SDL_isxdigit(int x);
  564. /**
  565. * Report if a character is a punctuation mark.
  566. *
  567. * **WARNING**: Regardless of system locale, this is equivalent to
  568. * `((SDL_isgraph(x)) && (!SDL_isalnum(x)))`.
  569. *
  570. * \param x character value to check.
  571. * \returns non-zero if x falls within the character class, zero otherwise.
  572. *
  573. * \threadsafety It is safe to call this function from any thread.
  574. *
  575. * \since This function is available since SDL 3.0.0.
  576. *
  577. * \sa SDL_isgraph
  578. * \sa SDL_isalnum
  579. */
  580. extern DECLSPEC int SDLCALL SDL_ispunct(int x);
  581. /**
  582. * Report if a character is whitespace.
  583. *
  584. * **WARNING**: Regardless of system locale, this will only treat the
  585. * following ASCII values as true:
  586. *
  587. * - space (0x20)
  588. * - tab (0x09)
  589. * - newline (0x0A)
  590. * - vertical tab (0x0B)
  591. * - form feed (0x0C)
  592. * - return (0x0D)
  593. *
  594. * \param x character value to check.
  595. * \returns non-zero if x falls within the character class, zero otherwise.
  596. *
  597. * \threadsafety It is safe to call this function from any thread.
  598. *
  599. * \since This function is available since SDL 3.0.0.
  600. */
  601. extern DECLSPEC int SDLCALL SDL_isspace(int x);
  602. /**
  603. * Report if a character is upper case.
  604. *
  605. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  606. * 'A' through 'Z' as true.
  607. *
  608. * \param x character value to check.
  609. * \returns non-zero if x falls within the character class, zero otherwise.
  610. *
  611. * \threadsafety It is safe to call this function from any thread.
  612. *
  613. * \since This function is available since SDL 3.0.0.
  614. */
  615. extern DECLSPEC int SDLCALL SDL_isupper(int x);
  616. /**
  617. * Report if a character is lower case.
  618. *
  619. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  620. * 'a' through 'z' as true.
  621. *
  622. * \param x character value to check.
  623. * \returns non-zero if x falls within the character class, zero otherwise.
  624. *
  625. * \threadsafety It is safe to call this function from any thread.
  626. *
  627. * \since This function is available since SDL 3.0.0.
  628. */
  629. extern DECLSPEC int SDLCALL SDL_islower(int x);
  630. /**
  631. * Report if a character is "printable".
  632. *
  633. * Be advised that "printable" has a definition that goes back to text
  634. * terminals from the dawn of computing, making this a sort of special case
  635. * function that is not suitable for Unicode (or most any) text management.
  636. *
  637. * **WARNING**: Regardless of system locale, this will only treat ASCII values
  638. * ' ' (0x20) through '~' (0x7E) as true.
  639. *
  640. * \param x character value to check.
  641. * \returns non-zero if x falls within the character class, zero otherwise.
  642. *
  643. * \threadsafety It is safe to call this function from any thread.
  644. *
  645. * \since This function is available since SDL 3.0.0.
  646. */
  647. extern DECLSPEC int SDLCALL SDL_isprint(int x);
  648. /**
  649. * Report if a character is any "printable" except space.
  650. *
  651. * Be advised that "printable" has a definition that goes back to text
  652. * terminals from the dawn of computing, making this a sort of special case
  653. * function that is not suitable for Unicode (or most any) text management.
  654. *
  655. * **WARNING**: Regardless of system locale, this is equivalent to
  656. * `(SDL_isprint(x)) && ((x) != ' ')`.
  657. *
  658. * \param x character value to check.
  659. * \returns non-zero if x falls within the character class, zero otherwise.
  660. *
  661. * \threadsafety It is safe to call this function from any thread.
  662. *
  663. * \since This function is available since SDL 3.0.0.
  664. *
  665. * \sa SDL_isprint
  666. */
  667. extern DECLSPEC int SDLCALL SDL_isgraph(int x);
  668. /**
  669. * Convert low-ASCII English letters to uppercase.
  670. *
  671. * **WARNING**: Regardless of system locale, this will only convert ASCII
  672. * values 'a' through 'z' to uppercase.
  673. *
  674. * This function returns the uppercase equivalent of `x`. If a character
  675. * cannot be converted, or is already uppercase, this function returns `x`.
  676. *
  677. * \param x character value to check.
  678. * \returns Capitalized version of x, or x if no conversion available.
  679. *
  680. * \threadsafety It is safe to call this function from any thread.
  681. *
  682. * \since This function is available since SDL 3.0.0.
  683. */
  684. extern DECLSPEC int SDLCALL SDL_toupper(int x);
  685. /**
  686. * Convert low-ASCII English letters to lowercase.
  687. *
  688. * **WARNING**: Regardless of system locale, this will only convert ASCII
  689. * values 'A' through 'Z' to lowercase.
  690. *
  691. * This function returns the lowercase equivalent of `x`. If a character
  692. * cannot be converted, or is already lowercase, this function returns `x`.
  693. *
  694. * \param x character value to check.
  695. * \returns Lowercase version of x, or x if no conversion available.
  696. *
  697. * \threadsafety It is safe to call this function from any thread.
  698. *
  699. * \since This function is available since SDL 3.0.0.
  700. */
  701. extern DECLSPEC int SDLCALL SDL_tolower(int x);
  702. extern DECLSPEC Uint16 SDLCALL SDL_crc16(Uint16 crc, const void *data, size_t len);
  703. extern DECLSPEC Uint32 SDLCALL SDL_crc32(Uint32 crc, const void *data, size_t len);
  704. extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  705. /* Take advantage of compiler optimizations for memcpy */
  706. #ifndef SDL_SLOW_MEMCPY
  707. #ifdef SDL_memcpy
  708. #undef SDL_memcpy
  709. #endif
  710. #define SDL_memcpy memcpy
  711. #endif
  712. #define SDL_copyp(dst, src) \
  713. { SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
  714. SDL_memcpy((dst), (src), sizeof(*(src)))
  715. extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
  716. /* Take advantage of compiler optimizations for memmove */
  717. #ifndef SDL_SLOW_MEMMOVE
  718. #ifdef SDL_memmove
  719. #undef SDL_memmove
  720. #endif
  721. #define SDL_memmove memmove
  722. #endif
  723. extern DECLSPEC void *SDLCALL SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len);
  724. extern DECLSPEC void *SDLCALL SDL_memset4(void *dst, Uint32 val, size_t dwords);
  725. /* Take advantage of compiler optimizations for memset */
  726. #ifndef SDL_SLOW_MEMSET
  727. #ifdef SDL_memset
  728. #undef SDL_memset
  729. #endif
  730. #define SDL_memset memset
  731. #endif
  732. #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
  733. #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
  734. #define SDL_zeroa(x) SDL_memset((x), 0, sizeof((x)))
  735. extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
  736. extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
  737. extern DECLSPEC size_t SDLCALL SDL_wcsnlen(const wchar_t *wstr, size_t maxlen);
  738. extern DECLSPEC size_t SDLCALL SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  739. extern DECLSPEC size_t SDLCALL SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen);
  740. extern DECLSPEC wchar_t *SDLCALL SDL_wcsdup(const wchar_t *wstr);
  741. extern DECLSPEC wchar_t *SDLCALL SDL_wcsstr(const wchar_t *haystack, const wchar_t *needle);
  742. extern DECLSPEC wchar_t *SDLCALL SDL_wcsnstr(const wchar_t *haystack, const wchar_t *needle, size_t maxlen);
  743. /**
  744. * Compare two null-terminated wide strings.
  745. *
  746. * This only compares wchar_t values until it hits a null-terminating
  747. * character; it does not care if the string is well-formed UTF-16 (or UTF-32,
  748. * depending on your platform's wchar_t size), or uses valid Unicode values.
  749. *
  750. * \param str1 The first string to compare. NULL is not permitted!
  751. * \param str2 The second string to compare. NULL is not permitted!
  752. * \returns less than zero if str1 is "less than" str2, greater than zero if
  753. * str1 is "greater than" str2, and zero if the strings match
  754. * exactly.
  755. *
  756. * \threadsafety It is safe to call this function from any thread.
  757. *
  758. * \since This function is available since SDL 3.0.0.
  759. */
  760. extern DECLSPEC int SDLCALL SDL_wcscmp(const wchar_t *str1, const wchar_t *str2);
  761. /**
  762. * Compare two wide strings up to a number of wchar_t values.
  763. *
  764. * This only compares wchar_t values; it does not care if the string is
  765. * well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size),
  766. * or uses valid Unicode values.
  767. *
  768. * Note that while this function is intended to be used with UTF-16 (or
  769. * UTF-32, depending on your platform's definition of wchar_t), it is
  770. * comparing raw wchar_t values and not Unicode codepoints: `maxlen` specifies
  771. * a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16
  772. * sequence, it will only compare a portion of the final character.
  773. *
  774. * `maxlen` specifies a maximum number of wchar_t to compare; if the strings
  775. * match to this number of wide chars (or both have matched to a
  776. * null-terminator character before this count), they will be considered
  777. * equal.
  778. *
  779. * \param str1 The first string to compare. NULL is not permitted!
  780. * \param str2 The second string to compare. NULL is not permitted!
  781. * \param maxlen The maximum number of wchar_t to compare.
  782. * \returns less than zero if str1 is "less than" str2, greater than zero if
  783. * str1 is "greater than" str2, and zero if the strings match
  784. * exactly.
  785. *
  786. * \threadsafety It is safe to call this function from any thread.
  787. *
  788. * \since This function is available since SDL 3.0.0.
  789. */
  790. extern DECLSPEC int SDLCALL SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  791. /**
  792. * Compare two null-terminated wide strings, case-insensitively.
  793. *
  794. * This will work with Unicode strings, using a technique called
  795. * "case-folding" to handle the vast majority of case-sensitive human
  796. * languages regardless of system locale. It can deal with expanding values: a
  797. * German Eszett character can compare against two ASCII 's' chars and be
  798. * considered a match, for example. A notable exception: it does not handle
  799. * the Turkish 'i' character; human language is complicated!
  800. *
  801. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  802. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  803. * handles Unicode, it expects the string to be well-formed and not a
  804. * null-terminated string of arbitrary bytes. Characters that are not valid
  805. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  806. * CHARACTER), which is to say two strings of random bits may turn out to
  807. * match if they convert to the same amount of replacement characters.
  808. *
  809. * \param str1 The first string to compare. NULL is not permitted!
  810. * \param str2 The second string to compare. NULL is not permitted!
  811. * \returns less than zero if str1 is "less than" str2, greater than zero if
  812. * str1 is "greater than" str2, and zero if the strings match
  813. * exactly.
  814. *
  815. * \threadsafety It is safe to call this function from any thread.
  816. *
  817. * \since This function is available since SDL 3.0.0.
  818. */
  819. extern DECLSPEC int SDLCALL SDL_wcscasecmp(const wchar_t *str1, const wchar_t *str2);
  820. /**
  821. * Compare two wide strings, case-insensitively, up to a number of wchar_t.
  822. *
  823. * This will work with Unicode strings, using a technique called
  824. * "case-folding" to handle the vast majority of case-sensitive human
  825. * languages regardless of system locale. It can deal with expanding values: a
  826. * German Eszett character can compare against two ASCII 's' chars and be
  827. * considered a match, for example. A notable exception: it does not handle
  828. * the Turkish 'i' character; human language is complicated!
  829. *
  830. * Depending on your platform, "wchar_t" might be 2 bytes, and expected to be
  831. * UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this
  832. * handles Unicode, it expects the string to be well-formed and not a
  833. * null-terminated string of arbitrary bytes. Characters that are not valid
  834. * UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT
  835. * CHARACTER), which is to say two strings of random bits may turn out to
  836. * match if they convert to the same amount of replacement characters.
  837. *
  838. * Note that while this function might deal with variable-sized characters,
  839. * `maxlen` specifies a _wchar_ limit! If the limit lands in the middle of a
  840. * multi-byte UTF-16 sequence, it may convert a portion of the final character
  841. * to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not
  842. * to overflow a buffer.
  843. *
  844. * `maxlen` specifies a maximum number of wchar_t values to compare; if the
  845. * strings match to this number of wchar_t (or both have matched to a
  846. * null-terminator character before this number of bytes), they will be
  847. * considered equal.
  848. *
  849. * \param str1 The first string to compare. NULL is not permitted!
  850. * \param str2 The second string to compare. NULL is not permitted!
  851. * \param maxlen The maximum number of wchar_t values to compare.
  852. * \returns less than zero if str1 is "less than" str2, greater than zero if
  853. * str1 is "greater than" str2, and zero if the strings match
  854. * exactly.
  855. *
  856. * \threadsafety It is safe to call this function from any thread.
  857. *
  858. * \since This function is available since SDL 3.0.0.
  859. */
  860. extern DECLSPEC int SDLCALL SDL_wcsncasecmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen);
  861. extern DECLSPEC long SDLCALL SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);
  862. extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
  863. extern DECLSPEC size_t SDLCALL SDL_strnlen(const char *str, size_t maxlen);
  864. extern DECLSPEC size_t SDLCALL SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  865. extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes);
  866. extern DECLSPEC size_t SDLCALL SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen);
  867. extern DECLSPEC SDL_MALLOC char *SDLCALL SDL_strdup(const char *str);
  868. extern DECLSPEC SDL_MALLOC char *SDLCALL SDL_strndup(const char *str, size_t maxlen);
  869. extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
  870. /**
  871. * Convert a string to uppercase.
  872. *
  873. * **WARNING**: Regardless of system locale, this will only convert ASCII
  874. * values 'A' through 'Z' to uppercase.
  875. *
  876. * This function operates on a null-terminated string of bytes--even if it is
  877. * malformed UTF-8!--and converts ASCII characters 'a' through 'z' to their
  878. * uppercase equivalents in-place, returning the original `str` pointer.
  879. *
  880. * \threadsafety It is safe to call this function from any thread.
  881. *
  882. * \since This function is available since SDL 3.0.0.
  883. *
  884. * \sa SDL_strlwr
  885. */
  886. extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
  887. /**
  888. * Convert a string to lowercase.
  889. *
  890. * **WARNING**: Regardless of system locale, this will only convert ASCII
  891. * values 'A' through 'Z' to lowercase.
  892. *
  893. * This function operates on a null-terminated string of bytes--even if it is
  894. * malformed UTF-8!--and converts ASCII characters 'A' through 'Z' to their
  895. * lowercase equivalents in-place, returning the original `str` pointer.
  896. *
  897. * \param str The string to convert in-place.
  898. * \returns The `str` pointer passed into this function.
  899. *
  900. * \threadsafety It is safe to call this function from any thread.
  901. *
  902. * \since This function is available since SDL 3.0.0.
  903. *
  904. * \sa SDL_strupr
  905. */
  906. extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
  907. extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
  908. extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
  909. extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
  910. extern DECLSPEC char *SDLCALL SDL_strnstr(const char *haystack, const char *needle, size_t maxlen);
  911. extern DECLSPEC char *SDLCALL SDL_strcasestr(const char *haystack, const char *needle);
  912. extern DECLSPEC char *SDLCALL SDL_strtok_r(char *s1, const char *s2, char **saveptr);
  913. extern DECLSPEC size_t SDLCALL SDL_utf8strlen(const char *str);
  914. extern DECLSPEC size_t SDLCALL SDL_utf8strnlen(const char *str, size_t bytes);
  915. extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
  916. extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
  917. extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
  918. extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
  919. extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
  920. extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
  921. extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
  922. extern DECLSPEC double SDLCALL SDL_atof(const char *str);
  923. extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
  924. extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
  925. extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
  926. extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
  927. extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
  928. /**
  929. * Compare two null-terminated UTF-8 strings.
  930. *
  931. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  932. * since effectively this function just compares bytes until it hits a
  933. * null-terminating character. Also due to the nature of UTF-8, this can be
  934. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  935. *
  936. * \param str1 The first string to compare. NULL is not permitted!
  937. * \param str2 The second string to compare. NULL is not permitted!
  938. * \returns less than zero if str1 is "less than" str2, greater than zero if
  939. * str1 is "greater than" str2, and zero if the strings match
  940. * exactly.
  941. *
  942. * \threadsafety It is safe to call this function from any thread.
  943. *
  944. * \since This function is available since SDL 3.0.0.
  945. */
  946. extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
  947. /**
  948. * Compare two UTF-8 strings up to a number of bytes.
  949. *
  950. * Due to the nature of UTF-8 encoding, this will work with Unicode strings,
  951. * since effectively this function just compares bytes until it hits a
  952. * null-terminating character. Also due to the nature of UTF-8, this can be
  953. * used with SDL_qsort() to put strings in (roughly) alphabetical order.
  954. *
  955. * Note that while this function is intended to be used with UTF-8, it is
  956. * doing a bytewise comparison, and `maxlen` specifies a _byte_ limit! If the
  957. * limit lands in the middle of a multi-byte UTF-8 sequence, it will only
  958. * compare a portion of the final character.
  959. *
  960. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  961. * match to this number of bytes (or both have matched to a null-terminator
  962. * character before this number of bytes), they will be considered equal.
  963. *
  964. * \param str1 The first string to compare. NULL is not permitted!
  965. * \param str2 The second string to compare. NULL is not permitted!
  966. * \param maxlen The maximum number of _bytes_ to compare.
  967. * \returns less than zero if str1 is "less than" str2, greater than zero if
  968. * str1 is "greater than" str2, and zero if the strings match
  969. * exactly.
  970. *
  971. * \threadsafety It is safe to call this function from any thread.
  972. *
  973. * \since This function is available since SDL 3.0.0.
  974. */
  975. extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
  976. /**
  977. * Compare two null-terminated UTF-8 strings, case-insensitively.
  978. *
  979. * This will work with Unicode strings, using a technique called
  980. * "case-folding" to handle the vast majority of case-sensitive human
  981. * languages regardless of system locale. It can deal with expanding values: a
  982. * German Eszett character can compare against two ASCII 's' chars and be
  983. * considered a match, for example. A notable exception: it does not handle
  984. * the Turkish 'i' character; human language is complicated!
  985. *
  986. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  987. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  988. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  989. * CHARACTER), which is to say two strings of random bits may turn out to
  990. * match if they convert to the same amount of replacement characters.
  991. *
  992. * \param str1 The first string to compare. NULL is not permitted!
  993. * \param str2 The second string to compare. NULL is not permitted!
  994. * \returns less than zero if str1 is "less than" str2, greater than zero if
  995. * str1 is "greater than" str2, and zero if the strings match
  996. * exactly.
  997. *
  998. * \threadsafety It is safe to call this function from any thread.
  999. *
  1000. * \since This function is available since SDL 3.0.0.
  1001. */
  1002. extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
  1003. /**
  1004. * Compare two UTF-8 strings, case-insensitively, up to a number of bytes.
  1005. *
  1006. * This will work with Unicode strings, using a technique called
  1007. * "case-folding" to handle the vast majority of case-sensitive human
  1008. * languages regardless of system locale. It can deal with expanding values: a
  1009. * German Eszett character can compare against two ASCII 's' chars and be
  1010. * considered a match, for example. A notable exception: it does not handle
  1011. * the Turkish 'i' character; human language is complicated!
  1012. *
  1013. * Since this handles Unicode, it expects the string to be well-formed UTF-8
  1014. * and not a null-terminated string of arbitrary bytes. Bytes that are not
  1015. * valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT
  1016. * CHARACTER), which is to say two strings of random bits may turn out to
  1017. * match if they convert to the same amount of replacement characters.
  1018. *
  1019. * Note that while this function is intended to be used with UTF-8, `maxlen`
  1020. * specifies a _byte_ limit! If the limit lands in the middle of a multi-byte
  1021. * UTF-8 sequence, it may convert a portion of the final character to one or
  1022. * more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow
  1023. * a buffer.
  1024. *
  1025. * `maxlen` specifies a maximum number of bytes to compare; if the strings
  1026. * match to this number of bytes (or both have matched to a null-terminator
  1027. * character before this number of bytes), they will be considered equal.
  1028. *
  1029. * \param str1 The first string to compare. NULL is not permitted!
  1030. * \param str2 The second string to compare. NULL is not permitted!
  1031. * \param maxlen The maximum number of bytes to compare.
  1032. * \returns less than zero if str1 is "less than" str2, greater than zero if
  1033. * str1 is "greater than" str2, and zero if the strings match
  1034. * exactly.
  1035. *
  1036. * \threadsafety It is safe to call this function from any thread.
  1037. *
  1038. * \since This function is available since SDL 3.0.0.
  1039. */
  1040. extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen);
  1041. extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...) SDL_SCANF_VARARG_FUNC(2);
  1042. extern DECLSPEC int SDLCALL SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2);
  1043. extern DECLSPEC int SDLCALL SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ... ) SDL_PRINTF_VARARG_FUNC(3);
  1044. extern DECLSPEC int SDLCALL SDL_swprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ... ) SDL_WPRINTF_VARARG_FUNC(3);
  1045. extern DECLSPEC int SDLCALL SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3);
  1046. extern DECLSPEC int SDLCALL SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap);
  1047. extern DECLSPEC int SDLCALL SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(2);
  1048. extern DECLSPEC int SDLCALL SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2);
  1049. #ifndef SDL_PI_D
  1050. #define SDL_PI_D 3.141592653589793238462643383279502884 /**< pi (double) */
  1051. #endif
  1052. #ifndef SDL_PI_F
  1053. #define SDL_PI_F 3.141592653589793238462643383279502884F /**< pi (float) */
  1054. #endif
  1055. /**
  1056. * Compute the arc cosine of `x`.
  1057. *
  1058. * The definition of `y = acos(x)` is `x = cos(y)`.
  1059. *
  1060. * Domain: `-1 <= x <= 1`
  1061. *
  1062. * Range: `0 <= y <= Pi`
  1063. *
  1064. * This function operates on double-precision floating point values, use
  1065. * SDL_acosf for single-precision floats.
  1066. *
  1067. * This function may use a different approximation across different versions,
  1068. * platforms and configurations. i.e, it can return a different value given
  1069. * the same input on different machines or operating systems, or if SDL is
  1070. * updated.
  1071. *
  1072. * \param x floating point value
  1073. * \returns arc cosine of `x`, in radians
  1074. *
  1075. * \threadsafety It is safe to call this function from any thread.
  1076. *
  1077. * \since This function is available since SDL 3.0.0.
  1078. *
  1079. * \sa SDL_acosf
  1080. * \sa SDL_asin
  1081. * \sa SDL_cos
  1082. */
  1083. extern DECLSPEC double SDLCALL SDL_acos(double x);
  1084. /**
  1085. * Compute the arc cosine of `x`.
  1086. *
  1087. * The definition of `y = acos(x)` is `x = cos(y)`.
  1088. *
  1089. * Domain: `-1 <= x <= 1`
  1090. *
  1091. * Range: `0 <= y <= Pi`
  1092. *
  1093. * This function operates on single-precision floating point values, use
  1094. * SDL_acos for double-precision floats.
  1095. *
  1096. * This function may use a different approximation across different versions,
  1097. * platforms and configurations. i.e, it can return a different value given
  1098. * the same input on different machines or operating systems, or if SDL is
  1099. * updated.
  1100. *
  1101. * \param x floating point value.
  1102. * \returns arc cosine of `x`, in radians
  1103. *
  1104. * \since This function is available since SDL 3.0.0.
  1105. *
  1106. * \sa SDL_acos
  1107. * \sa SDL_asinf
  1108. * \sa SDL_cosf
  1109. */
  1110. extern DECLSPEC float SDLCALL SDL_acosf(float x);
  1111. /**
  1112. * Compute the arc sine of `x`.
  1113. *
  1114. * The definition of `y = asin(x)` is `x = sin(y)`.
  1115. *
  1116. * Domain: `-1 <= x <= 1`
  1117. *
  1118. * Range: `-Pi/2 <= y <= Pi/2`
  1119. *
  1120. * This function operates on double-precision floating point values, use
  1121. * SDL_asinf for single-precision floats.
  1122. *
  1123. * This function may use a different approximation across different versions,
  1124. * platforms and configurations. i.e, it can return a different value given
  1125. * the same input on different machines or operating systems, or if SDL is
  1126. * updated.
  1127. *
  1128. * \param x floating point value.
  1129. * \returns arc sine of `x`, in radians.
  1130. *
  1131. * \since This function is available since SDL 3.0.0.
  1132. *
  1133. * \sa SDL_asinf
  1134. * \sa SDL_acos
  1135. * \sa SDL_sin
  1136. */
  1137. extern DECLSPEC double SDLCALL SDL_asin(double x);
  1138. /**
  1139. * Compute the arc sine of `x`.
  1140. *
  1141. * The definition of `y = asin(x)` is `x = sin(y)`.
  1142. *
  1143. * Domain: `-1 <= x <= 1`
  1144. *
  1145. * Range: `-Pi/2 <= y <= Pi/2`
  1146. *
  1147. * This function operates on single-precision floating point values, use
  1148. * SDL_asin for double-precision floats.
  1149. *
  1150. * This function may use a different approximation across different versions,
  1151. * platforms and configurations. i.e, it can return a different value given
  1152. * the same input on different machines or operating systems, or if SDL is
  1153. * updated.
  1154. *
  1155. * \param x floating point value.
  1156. * \returns arc sine of `x`, in radians.
  1157. *
  1158. * \since This function is available since SDL 3.0.0.
  1159. *
  1160. * \sa SDL_asin
  1161. * \sa SDL_acosf
  1162. * \sa SDL_sinf
  1163. */
  1164. extern DECLSPEC float SDLCALL SDL_asinf(float x);
  1165. /**
  1166. * Compute the arc tangent of `x`.
  1167. *
  1168. * The definition of `y = atan(x)` is `x = tan(y)`.
  1169. *
  1170. * Domain: `-INF <= x <= INF`
  1171. *
  1172. * Range: `-Pi/2 <= y <= Pi/2`
  1173. *
  1174. * This function operates on double-precision floating point values, use
  1175. * SDL_atanf for single-precision floats.
  1176. *
  1177. * To calculate the arc tangent of y / x, use SDL_atan2.
  1178. *
  1179. * This function may use a different approximation across different versions,
  1180. * platforms and configurations. i.e, it can return a different value given
  1181. * the same input on different machines or operating systems, or if SDL is
  1182. * updated.
  1183. *
  1184. * \param x floating point value.
  1185. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`.
  1186. *
  1187. * \since This function is available since SDL 3.0.0.
  1188. *
  1189. * \sa SDL_atanf
  1190. * \sa SDL_atan2
  1191. * \sa SDL_tan
  1192. */
  1193. extern DECLSPEC double SDLCALL SDL_atan(double x);
  1194. /**
  1195. * Compute the arc tangent of `x`.
  1196. *
  1197. * The definition of `y = atan(x)` is `x = tan(y)`.
  1198. *
  1199. * Domain: `-INF <= x <= INF`
  1200. *
  1201. * Range: `-Pi/2 <= y <= Pi/2`
  1202. *
  1203. * This function operates on single-precision floating point values, use
  1204. * SDL_atan for dboule-precision floats.
  1205. *
  1206. * To calculate the arc tangent of y / x, use SDL_atan2f.
  1207. *
  1208. * This function may use a different approximation across different versions,
  1209. * platforms and configurations. i.e, it can return a different value given
  1210. * the same input on different machines or operating systems, or if SDL is
  1211. * updated.
  1212. *
  1213. * \param x floating point value.
  1214. * \returns arc tangent of of `x` in radians, or 0 if `x = 0`
  1215. *
  1216. * \since This function is available since SDL 3.0.0.
  1217. *
  1218. * \sa SDL_atan
  1219. * \sa SDL_atan2f
  1220. * \sa SDL_tanf
  1221. */
  1222. extern DECLSPEC float SDLCALL SDL_atanf(float x);
  1223. /**
  1224. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  1225. * the result's quadrant.
  1226. *
  1227. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  1228. * of z is determined based on the signs of x and y.
  1229. *
  1230. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  1231. *
  1232. * Range: `-Pi/2 <= y <= Pi/2`
  1233. *
  1234. * This function operates on double-precision floating point values, use
  1235. * SDL_atan2f for single-precision floats.
  1236. *
  1237. * To calculate the arc tangent of a single value, use SDL_atan.
  1238. *
  1239. * This function may use a different approximation across different versions,
  1240. * platforms and configurations. i.e, it can return a different value given
  1241. * the same input on different machines or operating systems, or if SDL is
  1242. * updated.
  1243. *
  1244. * \param x floating point value of the denominator (x coordinate).
  1245. * \param y floating point value of the numerator (y coordinate)
  1246. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  1247. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  1248. *
  1249. * \since This function is available since SDL 3.0.0.
  1250. *
  1251. * \sa SDL_atan2f
  1252. * \sa SDL_atan
  1253. * \sa SDL_tan
  1254. */
  1255. extern DECLSPEC double SDLCALL SDL_atan2(double y, double x);
  1256. /**
  1257. * Compute the arc tangent of `y / x`, using the signs of x and y to adjust
  1258. * the result's quadrant.
  1259. *
  1260. * The definition of `z = atan2(x, y)` is `y = x tan(z)`, where the quadrant
  1261. * of z is determined based on the signs of x and y.
  1262. *
  1263. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  1264. *
  1265. * Range: `-Pi/2 <= y <= Pi/2`
  1266. *
  1267. * This function operates on single-precision floating point values, use
  1268. * SDL_atan2 for double-precision floats.
  1269. *
  1270. * To calculate the arc tangent of a single value, use SDL_atanf.
  1271. *
  1272. * This function may use a different approximation across different versions,
  1273. * platforms and configurations. i.e, it can return a different value given
  1274. * the same input on different machines or operating systems, or if SDL is
  1275. * updated.
  1276. *
  1277. * \param x floating point value of the denominator (x coordinate).
  1278. * \param y floating point value of the numerator (y coordinate)
  1279. * \returns arc tangent of of `y / x` in radians, or, if `x = 0`, either
  1280. * `-Pi/2`, `0`, or `Pi/2`, depending on the value of `y`.
  1281. *
  1282. * \since This function is available since SDL 3.0.0.
  1283. *
  1284. * \sa SDL_atan2f
  1285. * \sa SDL_atan
  1286. * \sa SDL_tan
  1287. */
  1288. extern DECLSPEC float SDLCALL SDL_atan2f(float y, float x);
  1289. /**
  1290. * Compute the ceiling of `x`.
  1291. *
  1292. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  1293. * rounded up to the nearest integer.
  1294. *
  1295. * Domain: `-INF <= x <= INF`
  1296. *
  1297. * Range: `-INF <= y <= INF`, y integer
  1298. *
  1299. * This function operates on double-precision floating point values, use
  1300. * SDL_ceilf for single-precision floats.
  1301. *
  1302. * \param x floating point value
  1303. * \returns the ceiling of `x`
  1304. *
  1305. * \since This function is available since SDL 3.0.0.
  1306. *
  1307. * \sa SDL_ceilf
  1308. * \sa SDL_floor
  1309. * \sa SDL_trunc
  1310. * \sa SDL_round
  1311. * \sa SDL_lround
  1312. */
  1313. extern DECLSPEC double SDLCALL SDL_ceil(double x);
  1314. /**
  1315. * Compute the ceiling of `x`.
  1316. *
  1317. * The ceiling of `x` is the smallest integer `y` such that `y > x`, i.e `x`
  1318. * rounded up to the nearest integer.
  1319. *
  1320. * Domain: `-INF <= x <= INF`
  1321. *
  1322. * Range: `-INF <= y <= INF`, y integer
  1323. *
  1324. * This function operates on single-precision floating point values, use
  1325. * SDL_ceil for double-precision floats.
  1326. *
  1327. * \param x floating point value
  1328. * \returns the ceiling of `x`
  1329. *
  1330. * \since This function is available since SDL 3.0.0.
  1331. *
  1332. * \sa SDL_ceil
  1333. * \sa SDL_floorf
  1334. * \sa SDL_truncf
  1335. * \sa SDL_roundf
  1336. * \sa SDL_lroundf
  1337. */
  1338. extern DECLSPEC float SDLCALL SDL_ceilf(float x);
  1339. /**
  1340. * Copy the sign of one floating-point value to another.
  1341. *
  1342. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  1343. *
  1344. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  1345. *
  1346. * Range: `-INF <= z <= INF`
  1347. *
  1348. * This function operates on double-precision floating point values, use
  1349. * SDL_copysignf for single-precision floats.
  1350. *
  1351. * \param x floating point value to use as the magnitude
  1352. * \param y floating point value to use as the sign
  1353. * \returns the floating point value with the sign of y and the magnitude of x
  1354. *
  1355. * \since This function is available since SDL 3.0.0.
  1356. *
  1357. * \sa SDL_copysignf
  1358. * \sa SDL_fabs
  1359. */
  1360. extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
  1361. /**
  1362. * Copy the sign of one floating-point value to another.
  1363. *
  1364. * The definition of copysign is that ``copysign(x, y) = abs(x) * sign(y)``.
  1365. *
  1366. * Domain: `-INF <= x <= INF`, ``-INF <= y <= f``
  1367. *
  1368. * Range: `-INF <= z <= INF`
  1369. *
  1370. * This function operates on single-precision floating point values, use
  1371. * SDL_copysign for double-precision floats.
  1372. *
  1373. * \param x floating point value to use as the magnitude
  1374. * \param y floating point value to use as the sign
  1375. * \returns the floating point value with the sign of y and the magnitude of x
  1376. *
  1377. * \since This function is available since SDL 3.0.0.
  1378. *
  1379. * \sa SDL_copysignf
  1380. * \sa SDL_fabsf
  1381. */
  1382. extern DECLSPEC float SDLCALL SDL_copysignf(float x, float y);
  1383. /**
  1384. * Compute the cosine of `x`.
  1385. *
  1386. * Domain: `-INF <= x <= INF`
  1387. *
  1388. * Range: `-1 <= y <= 1`
  1389. *
  1390. * This function operates on double-precision floating point values, use
  1391. * SDL_cosf for single-precision floats.
  1392. *
  1393. * This function may use a different approximation across different versions,
  1394. * platforms and configurations. i.e, it can return a different value given
  1395. * the same input on different machines or operating systems, or if SDL is
  1396. * updated.
  1397. *
  1398. * \param x floating point value, in radians
  1399. * \returns cosine of `x`
  1400. *
  1401. * \since This function is available since SDL 3.0.0.
  1402. *
  1403. * \sa SDL_cosf
  1404. * \sa SDL_acos
  1405. * \sa SDL_sin
  1406. */
  1407. extern DECLSPEC double SDLCALL SDL_cos(double x);
  1408. /**
  1409. * Compute the cosine of `x`.
  1410. *
  1411. * Domain: `-INF <= x <= INF`
  1412. *
  1413. * Range: `-1 <= y <= 1`
  1414. *
  1415. * This function operates on single-precision floating point values, use
  1416. * SDL_cos for double-precision floats.
  1417. *
  1418. * This function may use a different approximation across different versions,
  1419. * platforms and configurations. i.e, it can return a different value given
  1420. * the same input on different machines or operating systems, or if SDL is
  1421. * updated.
  1422. *
  1423. * \param x floating point value, in radians
  1424. * \returns cosine of `x`
  1425. *
  1426. * \since This function is available since SDL 3.0.0.
  1427. *
  1428. * \sa SDL_cos
  1429. * \sa SDL_acosf
  1430. * \sa SDL_sinf
  1431. */
  1432. extern DECLSPEC float SDLCALL SDL_cosf(float x);
  1433. /**
  1434. * Compute the exponential of `x`.
  1435. *
  1436. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  1437. * natural logarithm. The inverse is the natural logarithm, SDL_log.
  1438. *
  1439. * Domain: `-INF <= x <= INF`
  1440. *
  1441. * Range: `0 <= y <= INF`
  1442. *
  1443. * The output will overflow if `exp(x)` is too large to be represented.
  1444. *
  1445. * This function operates on double-precision floating point values, use
  1446. * SDL_expf for single-precision floats.
  1447. *
  1448. * This function may use a different approximation across different versions,
  1449. * platforms and configurations. i.e, it can return a different value given
  1450. * the same input on different machines or operating systems, or if SDL is
  1451. * updated.
  1452. *
  1453. * \param x floating point value
  1454. * \returns value of `e^x`
  1455. *
  1456. * \since This function is available since SDL 3.0.0.
  1457. *
  1458. * \sa SDL_expf
  1459. * \sa SDL_log
  1460. */
  1461. extern DECLSPEC double SDLCALL SDL_exp(double x);
  1462. /**
  1463. * Compute the exponential of `x`.
  1464. *
  1465. * The definition of `y = exp(x)` is `y = e^x`, where `e` is the base of the
  1466. * natural logarithm. The inverse is the natural logarithm, SDL_logf.
  1467. *
  1468. * Domain: `-INF <= x <= INF`
  1469. *
  1470. * Range: `0 <= y <= INF`
  1471. *
  1472. * The output will overflow if `exp(x)` is too large to be represented.
  1473. *
  1474. * This function operates on single-precision floating point values, use
  1475. * SDL_exp for double-precision floats.
  1476. *
  1477. * This function may use a different approximation across different versions,
  1478. * platforms and configurations. i.e, it can return a different value given
  1479. * the same input on different machines or operating systems, or if SDL is
  1480. * updated.
  1481. *
  1482. * \param x floating point value
  1483. * \returns value of `e^x`
  1484. *
  1485. * \since This function is available since SDL 3.0.0.
  1486. *
  1487. * \sa SDL_exp
  1488. * \sa SDL_logf
  1489. */
  1490. extern DECLSPEC float SDLCALL SDL_expf(float x);
  1491. /**
  1492. * Compute the absolute value of `x`
  1493. *
  1494. * Domain: `-INF <= x <= INF`
  1495. *
  1496. * Range: `0 <= y <= INF`
  1497. *
  1498. * This function operates on double-precision floating point values, use
  1499. * SDL_copysignf for single-precision floats.
  1500. *
  1501. * \param x floating point value to use as the magnitude
  1502. * \returns the absolute value of `x`
  1503. *
  1504. * \since This function is available since SDL 3.0.0.
  1505. *
  1506. * \sa SDL_fabsf
  1507. */
  1508. extern DECLSPEC double SDLCALL SDL_fabs(double x);
  1509. /**
  1510. * Compute the absolute value of `x`
  1511. *
  1512. * Domain: `-INF <= x <= INF`
  1513. *
  1514. * Range: `0 <= y <= INF`
  1515. *
  1516. * This function operates on single-precision floating point values, use
  1517. * SDL_copysignf for double-precision floats.
  1518. *
  1519. * \param x floating point value to use as the magnitude
  1520. * \returns the absolute value of `x`
  1521. *
  1522. * \since This function is available since SDL 3.0.0.
  1523. *
  1524. * \sa SDL_fabs
  1525. */
  1526. extern DECLSPEC float SDLCALL SDL_fabsf(float x);
  1527. /**
  1528. * Compute the floor of `x`.
  1529. *
  1530. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  1531. * rounded down to the nearest integer.
  1532. *
  1533. * Domain: `-INF <= x <= INF`
  1534. *
  1535. * Range: `-INF <= y <= INF`, y integer
  1536. *
  1537. * This function operates on double-precision floating point values, use
  1538. * SDL_floorf for single-precision floats.
  1539. *
  1540. * \param x floating point value
  1541. * \returns the floor of `x`
  1542. *
  1543. * \since This function is available since SDL 3.0.0.
  1544. *
  1545. * \sa SDL_floorf
  1546. * \sa SDL_ceil
  1547. * \sa SDL_trunc
  1548. * \sa SDL_round
  1549. * \sa SDL_lround
  1550. */
  1551. extern DECLSPEC double SDLCALL SDL_floor(double x);
  1552. /**
  1553. * Compute the floor of `x`.
  1554. *
  1555. * The floor of `x` is the largest integer `y` such that `y > x`, i.e `x`
  1556. * rounded down to the nearest integer.
  1557. *
  1558. * Domain: `-INF <= x <= INF`
  1559. *
  1560. * Range: `-INF <= y <= INF`, y integer
  1561. *
  1562. * This function operates on single-precision floating point values, use
  1563. * SDL_floorf for double-precision floats.
  1564. *
  1565. * \param x floating point value
  1566. * \returns the floor of `x`
  1567. *
  1568. * \since This function is available since SDL 3.0.0.
  1569. *
  1570. * \sa SDL_floor
  1571. * \sa SDL_ceilf
  1572. * \sa SDL_truncf
  1573. * \sa SDL_roundf
  1574. * \sa SDL_lroundf
  1575. */
  1576. extern DECLSPEC float SDLCALL SDL_floorf(float x);
  1577. /**
  1578. * Truncate `x` to an integer.
  1579. *
  1580. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  1581. * the fractional part of `x`, leaving only the integer part.
  1582. *
  1583. * Domain: `-INF <= x <= INF`
  1584. *
  1585. * Range: `-INF <= y <= INF`, y integer
  1586. *
  1587. * This function operates on double-precision floating point values, use
  1588. * SDL_truncf for single-precision floats.
  1589. *
  1590. * \param x floating point value
  1591. * \returns `x` truncated to an integer
  1592. *
  1593. * \since This function is available since SDL 3.0.0.
  1594. *
  1595. * \sa SDL_truncf
  1596. * \sa SDL_fmod
  1597. * \sa SDL_ceil
  1598. * \sa SDL_floor
  1599. * \sa SDL_round
  1600. * \sa SDL_lround
  1601. */
  1602. extern DECLSPEC double SDLCALL SDL_trunc(double x);
  1603. /**
  1604. * Truncate `x` to an integer.
  1605. *
  1606. * Rounds `x` to the next closest integer to 0. This is equivalent to removing
  1607. * the fractional part of `x`, leaving only the integer part.
  1608. *
  1609. * Domain: `-INF <= x <= INF`
  1610. *
  1611. * Range: `-INF <= y <= INF`, y integer
  1612. *
  1613. * This function operates on single-precision floating point values, use
  1614. * SDL_truncf for double-precision floats.
  1615. *
  1616. * \param x floating point value
  1617. * \returns `x` truncated to an integer
  1618. *
  1619. * \since This function is available since SDL 3.0.0.
  1620. *
  1621. * \sa SDL_trunc
  1622. * \sa SDL_fmodf
  1623. * \sa SDL_ceilf
  1624. * \sa SDL_floorf
  1625. * \sa SDL_roundf
  1626. * \sa SDL_lroundf
  1627. */
  1628. extern DECLSPEC float SDLCALL SDL_truncf(float x);
  1629. /**
  1630. * Return the floating-point remainder of `x / y`
  1631. *
  1632. * Divides `x` by `y`, and returns the remainder.
  1633. *
  1634. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  1635. *
  1636. * Range: `-y <= z <= y`
  1637. *
  1638. * This function operates on double-precision floating point values, use
  1639. * SDL_fmodf for single-precision floats.
  1640. *
  1641. * \param x the numerator
  1642. * \param y the denominator. Must not be 0.
  1643. * \returns the remainder of `x / y`
  1644. *
  1645. * \since This function is available since SDL 3.0.0.
  1646. *
  1647. * \sa SDL_fmodf
  1648. * \sa SDL_modf
  1649. * \sa SDL_trunc
  1650. * \sa SDL_ceil
  1651. * \sa SDL_floor
  1652. * \sa SDL_round
  1653. * \sa SDL_lround
  1654. */
  1655. extern DECLSPEC double SDLCALL SDL_fmod(double x, double y);
  1656. /**
  1657. * Return the floating-point remainder of `x / y`
  1658. *
  1659. * Divides `x` by `y`, and returns the remainder.
  1660. *
  1661. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`, `y != 0`
  1662. *
  1663. * Range: `-y <= z <= y`
  1664. *
  1665. * This function operates on single-precision floating point values, use
  1666. * SDL_fmod for single-precision floats.
  1667. *
  1668. * \param x the numerator
  1669. * \param y the denominator. Must not be 0.
  1670. * \returns the remainder of `x / y`
  1671. *
  1672. * \since This function is available since SDL 3.0.0.
  1673. *
  1674. * \sa SDL_fmod
  1675. * \sa SDL_truncf
  1676. * \sa SDL_modff
  1677. * \sa SDL_ceilf
  1678. * \sa SDL_floorf
  1679. * \sa SDL_roundf
  1680. * \sa SDL_lroundf
  1681. */
  1682. extern DECLSPEC float SDLCALL SDL_fmodf(float x, float y);
  1683. /**
  1684. * Compute the natural logarithm of `x`.
  1685. *
  1686. * Domain: `0 < x <= INF`
  1687. *
  1688. * Range: `-INF <= y <= INF`
  1689. *
  1690. * It is an error for `x` to be less than or equal to 0.
  1691. *
  1692. * This function operates on double-precision floating point values, use
  1693. * SDL_logf for single-precision floats.
  1694. *
  1695. * This function may use a different approximation across different versions,
  1696. * platforms and configurations. i.e, it can return a different value given
  1697. * the same input on different machines or operating systems, or if SDL is
  1698. * updated.
  1699. *
  1700. * \param x floating point value. Must be greater than 0.
  1701. * \returns the natural logarithm of `x`
  1702. *
  1703. * \since This function is available since SDL 3.0.0.
  1704. *
  1705. * \sa SDL_logf
  1706. * \sa SDL_log10
  1707. * \sa SDL_exp
  1708. */
  1709. extern DECLSPEC double SDLCALL SDL_log(double x);
  1710. /**
  1711. * Compute the natural logarithm of `x`.
  1712. *
  1713. * Domain: `0 < x <= INF`
  1714. *
  1715. * Range: `-INF <= y <= INF`
  1716. *
  1717. * It is an error for `x` to be less than or equal to 0.
  1718. *
  1719. * This function operates on single-precision floating point values, use
  1720. * SDL_log for double-precision floats.
  1721. *
  1722. * This function may use a different approximation across different versions,
  1723. * platforms and configurations. i.e, it can return a different value given
  1724. * the same input on different machines or operating systems, or if SDL is
  1725. * updated.
  1726. *
  1727. * \param x floating point value. Must be greater than 0.
  1728. * \returns the natural logarithm of `x`
  1729. *
  1730. * \since This function is available since SDL 3.0.0.
  1731. *
  1732. * \sa SDL_log
  1733. * \sa SDL_expf
  1734. */
  1735. extern DECLSPEC float SDLCALL SDL_logf(float x);
  1736. /**
  1737. * Compute the base-10 logarithm of `x`.
  1738. *
  1739. * Domain: `0 < x <= INF`
  1740. *
  1741. * Range: `-INF <= y <= INF`
  1742. *
  1743. * It is an error for `x` to be less than or equal to 0.
  1744. *
  1745. * This function operates on double-precision floating point values, use
  1746. * SDL_log10f for single-precision floats.
  1747. *
  1748. * This function may use a different approximation across different versions,
  1749. * platforms and configurations. i.e, it can return a different value given
  1750. * the same input on different machines or operating systems, or if SDL is
  1751. * updated.
  1752. *
  1753. * \param x floating point value. Must be greater than 0.
  1754. * \returns the logarithm of `x`
  1755. *
  1756. * \since This function is available since SDL 3.0.0.
  1757. *
  1758. * \sa SDL_log10f
  1759. * \sa SDL_log
  1760. * \sa SDL_pow
  1761. */
  1762. extern DECLSPEC double SDLCALL SDL_log10(double x);
  1763. /**
  1764. * Compute the base-10 logarithm of `x`.
  1765. *
  1766. * Domain: `0 < x <= INF`
  1767. *
  1768. * Range: `-INF <= y <= INF`
  1769. *
  1770. * It is an error for `x` to be less than or equal to 0.
  1771. *
  1772. * This function operates on single-precision floating point values, use
  1773. * SDL_log10 for double-precision floats.
  1774. *
  1775. * This function may use a different approximation across different versions,
  1776. * platforms and configurations. i.e, it can return a different value given
  1777. * the same input on different machines or operating systems, or if SDL is
  1778. * updated.
  1779. *
  1780. * \param x floating point value. Must be greater than 0.
  1781. * \returns the logarithm of `x`
  1782. *
  1783. * \since This function is available since SDL 3.0.0.
  1784. *
  1785. * \sa SDL_log10
  1786. * \sa SDL_logf
  1787. * \sa SDL_powf
  1788. */
  1789. extern DECLSPEC float SDLCALL SDL_log10f(float x);
  1790. /**
  1791. * Split `x` into integer and fractional parts
  1792. *
  1793. * This function operates on double-precision floating point values, use
  1794. * SDL_modff for single-precision floats.
  1795. *
  1796. * \param x floating point value
  1797. * \param y output pointer to store the integer part of `x`
  1798. * \returns the fractional part of `x`
  1799. *
  1800. * \since This function is available since SDL 3.0.0.
  1801. *
  1802. * \sa SDL_modff
  1803. * \sa SDL_trunc
  1804. * \sa SDL_fmod
  1805. */
  1806. extern DECLSPEC double SDLCALL SDL_modf(double x, double *y);
  1807. /**
  1808. * Split `x` into integer and fractional parts
  1809. *
  1810. * This function operates on single-precision floating point values, use
  1811. * SDL_modf for double-precision floats.
  1812. *
  1813. * \param x floating point value
  1814. * \param y output pointer to store the integer part of `x`
  1815. * \returns the fractional part of `x`
  1816. *
  1817. * \since This function is available since SDL 3.0.0.
  1818. *
  1819. * \sa SDL_modf
  1820. * \sa SDL_truncf
  1821. * \sa SDL_fmodf
  1822. */
  1823. extern DECLSPEC float SDLCALL SDL_modff(float x, float *y);
  1824. /**
  1825. * Raise `x` to the power `y`
  1826. *
  1827. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  1828. *
  1829. * Range: `-INF <= z <= INF`
  1830. *
  1831. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  1832. * instead.
  1833. *
  1834. * This function operates on double-precision floating point values, use
  1835. * SDL_powf for single-precision floats.
  1836. *
  1837. * This function may use a different approximation across different versions,
  1838. * platforms and configurations. i.e, it can return a different value given
  1839. * the same input on different machines or operating systems, or if SDL is
  1840. * updated.
  1841. *
  1842. * \param x the base
  1843. * \param y the exponent
  1844. * \returns `x` raised to the power `y`
  1845. *
  1846. * \since This function is available since SDL 3.0.0.
  1847. *
  1848. * \sa SDL_powf
  1849. * \sa SDL_exp
  1850. * \sa SDL_log
  1851. */
  1852. extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
  1853. /**
  1854. * Raise `x` to the power `y`
  1855. *
  1856. * Domain: `-INF <= x <= INF`, `-INF <= y <= INF`
  1857. *
  1858. * Range: `-INF <= z <= INF`
  1859. *
  1860. * If `y` is the base of the natural logarithm (e), consider using SDL_exp
  1861. * instead.
  1862. *
  1863. * This function operates on single-precision floating point values, use
  1864. * SDL_powf for double-precision floats.
  1865. *
  1866. * This function may use a different approximation across different versions,
  1867. * platforms and configurations. i.e, it can return a different value given
  1868. * the same input on different machines or operating systems, or if SDL is
  1869. * updated.
  1870. *
  1871. * \param x the base
  1872. * \param y the exponent
  1873. * \returns `x` raised to the power `y`
  1874. *
  1875. * \since This function is available since SDL 3.0.0.
  1876. *
  1877. * \sa SDL_pow
  1878. * \sa SDL_expf
  1879. * \sa SDL_logf
  1880. */
  1881. extern DECLSPEC float SDLCALL SDL_powf(float x, float y);
  1882. /**
  1883. * Round `x` to the nearest integer.
  1884. *
  1885. * Rounds `x` to the nearest integer. Values halfway between integers will be
  1886. * rounded away from zero.
  1887. *
  1888. * Domain: `-INF <= x <= INF`
  1889. *
  1890. * Range: `-INF <= y <= INF`, y integer
  1891. *
  1892. * This function operates on double-precision floating point values, use
  1893. * SDL_roundf for single-precision floats. To get the result as an integer
  1894. * type, use SDL_lround.
  1895. *
  1896. * \param x floating point value
  1897. * \returns the nearest integer to `x`
  1898. *
  1899. * \since This function is available since SDL 3.0.0.
  1900. *
  1901. * \sa SDL_roundf
  1902. * \sa SDL_lround
  1903. * \sa SDL_floor
  1904. * \sa SDL_ceil
  1905. * \sa SDL_trunc
  1906. */
  1907. extern DECLSPEC double SDLCALL SDL_round(double x);
  1908. /**
  1909. * Round `x` to the nearest integer.
  1910. *
  1911. * Rounds `x` to the nearest integer. Values halfway between integers will be
  1912. * rounded away from zero.
  1913. *
  1914. * Domain: `-INF <= x <= INF`
  1915. *
  1916. * Range: `-INF <= y <= INF`, y integer
  1917. *
  1918. * This function operates on double-precision floating point values, use
  1919. * SDL_roundf for single-precision floats. To get the result as an integer
  1920. * type, use SDL_lroundf.
  1921. *
  1922. * \param x floating point value
  1923. * \returns the nearest integer to `x`
  1924. *
  1925. * \since This function is available since SDL 3.0.0.
  1926. *
  1927. * \sa SDL_round
  1928. * \sa SDL_lroundf
  1929. * \sa SDL_floorf
  1930. * \sa SDL_ceilf
  1931. * \sa SDL_truncf
  1932. */
  1933. extern DECLSPEC float SDLCALL SDL_roundf(float x);
  1934. /**
  1935. * Round `x` to the nearest integer representable as a long
  1936. *
  1937. * Rounds `x` to the nearest integer. Values halfway between integers will be
  1938. * rounded away from zero.
  1939. *
  1940. * Domain: `-INF <= x <= INF`
  1941. *
  1942. * Range: `MIN_LONG <= y <= MAX_LONG`
  1943. *
  1944. * This function operates on double-precision floating point values, use
  1945. * SDL_lround for single-precision floats. To get the result as a
  1946. * floating-point type, use SDL_round.
  1947. *
  1948. * \param x floating point value
  1949. * \returns the nearest integer to `x`
  1950. *
  1951. * \since This function is available since SDL 3.0.0.
  1952. *
  1953. * \sa SDL_lroundf
  1954. * \sa SDL_round
  1955. * \sa SDL_floor
  1956. * \sa SDL_ceil
  1957. * \sa SDL_trunc
  1958. */
  1959. extern DECLSPEC long SDLCALL SDL_lround(double x);
  1960. /**
  1961. * Round `x` to the nearest integer representable as a long
  1962. *
  1963. * Rounds `x` to the nearest integer. Values halfway between integers will be
  1964. * rounded away from zero.
  1965. *
  1966. * Domain: `-INF <= x <= INF`
  1967. *
  1968. * Range: `MIN_LONG <= y <= MAX_LONG`
  1969. *
  1970. * This function operates on single-precision floating point values, use
  1971. * SDL_lroundf for double-precision floats. To get the result as a
  1972. * floating-point type, use SDL_roundf,
  1973. *
  1974. * \param x floating point value
  1975. * \returns the nearest integer to `x`
  1976. *
  1977. * \since This function is available since SDL 3.0.0.
  1978. *
  1979. * \sa SDL_lround
  1980. * \sa SDL_roundf
  1981. * \sa SDL_floorf
  1982. * \sa SDL_ceilf
  1983. * \sa SDL_truncf
  1984. */
  1985. extern DECLSPEC long SDLCALL SDL_lroundf(float x);
  1986. /**
  1987. * Scale `x` by an integer power of two.
  1988. *
  1989. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  1990. *
  1991. * Domain: `-INF <= x <= INF`, `n` integer
  1992. *
  1993. * Range: `-INF <= y <= INF`
  1994. *
  1995. * This function operates on double-precision floating point values, use
  1996. * SDL_scalbnf for single-precision floats.
  1997. *
  1998. * \param x floating point value to be scaled
  1999. * \param n integer exponent
  2000. * \returns `x * 2^n`
  2001. *
  2002. * \since This function is available since SDL 3.0.0.
  2003. *
  2004. * \sa SDL_scalbnf
  2005. * \sa SDL_pow
  2006. */
  2007. extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
  2008. /**
  2009. * Scale `x` by an integer power of two.
  2010. *
  2011. * Multiplies `x` by the `n`th power of the floating point radix (always 2).
  2012. *
  2013. * Domain: `-INF <= x <= INF`, `n` integer
  2014. *
  2015. * Range: `-INF <= y <= INF`
  2016. *
  2017. * This function operates on single-precision floating point values, use
  2018. * SDL_scalbn for double-precision floats.
  2019. *
  2020. * \param x floating point value to be scaled
  2021. * \param n integer exponent
  2022. * \returns `x * 2^n`
  2023. *
  2024. * \since This function is available since SDL 3.0.0.
  2025. *
  2026. * \sa SDL_scalbn
  2027. * \sa SDL_powf
  2028. */
  2029. extern DECLSPEC float SDLCALL SDL_scalbnf(float x, int n);
  2030. /**
  2031. * Compute the sine of `x`.
  2032. *
  2033. * Domain: `-INF <= x <= INF`
  2034. *
  2035. * Range: `-1 <= y <= 1`
  2036. *
  2037. * This function operates on double-precision floating point values, use
  2038. * SDL_sinf for single-precision floats.
  2039. *
  2040. * This function may use a different approximation across different versions,
  2041. * platforms and configurations. i.e, it can return a different value given
  2042. * the same input on different machines or operating systems, or if SDL is
  2043. * updated.
  2044. *
  2045. * \param x floating point value, in radians
  2046. * \returns sine of `x`
  2047. *
  2048. * \since This function is available since SDL 3.0.0.
  2049. *
  2050. * \sa SDL_sinf
  2051. * \sa SDL_asin
  2052. * \sa SDL_cos
  2053. */
  2054. extern DECLSPEC double SDLCALL SDL_sin(double x);
  2055. /**
  2056. * Compute the sine of `x`.
  2057. *
  2058. * Domain: `-INF <= x <= INF`
  2059. *
  2060. * Range: `-1 <= y <= 1`
  2061. *
  2062. * This function operates on single-precision floating point values, use
  2063. * SDL_sinf for double-precision floats.
  2064. *
  2065. * This function may use a different approximation across different versions,
  2066. * platforms and configurations. i.e, it can return a different value given
  2067. * the same input on different machines or operating systems, or if SDL is
  2068. * updated.
  2069. *
  2070. * \param x floating point value, in radians
  2071. * \returns sine of `x`
  2072. *
  2073. * \since This function is available since SDL 3.0.0.
  2074. *
  2075. * \sa SDL_sin
  2076. * \sa SDL_asinf
  2077. * \sa SDL_cosf
  2078. */
  2079. extern DECLSPEC float SDLCALL SDL_sinf(float x);
  2080. /**
  2081. * Compute the square root of `x`.
  2082. *
  2083. * Domain: `0 <= x <= INF`
  2084. *
  2085. * Range: `0 <= y <= INF`
  2086. *
  2087. * This function operates on double-precision floating point values, use
  2088. * SDL_sqrtf for single-precision floats.
  2089. *
  2090. * This function may use a different approximation across different versions,
  2091. * platforms and configurations. i.e, it can return a different value given
  2092. * the same input on different machines or operating systems, or if SDL is
  2093. * updated.
  2094. *
  2095. * \param x floating point value. Must be greater than or equal to 0.
  2096. * \returns square root of `x`
  2097. *
  2098. * \since This function is available since SDL 3.0.0.
  2099. *
  2100. * \sa SDL_sqrtf
  2101. */
  2102. extern DECLSPEC double SDLCALL SDL_sqrt(double x);
  2103. /**
  2104. * Compute the square root of `x`.
  2105. *
  2106. * Domain: `0 <= x <= INF`
  2107. *
  2108. * Range: `0 <= y <= INF`
  2109. *
  2110. * This function operates on single-precision floating point values, use
  2111. * SDL_sqrt for double-precision floats.
  2112. *
  2113. * This function may use a different approximation across different versions,
  2114. * platforms and configurations. i.e, it can return a different value given
  2115. * the same input on different machines or operating systems, or if SDL is
  2116. * updated.
  2117. *
  2118. * \param x floating point value. Must be greater than or equal to 0.
  2119. * \returns square root of `x`
  2120. *
  2121. * \since This function is available since SDL 3.0.0.
  2122. *
  2123. * \sa SDL_sqrt
  2124. */
  2125. extern DECLSPEC float SDLCALL SDL_sqrtf(float x);
  2126. /**
  2127. * Compute the tangent of `x`.
  2128. *
  2129. * Domain: `-INF <= x <= INF`
  2130. *
  2131. * Range: `-INF <= y <= INF`
  2132. *
  2133. * This function operates on double-precision floating point values, use
  2134. * SDL_tanf for single-precision floats.
  2135. *
  2136. * This function may use a different approximation across different versions,
  2137. * platforms and configurations. i.e, it can return a different value given
  2138. * the same input on different machines or operating systems, or if SDL is
  2139. * updated.
  2140. *
  2141. * \param x floating point value, in radians
  2142. * \returns tangent of `x`
  2143. *
  2144. * \since This function is available since SDL 3.0.0.
  2145. *
  2146. * \sa SDL_tanf
  2147. * \sa SDL_sin
  2148. * \sa SDL_cos
  2149. * \sa SDL_atan
  2150. * \sa SDL_atan2
  2151. */
  2152. extern DECLSPEC double SDLCALL SDL_tan(double x);
  2153. /**
  2154. * Compute the tangent of `x`.
  2155. *
  2156. * Domain: `-INF <= x <= INF`
  2157. *
  2158. * Range: `-INF <= y <= INF`
  2159. *
  2160. * This function operates on single-precision floating point values, use
  2161. * SDL_tanf for double-precision floats.
  2162. *
  2163. * This function may use a different approximation across different versions,
  2164. * platforms and configurations. i.e, it can return a different value given
  2165. * the same input on different machines or operating systems, or if SDL is
  2166. * updated.
  2167. *
  2168. * \param x floating point value, in radians
  2169. * \returns tangent of `x`
  2170. *
  2171. * \since This function is available since SDL 3.0.0.
  2172. *
  2173. * \sa SDL_tan
  2174. * \sa SDL_sinf
  2175. * \sa SDL_cosf
  2176. * \sa SDL_atanf
  2177. * \sa SDL_atan2f
  2178. */
  2179. extern DECLSPEC float SDLCALL SDL_tanf(float x);
  2180. /* The SDL implementation of iconv() returns these error codes */
  2181. #define SDL_ICONV_ERROR (size_t)-1
  2182. #define SDL_ICONV_E2BIG (size_t)-2
  2183. #define SDL_ICONV_EILSEQ (size_t)-3
  2184. #define SDL_ICONV_EINVAL (size_t)-4
  2185. /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
  2186. typedef struct SDL_iconv_data_t *SDL_iconv_t;
  2187. extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
  2188. const char *fromcode);
  2189. extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
  2190. extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
  2191. size_t * inbytesleft, char **outbuf,
  2192. size_t * outbytesleft);
  2193. /**
  2194. * This function converts a buffer or string between encodings in one pass,
  2195. * returning a string that must be freed with SDL_free() or NULL on error.
  2196. *
  2197. * \since This function is available since SDL 3.0.0.
  2198. */
  2199. extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
  2200. const char *fromcode,
  2201. const char *inbuf,
  2202. size_t inbytesleft);
  2203. #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
  2204. #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1)
  2205. #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1)
  2206. #define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t))
  2207. /* force builds using Clang's static analysis tools to use literal C runtime
  2208. here, since there are possibly tests that are ineffective otherwise. */
  2209. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  2210. /* The analyzer knows about strlcpy even when the system doesn't provide it */
  2211. #if !defined(HAVE_STRLCPY) && !defined(strlcpy)
  2212. size_t strlcpy(char* dst, const char* src, size_t size);
  2213. #endif
  2214. /* The analyzer knows about strlcat even when the system doesn't provide it */
  2215. #if !defined(HAVE_STRLCAT) && !defined(strlcat)
  2216. size_t strlcat(char* dst, const char* src, size_t size);
  2217. #endif
  2218. #if !defined(HAVE_WCSLCPY) && !defined(wcslcpy)
  2219. size_t wcslcpy(wchar_t *dst, const wchar_t *src, size_t size);
  2220. #endif
  2221. #if !defined(HAVE_WCSLCAT) && !defined(wcslcat)
  2222. size_t wcslcat(wchar_t *dst, const wchar_t *src, size_t size);
  2223. #endif
  2224. /* Starting LLVM 16, the analyser errors out if these functions do not have
  2225. their prototype defined (clang-diagnostic-implicit-function-declaration) */
  2226. #include <stdlib.h>
  2227. #include <stdio.h>
  2228. #define SDL_malloc malloc
  2229. #define SDL_calloc calloc
  2230. #define SDL_realloc realloc
  2231. #define SDL_free free
  2232. #ifndef SDL_memcpy
  2233. #define SDL_memcpy memcpy
  2234. #endif
  2235. #ifndef SDL_memmove
  2236. #define SDL_memmove memmove
  2237. #endif
  2238. #ifndef SDL_memset
  2239. #define SDL_memset memset
  2240. #endif
  2241. #define SDL_memcmp memcmp
  2242. #define SDL_strlcpy strlcpy
  2243. #define SDL_strlcat strlcat
  2244. #define SDL_strlen strlen
  2245. #define SDL_wcslen wcslen
  2246. #define SDL_wcslcpy wcslcpy
  2247. #define SDL_wcslcat wcslcat
  2248. #define SDL_strdup strdup
  2249. #define SDL_wcsdup wcsdup
  2250. #define SDL_strchr strchr
  2251. #define SDL_strrchr strrchr
  2252. #define SDL_strstr strstr
  2253. #define SDL_wcsstr wcsstr
  2254. #define SDL_strtok_r strtok_r
  2255. #define SDL_strcmp strcmp
  2256. #define SDL_wcscmp wcscmp
  2257. #define SDL_strncmp strncmp
  2258. #define SDL_wcsncmp wcsncmp
  2259. #define SDL_strcasecmp strcasecmp
  2260. #define SDL_strncasecmp strncasecmp
  2261. #define SDL_sscanf sscanf
  2262. #define SDL_vsscanf vsscanf
  2263. #define SDL_snprintf snprintf
  2264. #define SDL_vsnprintf vsnprintf
  2265. #endif
  2266. /**
  2267. * If a * b would overflow, return -1. Otherwise store a * b via ret
  2268. * and return 0.
  2269. *
  2270. * \since This function is available since SDL 3.0.0.
  2271. */
  2272. SDL_FORCE_INLINE int SDL_size_mul_overflow (size_t a,
  2273. size_t b,
  2274. size_t *ret)
  2275. {
  2276. if (a != 0 && b > SDL_SIZE_MAX / a) {
  2277. return -1;
  2278. }
  2279. *ret = a * b;
  2280. return 0;
  2281. }
  2282. #if SDL_HAS_BUILTIN(__builtin_mul_overflow)
  2283. /* This needs to be wrapped in an inline rather than being a direct #define,
  2284. * because __builtin_mul_overflow() is type-generic, but we want to be
  2285. * consistent about interpreting a and b as size_t. */
  2286. SDL_FORCE_INLINE int SDL_size_mul_overflow_builtin (size_t a,
  2287. size_t b,
  2288. size_t *ret)
  2289. {
  2290. return __builtin_mul_overflow(a, b, ret) == 0 ? 0 : -1;
  2291. }
  2292. #define SDL_size_mul_overflow(a, b, ret) (SDL_size_mul_overflow_builtin(a, b, ret))
  2293. #endif
  2294. /**
  2295. * If a + b would overflow, return -1. Otherwise store a + b via ret
  2296. * and return 0.
  2297. *
  2298. * \since This function is available since SDL 3.0.0.
  2299. */
  2300. SDL_FORCE_INLINE int SDL_size_add_overflow (size_t a,
  2301. size_t b,
  2302. size_t *ret)
  2303. {
  2304. if (b > SDL_SIZE_MAX - a) {
  2305. return -1;
  2306. }
  2307. *ret = a + b;
  2308. return 0;
  2309. }
  2310. #if SDL_HAS_BUILTIN(__builtin_add_overflow)
  2311. /* This needs to be wrapped in an inline rather than being a direct #define,
  2312. * the same as the call to __builtin_mul_overflow() above. */
  2313. SDL_FORCE_INLINE int SDL_size_add_overflow_builtin (size_t a,
  2314. size_t b,
  2315. size_t *ret)
  2316. {
  2317. return __builtin_add_overflow(a, b, ret) == 0 ? 0 : -1;
  2318. }
  2319. #define SDL_size_add_overflow(a, b, ret) (SDL_size_add_overflow_builtin(a, b, ret))
  2320. #endif
  2321. /* This is a generic function pointer which should be cast to the type you expect */
  2322. #ifdef SDL_FUNCTION_POINTER_IS_VOID_POINTER
  2323. typedef void *SDL_FunctionPointer;
  2324. #else
  2325. typedef void (*SDL_FunctionPointer)(void);
  2326. #endif
  2327. /* Ends C function definitions when using C++ */
  2328. #ifdef __cplusplus
  2329. }
  2330. #endif
  2331. #include <SDL3/SDL_close_code.h>
  2332. #endif /* SDL_stdinc_h_ */