SDL_stdinc.h 81 KB

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