SDL_trunc(3)
π SDL_trunc β the glow-up where your double becomes a whole number π
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, and today's main character is SDL_trunc(3). yes, that's the page you're on. she's short, she's iconic, she's lowkey the reason your math doesn't look a mess. let's get into it π
β¨ NAME β¨
SDL_trunc β Truncate x to an integer. periodt.
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_stdinc.h>
double SDL_trunc(double x);
that's it. one include, one function, no drama. π¦
π DESCRIPTION π
so here's the tea: SDL_trunc rounds x to the next closest integer toward 0. not toward positive infinity, not toward negative infinity β toward zero. it's basically grabbing your number and ripping off the fractional part, leaving just the integer part sitting there looking cute. βοΈβ¨
think of it as the fractional part getting unfollowed. no cap.
Domain: -INF <= x <= INF
Range: -INF <= y <= INF, y integer
and a lil heads up because she's precise like that: this function operates on double-precision floating point values. if you're working with single-precision floats, go use SDL_truncf instead β she's the float-sized sister and she's also slaying. π
π«Ά FUNCTION PARAMETERS π«Ά
xβ floating point value. that's the whole list bestie, she's not complicated π
β RETURN VALUE β
Returns x truncated to an integer. exactly what you asked for, no surprises, no plot twists. π
π§ THREAD SAFETY π§
it is safe to call this function from any thread. yes gorl, ANY thread. go wild, call her from everywhere, she does not care. π₯
π AVAILABILITY π
This function is available since SDL 3.2.0. so if you're on something olderβ¦ babe. upgrade. π
π SEE ALSO π
go give her friends some love too, they're all in the group chat:
reminder bestie: she truncates toward zero, not toward negative infinity. if you wanted floor energy you want SDL_floor. don't mix them up, it's giving undefined-vibes-but-actually-just-wrong-answers π
okay that's the whole page, and that's on Simple Directmedia Layer β SDL 3.4.18 edition, brought to you by the SDL3 FUNCTIONS girlies. mwah, go truncate something responsibly πβ¨π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms