too much changes to describe
This commit is contained in:
271
utils.h
271
utils.h
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <mpfr.h>
|
||||
#include "./mpreal.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
namespace Util {
|
||||
|
||||
@ -35,134 +36,148 @@ public:
|
||||
Vec2d(double x, double y);
|
||||
};
|
||||
|
||||
class BigFloat {
|
||||
//class BigFloat {
|
||||
//public:
|
||||
// uint32_t precision;
|
||||
// mpfr_t val;
|
||||
//
|
||||
// BigFloat(uint32_t prec);
|
||||
// ~BigFloat();
|
||||
// static BigFloat BigFloat_d(double d, uint32_t prec);
|
||||
// static BigFloat abs(const BigFloat &bf);
|
||||
// void setValue(double val);
|
||||
// std::string to_str() const;
|
||||
// BigFloat operator / (const BigFloat &f);
|
||||
//
|
||||
// inline BigFloat operator - (const BigFloat &f) const
|
||||
// {
|
||||
// BigFloat res = BigFloat(f.precision);
|
||||
// mpfr_sub(res.val, this->val, f.val, MPFR_RNDD);
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
//
|
||||
// inline BigFloat operator - (const double d) const
|
||||
// {
|
||||
// // BigFloat bd = BigFloat(this->precision);
|
||||
// // bd.setValue(d);
|
||||
// BigFloat res = BigFloat(this->precision);
|
||||
// mpfr_sub_d(res.val, this->val, d, MPFR_RNDD);
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
//
|
||||
// inline BigFloat operator * (const BigFloat &f) const
|
||||
// {
|
||||
// BigFloat res = BigFloat(f.precision);
|
||||
// mpfr_mul(res.val, this->val, f.val, MPFR_RNDD);
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
//
|
||||
// inline BigFloat operator * (const double d) const
|
||||
// {
|
||||
// // BigFloat bd = BigFloat(this->precision);
|
||||
// // bd.setValue(d);
|
||||
// BigFloat res = BigFloat(this->precision);
|
||||
// mpfr_mul_d(res.val, this->val, d, MPFR_RNDD);
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
//
|
||||
// inline BigFloat operator + (const BigFloat &f) const
|
||||
// {
|
||||
// BigFloat res = BigFloat(f.precision);
|
||||
// mpfr_add(res.val, this->val, f.val, MPFR_RNDD);
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
//
|
||||
// inline BigFloat operator + (const double d) const
|
||||
// {
|
||||
// // BigFloat bd = BigFloat(this->precision);
|
||||
// // bd.setValue(d);
|
||||
// BigFloat res = BigFloat(this->precision);
|
||||
// mpfr_add_d(res.val, this->val, d, MPFR_RNDD);
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
//
|
||||
// bool operator < (const BigFloat &f)
|
||||
// {
|
||||
// if (mpfr_cmp(this->val, f.val) < 0)
|
||||
// return true;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// bool operator > (const BigFloat &f)
|
||||
// {
|
||||
// if (mpfr_cmp(this->val, f.val) > 0)
|
||||
// return true;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// bool operator <= (const BigFloat &f)
|
||||
// {
|
||||
// int v = mpfr_cmp(this->val, f.val);
|
||||
//
|
||||
// if (v < 0 || v == 0)
|
||||
// return true;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// bool operator >= (const BigFloat &f)
|
||||
// {
|
||||
// int v = mpfr_cmp(this->val, f.val);
|
||||
//
|
||||
// if (v > 0 || v == 0)
|
||||
// return true;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// bool operator < (const double d)
|
||||
// {
|
||||
// if (mpfr_cmp_d(this->val, d) < 0)
|
||||
// return true;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// bool operator > (const double d)
|
||||
// {
|
||||
// if (mpfr_cmp_d(this->val, d) > 0)
|
||||
// return true;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// bool operator <= (const double d)
|
||||
// {
|
||||
// int v = mpfr_cmp_d(this->val, d);
|
||||
//
|
||||
// //std::cout << "comp: " << v << std::endl;
|
||||
//
|
||||
// if (v < 0 || v == 0)
|
||||
// return true;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// bool operator >= (const double d)
|
||||
// {
|
||||
// int v = mpfr_cmp_d(this->val, d);
|
||||
//
|
||||
// if (v > 0 || v == 0)
|
||||
// return true;
|
||||
// return false;
|
||||
// }
|
||||
//};
|
||||
|
||||
void init(uint32_t prec);
|
||||
|
||||
class Vec2mp {
|
||||
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) const
|
||||
{
|
||||
BigFloat res = BigFloat(f.precision);
|
||||
mpfr_sub(res.val, this->val, f.val, MPFR_RNDD);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
inline BigFloat operator - (const double d) const
|
||||
{
|
||||
BigFloat res = BigFloat(this->precision);
|
||||
mpfr_sub_d(res.val, this->val, d, MPFR_RNDD);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
inline BigFloat operator * (const BigFloat &f) const
|
||||
{
|
||||
BigFloat res = BigFloat(f.precision);
|
||||
mpfr_mul(res.val, this->val, f.val, MPFR_RNDD);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
inline BigFloat operator * (const double d) const
|
||||
{
|
||||
BigFloat res = BigFloat(this->precision);
|
||||
mpfr_mul_d(res.val, this->val, d, MPFR_RNDD);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
inline BigFloat operator + (const BigFloat &f) const
|
||||
{
|
||||
BigFloat res = BigFloat(f.precision);
|
||||
mpfr_add(res.val, this->val, f.val, MPFR_RNDD);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
inline BigFloat operator + (const double d) const
|
||||
{
|
||||
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);
|
||||
mpfr::mpreal x;
|
||||
mpfr::mpreal y;
|
||||
Vec2mp(mpfr::mpreal x, mpfr::mpreal y);
|
||||
Vec2mp(double x, double y);
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user