/*******************************************************************************
***  This file is part of Pecunia.                                           ***
***                                                                          ***
***  Copyright (C) 2017, 2018, 2019, 2020, 2021, 2023                        ***
***  John Schneiderman <Licencing _AT_ Schneiderman _DOT_ me>                ***
***                                                                          ***
***  This program is free software: you can redistribute it and/or modify it ***
***  under the terms of the GNU Lesser General Public License as published   ***
***  by the Free Software Foundation, either version 3 of the License, or    ***
***  (at your option) any later version.                                     ***
***                                                                          ***
***  This program is distributed in the hope that it will be useful, but     ***
***  WITHOUT ANY WARRANTY; without even the implied warranty of              ***
***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                    ***
***  See the GNU Lesser General Public License for more details.             ***
***                                                                          ***
***  You should have received a copy of the GNU Lesser General Public License***
***  along with this program. If not, see <http://www.gnu.org/licenses/>.    ***
*******************************************************************************/
#ifndef PECUNIA_ROUNDERS_H_
#define PECUNIA_ROUNDERS_H_

#include <cstdint>

#include "MoneyTypes.h"
#include <pecunia_export.h> // cppcheck-suppress missingInclude


namespace pecunia
{
namespace rounders
{
namespace reals
{

/**
 * @breif Performs a rounding operation using the round-half up towards +∞ method.
 *
 * @param[in] number The floating-point number to round.
 * @param[in] digitsLeft The number of digits left after rounding the number to the right of
 * the decimal point.
 *
 * @return The rounded number with the correct number of digits.
 */
PECUNIA_EXPORT FloatingPoint up(const FloatingPoint& number, const std::uint8_t& digitsLeft);
/**
 * @breif Performs a rounding operation using the round-half down towards -∞ method.
 *
 * @param[in] number The floating-point number to round.
 * @param[in] digitsLeft The number of digits left after rounding the number to the right of
 * the decimal point.
 *
 * @return The rounded number with the correct number of digits.
 */
PECUNIA_EXPORT FloatingPoint down(const FloatingPoint& number, const std::uint8_t& digitsLeft);
/**
 * @breif Performs a rounding operation using the round-half towards zero method.
 *
 * @param[in] number The floating-point number to round.
 * @param[in] digitsLeft The number of digits left after rounding the number to the right of
 * the decimal point.
 *
 * @return The rounded number with the correct number of digits.
 */
PECUNIA_EXPORT FloatingPoint towardsZero(
	const FloatingPoint& number,
	const std::uint8_t& digitsLeft
);
/**
 * @breif Performs a rounding operation using the round-half away from zero method.
 *
 * @param[in] number The floating-point number to round.
 * @param[in] digitsLeft The number of digits left after rounding the number to the right of
 * the decimal point.
 *
 * @return The rounded number with the correct number of digits.
 */
PECUNIA_EXPORT FloatingPoint awayZero(const FloatingPoint& number, const std::uint8_t& digitsLeft);
/**
 * @breif Performs a rounding operation using the round-half to even method.
 *
 * @param[in] number The floating-point number to round.
 * @param[in] digitsLeft The number of digits left after rounding the number to the right of
 * the decimal point.
 *
 * @return The rounded number with the correct number of digits.
 */
PECUNIA_EXPORT FloatingPoint even(const FloatingPoint& number, const std::uint8_t& digitsLeft);
/**
 * @breif Performs a rounding operation using the round-half to odd method.
 *
 * @param[in] number The floating-point number to round.
 * @param[in] digitsLeft The number of digits left after rounding the number to the right of
 * the decimal point.
 *
 * @return The rounded number with the correct number of digits.
 */
PECUNIA_EXPORT FloatingPoint odd(const FloatingPoint& number, const std::uint8_t& digitsLeft);

}
namespace currency
{

/**
 * @breif Performs a rounding operation using the round-half up towards +∞ method.
 *
 * @param[in] amount The major and minor units of the currency stored as one.
 * @param[in] minorDigits The number of digits in the minor unit.
 * @param[in] digitsLeft The number of digits left in the minor unit after rounding the number to
 * the right of the decimal point.
 *
 * @return The rounded number with the correct number of digits.
 */
PECUNIA_EXPORT UnitStorage up(
	const UnitStorage& amount,
	const std::uint8_t& minorDigits,
	const std::uint8_t& digitsLeft
);
/**
 * @breif Performs a rounding operation using the round-half to even method.
 *
 * @param[in] amount The major and minor units of the currency stored as one.
 * @param[in] minorDigits The number of digits in the minor unit.
 * @param[in] digitsLeft The number of digits left in the minor unit after rounding the number to
 * the right of the decimal point.
 *
 * @return The rounded number with the correct number of digits.
 */
PECUNIA_EXPORT UnitStorage even(
	const UnitStorage& amount,
	const std::uint8_t& minorDigits,
	const std::uint8_t& digitsLeft
);

}}}

#endif
