mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-06-12 03:01:58 -04:00
spa: utils: add SPA_MACHINE_USES_TWOS_COMPLEMENT macro
This commit is contained in:
parent
bb90fdf03b
commit
4eed79ee81
1 changed files with 16 additions and 0 deletions
|
|
@ -10,6 +10,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -336,6 +337,21 @@ struct spa_fraction {
|
|||
_n + 1; \
|
||||
})
|
||||
|
||||
/* The vast majority of real world machines use a two's complement method.
|
||||
* However, it is still prudent to check for that instead of just assuming.
|
||||
* Fortunately, it is simple to check for this by negating INT_MAX and
|
||||
* subtracting 1 from that. In two's complement, there is one more negative
|
||||
* integer than there are positive integers (due to two's complement having
|
||||
* only one zero representation), and this check exploits that particular
|
||||
* asymmetry.
|
||||
* It is very important to make sure limits.h is included for this to work,
|
||||
* since otherwise, INT_MIN and INT_MAX will be missing, and this will _not_
|
||||
* cause a preprocessor error - instead, the #if check here silently fails,
|
||||
* as if the machine used something other than a two's complement method. */
|
||||
#if INT_MIN == (-(INT_MAX) - 1)
|
||||
#define SPA_MACHINE_USES_TWOS_COMPLEMENT
|
||||
#endif
|
||||
|
||||
|
||||
#define SPA_PTR_ALIGNMENT(p,align) ((uintptr_t)(p) & ((align)-1))
|
||||
#define SPA_IS_ALIGNED(p,align) (SPA_PTR_ALIGNMENT(p,align) == 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue