SDL_stdinc.h 98 KB

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