SDL_stdinc.h 85 KB

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