SDL_roundf(3)

πŸ’– SDL_roundf πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_roundf. she's small, she's single-precision, and she is so good at her one job. let's go πŸ’…

✨ NAME ✨

SDL_roundf β€” round x to the nearest integer. that's it. that's the whole vibe. πŸŽ€


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_stdinc.h>

float SDL_roundf(float x);

like. one include. one function. one float in, one float out. iconic behaviour, no notes 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so what she does is: she rounds x to the nearest integer. and if a value is sitting exactly halfway between two integers? she rounds it away from zero. that's the rule, that's the law, and she does not negotiate πŸ’€

here's the domain and range breakdown, because we love a well-behaved function:

  • Domain: -INF <= x <= INF
  • Range: -INF <= y <= INF, y integer

now listen, this is the single-precision girlie. if you've got a double-precision float and you want it handled, go talk to SDL_round instead. and if what you actually want back is an integer type and not a float, then SDL_lroundf is your bestie. pick the right one, okay? i believe in you πŸ’œ


πŸ“ FUNCTION PARAMETERS πŸ“

  • x β€” a floating point value. that's the whole input. she takes it, she rounds it, she moves on. lowkey efficient ✨

⭐ RETURN VALUE ⭐

Returns the nearest integer to x. as a float, obviously, because that's her whole thing. slay πŸŽ€


🧚 THREAD SAFETY 🧚

you can call her from any thread. any of them. all of them. she's not gonna get weird about it. no cap 🫢


πŸ‘‘ AVAILABILITY πŸ‘‘

this function has been available since SDL 3.2.0. so if you're on something older... bestie, upgrade 😭


🌈 SEE ALSO 🌈

the whole rounded-up (and rounded-down) friend group, fr fr:


lowkey reminder: halfway values round away from zero. not toward. not to-even. away from zero. don't come for me if you forget, i literally just told you πŸ’…

and that's the page, bestie!! this one came to you courtesy of Simple Directmedia Layer, version SDL 3.4.18, filed under SDL_roundf(3) in the SDL3 FUNCTIONS fam. go round some floats, you absolute legend πŸŒΈπŸ’–βœ¨

πŸ“¦ where this page comes from