ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1#pragma once
2
24#include <stdint.h>
25#include <stdbool.h>
26#include <stddef.h>
27
28/* ============================================================================
29 * Mathematical Macros
30 * ============================================================================
31 */
32
53#define ROUND(xfloat) (int)(0.5f + (xfloat))
54
55/* ============================================================================
56 * Clamping Functions
57 * ============================================================================
58 */
59
81static inline uint8_t clamp_rgb(int value) {
82 if (value < 0)
83 return 0;
84 if (value > 255)
85 return 255;
86 return (uint8_t)value;
87}
88
89/* ============================================================================
90 * Power-of-Two Utilities
91 * ============================================================================
92 */
93
117static inline bool math_is_power_of_two(size_t n) {
118 return n && !(n & (n - 1));
119}
120
145static inline size_t math_next_power_of_two(size_t n) {
146 if (n == 0)
147 return 1;
148 n--;
149 n |= n >> 1;
150 n |= n >> 2;
151 n |= n >> 4;
152 n |= n >> 8;
153 n |= n >> 16;
154 if (sizeof(size_t) > 4) {
155 n |= n >> 32;
156 }
157 return n + 1;
158}
unsigned char uint8_t
Definition common.h:56