mandelbrot/utils.h
2022-07-04 19:22:36 +02:00

169 lines
3.1 KiB
C++

#pragma once
#include <cstdint>
#include <mpfr.h>
#include <string>
namespace Util {
class rgb {
public:
uint8_t r;
uint8_t g;
uint8_t b;
rgb(uint8_t r, uint8_t g, uint8_t b);
};
class Vec2i {
public:
int x;
int y;
Vec2i(int x, int y);
};
class Vec2f {
public:
float x;
float y;
Vec2f(float x, float y);
};
class Vec2d {
public:
double x;
double y;
Vec2d(double x, double y);
};
class BigFloat {
public:
uint32_t precision;
mpfr_t val;
BigFloat(uint32_t prec);
void setValue(double val);
std::string to_str();
BigFloat operator / (const BigFloat &f);
inline BigFloat operator - (const BigFloat &f)
{
BigFloat res = BigFloat(f.precision);
mpfr_sub(res.val, this->val, f.val, MPFR_RNDD);
return res;
}
inline BigFloat operator - (const double d)
{
BigFloat res = BigFloat(this->precision);
mpfr_sub_d(res.val, this->val, d, MPFR_RNDD);
return res;
}
inline BigFloat operator * (const BigFloat &f)
{
BigFloat res = BigFloat(f.precision);
mpfr_mul(res.val, this->val, f.val, MPFR_RNDD);
return res;
}
inline BigFloat operator * (const double d)
{
BigFloat res = BigFloat(this->precision);
mpfr_mul_d(res.val, this->val, d, MPFR_RNDD);
return res;
}
inline BigFloat operator + (const BigFloat &f)
{
BigFloat res = BigFloat(f.precision);
mpfr_add(res.val, this->val, f.val, MPFR_RNDD);
return res;
}
inline BigFloat operator + (const double d)
{
BigFloat res = BigFloat(this->precision);
mpfr_add_d(res.val, this->val, d, MPFR_RNDD);
return res;
}
inline bool operator < (const BigFloat &f)
{
if (mpfr_cmp(this->val, f.val) < 0)
return true;
return false;
}
inline bool operator > (const BigFloat &f)
{
if (mpfr_cmp(this->val, f.val) > 0)
return true;
return false;
}
inline bool operator <= (const BigFloat &f)
{
int v = mpfr_cmp(this->val, f.val);
if (v < 0 || v == 0)
return true;
return false;
}
inline bool operator >= (const BigFloat &f)
{
int v = mpfr_cmp(this->val, f.val);
if (v > 0 || v == 0)
return true;
return false;
}
inline bool operator < (const double d)
{
if (mpfr_cmp_d(this->val, d) < 0)
return true;
return false;
}
inline bool operator > (const double d)
{
if (mpfr_cmp_d(this->val, d) > 0)
return true;
return false;
}
inline bool operator <= (const double d)
{
int v = mpfr_cmp_d(this->val, d);
if (v < 0 || v == 0)
return true;
return false;
}
inline bool operator >= (const double d)
{
int v = mpfr_cmp_d(this->val, d);
if (v > 0 || v == 0)
return true;
return false;
}
};
class Vec2bf {
public:
BigFloat x;
BigFloat y;
Vec2bf(double x, double y, uint32_t prec);
};
}