<?php
/*
 * Software Name: Eorisis Pixels
 * Software URI: https://eorisis.com/shop/software/joomla/pixels
 * Author: Eorisis
 * Author URI: https://eorisis.com
 * Copyright: Copyright (C) 2011-2025 EORISIS. All Rights Reserved.
 * License: GNU General Public License version 2; See https://eorisis.com/gpl
 * Terms of Service: https://eorisis.com/tos
 */
namespace com_eorisis_pixels\framework\lib\core\model;
\defined('_JEXEC') or die;
\defined('EORISIS_MBSTRING') or \define('EORISIS_MBSTRING', \extension_loaded('mbstring'));

class math
{
	public function __construct() {}

	// --------------------------------------------------

	public static function bin($num, $default = 0)
	{
		if (!\is_numeric($num))
		{
			$num = (int)$num;
		}

		return \in_array($num, [0,1]) ? (int)$num : $default;
	}

	// --------------------------------------------------

	public static function natural_number($num, $default = 1)
	{
		// Natural numbers are the numbers you can count on your hand
		// They start at 1 and go up by 1

		if (!\is_numeric($num))
		{
			return $default;
		}

		return $num > 0 ? (int)$num : $default;
	}

	// --------------------------------------------------

	public static function whole_number($num, $default = 0)
	{
		// Whole numbers are all the natural numbers plus 0

		if (!\is_numeric($num))
		{
			return $default;
		}

		return $num >= 0 ? (int)$num : $default;
	}

	// --------------------------------------------------

	public static function strlen($string) : int
	{
		if (EORISIS_MBSTRING)
		{
			return \mb_strlen((string)$string, 'UTF-8');
		}

		return \strlen((string)$string);
	}
}
