SDL_stdinc.h 81 KB

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