Commit e24bedcf authored by YIxin-Hu's avatar YIxin-Hu
Browse files

Merge branch 'dev' of https://github.com/wildmeshing/fTetWild into dev

parents f172819f da1b0140
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -90,10 +90,10 @@ IF(NOT ${GMP_FOUND})
	MESSAGE(FATAL_ERROR "Cannot find GMP")
ENDIF()

find_package(MPFR)
IF(NOT ${MPFR_FOUND})
	MESSAGE(FATAL_ERROR "Cannot find MPFR")
ENDIF()
# find_package(MPFR)
# IF(NOT ${MPFR_FOUND})
# 	MESSAGE(FATAL_ERROR "Cannot find MPFR")
# ENDIF()

# add_library() can only be called without any source since CMake 3.11 ...
add_library(${PROJECT_NAME} src/Logger.cpp)
@@ -126,7 +126,7 @@ if(FLOAT_TETWILD_USE_FLOAT)
	target_compile_definitions(${PROJECT_NAME} PUBLIC -DFLOAT_TETWILD_USE_FLOAT)
endif()

target_include_directories(${PROJECT_NAME} PUBLIC ${GMP_INCLUDE_DIRS} ${MPFR_INCLUDES})
target_include_directories(${PROJECT_NAME} PUBLIC ${GMP_INCLUDE_DIRS})

target_link_libraries(${PROJECT_NAME}
	PUBLIC
@@ -136,7 +136,7 @@ target_link_libraries(${PROJECT_NAME}
		Threads::Threads
		fast_winding_number
		${GMP_LIBRARIES}
		${MPFR_LIBRARIES}
		# ${MPFR_LIBRARIES}
)
if(FLOAT_TETWILD_ENABLE_TBB)
	target_link_libraries(${PROJECT_NAME} PUBLIC tbb::tbb)
+1 −2
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ set(SOURCES
	FastWindingNumber.cpp

	Rational.h
	Multiprecision.hpp
)

prepend_current_path(SOURCES)

src/external/Multiprecision.hpp

deleted100644 → 0
+0 −182
Original line number Diff line number Diff line
#pragma once

#include <gmp.h>
#include <mpfr.h>
#include <iostream>

namespace floatTetWild
{

class Multiprecision
{
public:
	mpfr_t value;

	static const int prec = 32;
	//https://www.mpfr.org/mpfr-current/mpfr.html#Rounding-Modes
	static const mpfr_rnd_t rnd = MPFR_RNDN;

	int get_sign()
	{
		return mpfr_sgn(value);
	}

	int get_prec_bits()
	{
		return mpfr_get_prec(value);
	}

	Multiprecision()
	{
		mpfr_init2(value, prec);
		mpfr_set_d(value, 0, rnd);
	}

	Multiprecision(double d)
	{
		mpfr_init2(value, prec);
		mpfr_set_d(value, d, rnd);
	}

	Multiprecision(const mpfr_t &v_)
	{
		mpfr_init2(value, mpfr_get_prec(v_));
		mpfr_set(value, v_, rnd);
	}

	Multiprecision(const Multiprecision &other)
	{
		mpfr_init2(value, other.prec);
		mpfr_set(value, other.value, rnd);
	}

	~Multiprecision()
	{
		mpfr_clear(value);
	}

	friend Multiprecision operator+(const Multiprecision &x, const Multiprecision &y)
	{
		Multiprecision r_out;

		mpfr_add(r_out.value, x.value, y.value, rnd);

		return r_out;
	}

	friend Multiprecision operator-(const Multiprecision &x, const Multiprecision &y)
	{
		Multiprecision r_out;

		mpfr_sub(r_out.value, x.value, y.value, rnd);

		return r_out;
	}

	friend Multiprecision operator*(const Multiprecision &x, const Multiprecision &y)
	{
		Multiprecision r_out;

		mpfr_mul(r_out.value, x.value, y.value, rnd);

		return r_out;
	}

	friend Multiprecision operator/(const Multiprecision &x, const Multiprecision &y)
	{
		Multiprecision r_out;

		mpfr_div(r_out.value, x.value, y.value, rnd);

		return r_out;
	}

	Multiprecision &operator=(const Multiprecision &x)
	{
		if (this == &x)
			return *this;

		//mpfr_init2(value, prec);

		mpfr_set(value, x.value, rnd);

		return *this;
	}

	Multiprecision &operator=(const double x)
	{
		//mpfr_init2(value, prec);

		mpfr_set_d(value, x, rnd);

		return *this;
	}

	//> < ==

	friend bool operator<(const Multiprecision &r, const Multiprecision &r1)
	{
		return mpfr_cmp(r.value, r1.value) < 0;
	}

	friend bool operator>(const Multiprecision &r, const Multiprecision &r1)
	{
		return mpfr_cmp(r.value, r1.value) > 0;
	}

	friend bool operator<=(const Multiprecision &r, const Multiprecision &r1)
	{
		return mpfr_cmp(r.value, r1.value) <= 0;
	}

	friend bool operator>=(const Multiprecision &r, const Multiprecision &r1)
	{
		return mpfr_cmp(r.value, r1.value) >= 0;
	}

	friend bool operator==(const Multiprecision &r, const Multiprecision &r1)
	{
		return mpfr_cmp(r.value, r1.value) == 0;
	}

	friend bool operator!=(const Multiprecision &r, const Multiprecision &r1)
	{
		return mpfr_cmp(r.value, r1.value) != 0;
	}

	//to double

	double to_double() const
	{
		return mpfr_get_d(value, rnd);
	}

	//<<

	friend std::ostream &operator<<(std::ostream &os, const Multiprecision &r)
	{
		os << r.to_double();

		return os;
	}

	friend Multiprecision sqrt(const Multiprecision &mp)
	{
		Multiprecision res;

		mpfr_sqrt(res.value, mp.value, rnd);

		return res;
	}

	friend Multiprecision cbrt(const Multiprecision &mp)
	{
		Multiprecision res;

		mpfr_cbrt(res.value, mp.value, rnd);

		return res;
	}
};

} // namespace fastEnvelope