1fixadd(3) Allegro manual fixadd(3)
2
3
4
6 fixadd - Safe function to add fixed point numbers clamping overflow.
7 Allegro game programming library.
8
10 #include <allegro.h>
11
12
13 fixed fixadd(fixed x, fixed y);
14
16 Although fixed point numbers can be added with the normal '+' integer
17 operator, that doesn't provide any protection against overflow. If
18 overflow is a problem, you should use this function instead. It is
19 slower than using integer operators, but if an overflow occurs it will
20 set `errno' and clamp the result, rather than just letting it wrap.
21 Example:
22
23 fixed result;
24 /* This will put 5035 into `result'. */
25 result = fixadd(itofix(5000), itofix(35));
26 /* Sets `errno' and puts -32768 into `result'. */
27 result = fixadd(itofix(-31000), itofix(-3000));
28 ASSERT(!errno); /* This will fail. */
29
31 Returns the clamped result of adding `x' to `y', setting `errno' to
32 ERANGE if there was an overflow.
33
34
36 fixsub(3), fixmul(3), fixdiv(3)
37
38
39
40Allegro version 4.2.2 fixadd(3)