SDL_stdinc.h 81 KB

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