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