// Copyright (c) 2024 Codemongous LLC. All Rights Reserved.

#pragma once

#include <cmath>

using std::fabs;

namespace Sourcify
{

#define SRCFY_SMALL_NUMBER			(1.e-8f)
#define SRCFY_DOUBLE_SMALL_NUMBER	(1.e-8)

	class MathHelpers
	{
		MathHelpers() = delete;

	public:
		[[nodiscard]] static inline bool IsNearlyEqual(double A, double B, double ErrorTolerance = SRCFY_DOUBLE_SMALL_NUMBER)
		{
			return fabs(A - B) <= ErrorTolerance;
		}

		[[nodiscard]] static inline bool IsNearlyEqual(float A, float B, float ErrorTolerance = SRCFY_SMALL_NUMBER)
		{
			return fabs(A - B) <= ErrorTolerance;
		}

		[[nodiscard]] static inline bool IsNearlyZero(double Value, double ErrorTolerance = SRCFY_DOUBLE_SMALL_NUMBER)
		{
			return fabs(Value) <= ErrorTolerance;
		}

		[[nodiscard]] static inline bool IsNearlyZero(float Value, float ErrorTolerance = SRCFY_SMALL_NUMBER)
		{
			return fabs(Value) <= ErrorTolerance;
		}
	};
}