17 #ifndef DISTRHO_UTILS_HPP_INCLUDED
18 #define DISTRHO_UTILS_HPP_INCLUDED
20 #include "src/DistrhoDefines.h"
30 #ifdef DISTRHO_PROPER_CPP11_SUPPORT
36 #if defined(DISTRHO_OS_MAC) && ! defined(CARLA_OS_MAC)
38 inline float fmin(
float __x,
float __y)
39 {
return __builtin_fminf(__x, __y); }
40 inline float fmax(
float __x,
float __y)
41 {
return __builtin_fmaxf(__x, __y); }
42 inline float rint(
float __x)
43 {
return __builtin_rintf(__x); }
44 inline float round(
float __x)
45 {
return __builtin_roundf(__x); }
56 int64_t d_cconst(
const uint8_t a,
const uint8_t b,
const uint8_t c,
const uint8_t d) noexcept
58 return (a << 24) | (b << 16) | (c << 8) | (d << 0);
65 void d_pass() noexcept {}
78 void d_debug(
const char*
const fmt, ...) noexcept
82 ::va_start(args, fmt);
83 std::fprintf(stdout,
"\x1b[30;1m");
84 std::vfprintf(stdout, fmt, args);
85 std::fprintf(stdout,
"\x1b[0m\n");
95 void d_stdout(
const char*
const fmt, ...) noexcept
99 ::va_start(args, fmt);
100 std::vfprintf(stdout, fmt, args);
101 std::fprintf(stdout,
"\n");
110 void d_stderr(
const char*
const fmt, ...) noexcept
114 ::va_start(args, fmt);
115 std::vfprintf(stderr, fmt, args);
116 std::fprintf(stderr,
"\n");
125 void d_stderr2(
const char*
const fmt, ...) noexcept
129 ::va_start(args, fmt);
130 std::fprintf(stderr,
"\x1b[31m");
131 std::vfprintf(stderr, fmt, args);
132 std::fprintf(stderr,
"\x1b[0m\n");
141 void d_safe_assert(
const char*
const assertion,
const char*
const file,
const int line) noexcept
143 d_stderr2(
"assertion failure: \"%s\" in file %s, line %i", assertion, file, line);
150 void d_safe_exception(
const char*
const exception,
const char*
const file,
const int line) noexcept
152 d_stderr2(
"exception caught: \"%s\" in file %s, line %i", exception, file, line);
164 bool d_isEqual(
const T& v1,
const T& v2)
166 return std::abs(v1-v2) < std::numeric_limits<T>::epsilon();
175 bool d_isNotEqual(
const T& v1,
const T& v2)
177 return std::abs(v1-v2) >= std::numeric_limits<T>::epsilon();
185 bool d_isZero(
const T& value)
187 return std::abs(value) < std::numeric_limits<T>::epsilon();
195 bool d_isNotZero(
const T& value)
197 return std::abs(value) >= std::numeric_limits<T>::epsilon();
202 #endif // DISTRHO_UTILS_HPP_INCLUDED