SDL_stdinc.h 81 KB

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