fixadd(3alleg4)
β¨ fixadd β¨
okay bestie, you know how the Allegro manual has a whole page for this one little function? yeah. it's fixadd, and it lives in the 3alleg4 manual, and it's part of the Allegro game programming library. she's small but she's important, fr fr. π
πΈ SYNOPSIS πΈ
#include <allegro.h>
fixed fixadd(fixed x, fixed y);
π DESCRIPTION π
so likeβ¦ fixed point numbers? you can totally just add them with the normal + integer operator. it works. it's fine. it's giving effortless. BUT β and this is the plot twist β that way gives you zero protection against overflow. none. nada. it will just happily wrap around and ruin your whole day. π
so if overflow is actually a problem for you (and lowkey it should be), you should use this function instead. she's slower than using integer operators, yeah, but the tradeoff is she's got your back: if an overflow happens, she sets errno and clamps the result, instead of just letting it wrap. main character energy, honestly. π
example time, because examples ate:
fixed result;
/* This will put 5035 into `result'. */
result = fixadd(itofix(5000), itofix(35));
/* Sets `errno' and puts -32768 into `result'. */
result = fixadd(itofix(-31000), itofix(-3000));
ASSERT(!errno); /* This will fail. */
see that last line? yeah, that ASSERT will fail. not a drill. not a vibe. it's failing. π
π«Ά RETURN VALUE π«Ά
she returns the clamped result of adding x to y β and if there was an overflow, she sets errno to ERANGE. that's it, that's the whole thing. so precious. β
π SEE ALSO π
her sisters, obviously. go give them a read too, they're all iconic:
mwah π that's the whole page. brought to you by the Allegro manual, version 4.4.3 β no cap, that's the version, and that's the whole vibe. go clamp something safely, bestie. π¦
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms