1fixsub(3) Allegro manual fixsub(3)
2
3
4
6 fixsub - Safe function to subtract fixed point numbers clamping under‐
7 flow. Allegro game programming library.
8
10 #include <allegro.h>
11
12
13 fixed fixsub(fixed x, fixed y);
14
16 Although fixed point numbers can be subtracted with the normal '-'
17 integer operator, that doesn't provide any protection against overflow.
18 If 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 4965 into `result'. */
25 result = fixsub(itofix(5000), itofix(35));
26 /* Sets `errno' and puts -32768 into `result'. */
27 result = fixsub(itofix(-31000), itofix(3000));
28 ASSERT(!errno); /* This will fail. */
29
31 Returns the clamped result of subtracting `y' from `x', setting `errno'
32 to ERANGE if there was an overflow.
33
34
36 fixadd(3), fixmul(3), fixdiv(3)
37
38
39
40Allegro version 4.4.3 fixsub(3)