SDL_stdinc.h 80 KB

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