SDL_stdinc.h 81 KB

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