SDL_stdinc.h 85 KB

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