From 3f503e883a4d62892c3c6e75505617323d4be2d0 Mon Sep 17 00:00:00 2001 From: gabriel-logan Date: Sat, 30 Mar 2024 01:26:04 -0300 Subject: [PATCH] feat: publish 0.0.16 version stable of lib --- packages/python/.gitignore | 2 + packages/python/LICENSE | 19 ++ packages/python/README.md | 45 +++ packages/python/loganmatic.py | 164 ----------- packages/python/pyproject.toml | 24 ++ .../python/src/loganmatic.egg-info/PKG-INFO | 59 ++++ .../src/loganmatic.egg-info/SOURCES.txt | 9 + .../loganmatic.egg-info/dependency_links.txt | 1 + .../src/loganmatic.egg-info/top_level.txt | 1 + packages/python/src/loganmatic/__init__.py | 264 ++++++++++++++++++ packages/python/testarlib.py | 17 -- packages/python/tests/testarlib.py | 16 ++ 12 files changed, 440 insertions(+), 181 deletions(-) create mode 100644 packages/python/.gitignore create mode 100644 packages/python/LICENSE create mode 100644 packages/python/README.md delete mode 100644 packages/python/loganmatic.py create mode 100644 packages/python/pyproject.toml create mode 100644 packages/python/src/loganmatic.egg-info/PKG-INFO create mode 100644 packages/python/src/loganmatic.egg-info/SOURCES.txt create mode 100644 packages/python/src/loganmatic.egg-info/dependency_links.txt create mode 100644 packages/python/src/loganmatic.egg-info/top_level.txt create mode 100644 packages/python/src/loganmatic/__init__.py delete mode 100644 packages/python/testarlib.py create mode 100644 packages/python/tests/testarlib.py diff --git a/packages/python/.gitignore b/packages/python/.gitignore new file mode 100644 index 0000000..40fdf2f --- /dev/null +++ b/packages/python/.gitignore @@ -0,0 +1,2 @@ +dist/ +comopublicar.txt \ No newline at end of file diff --git a/packages/python/LICENSE b/packages/python/LICENSE new file mode 100644 index 0000000..265cac1 --- /dev/null +++ b/packages/python/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2023 The Python Packaging Authority + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/python/README.md b/packages/python/README.md new file mode 100644 index 0000000..3afbec8 --- /dev/null +++ b/packages/python/README.md @@ -0,0 +1,45 @@ +# Loganmatic + +[![PyPI version](https://badge.fury.io/py/loganmatic.svg)](https://badge.fury.io/py/loganmatic) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![PyPI downloads](https://img.shields.io/pypi/dm/loganmatic.svg?style=flat-square)](https://pypistats.org/packages/loganmatic) + +## Example usage of the Calculator class + +!! PYTHON !! + +## Docs +https://gabriel-logan.github.io/Math_Lib/python + +To use as a PIP package, simply use + +```bash +pip install loganmatic +``` + +Then, you can use it as follows: + +```py +from loganmatic import loganmatic +``` + +## Example usage of the Calculator class + +```py +# Import the Calculator class from the loganmatic module +from loganmatic import loganmatic + +print("Pi value", loganmatic.Pi) +print("Euler value", loganmatic.EulerNumber) +print("Absolute value", loganmatic.absoluteValue(-5)) +print("Factorial", loganmatic.factorial(5)) +print("Square root", loganmatic.squareRoot(25)) +print("Cubic root", loganmatic.cubicRoot(27)) +print("Factors", loganmatic.factor(12)) +print("Sine", loganmatic.sine(0.5)) +print("Cosine", loganmatic.cosine(0.5)) +print("Random number", loganmatic.random_number_between(1, 10)) +print("Root of linear equation", loganmatic.root_of_first_degree(2, 4)) +print("Roots of quadratic equation", loganmatic.root_of_second_degree(1, -3, 2)) + +``` \ No newline at end of file diff --git a/packages/python/loganmatic.py b/packages/python/loganmatic.py deleted file mode 100644 index bf69648..0000000 --- a/packages/python/loganmatic.py +++ /dev/null @@ -1,164 +0,0 @@ -import time - -class Calculadora: - def __init__(self): - def crie_euler_number() -> float: - n: int = 99 - inicio_somatorio: int = 0 - valor_vasio: float = 0 - - for k in range(inicio_somatorio, n + 1): - serie: float = ((1 ** k)) / (self.fatorial(k)) - valor_vasio += serie - return valor_vasio - - self.NumeroEuler: float = crie_euler_number() - - self.Pi: float = 3.1415926535897932384626433832795 - - @classmethod - def modulo(cls, numero: float) -> float: - if numero < 0: - return -numero # Retorna o valor negativo como positivo - else: - return numero # Retorna o valor positivo como é - - - @classmethod - def fatorial(cls, valor_para_calcular: float) -> float: - # Se o valor é zero, o fatorial é 1 - if valor_para_calcular == 0: - return 1 - - resultado: int = 1 - # Itera sobre os números menores ou iguais ao valor para calcular o fatorial - for i in range(1, valor_para_calcular + 1): - resultado *= i - - # Retorna o resultado do fatorial - return resultado - - @classmethod - def raizQuadrada(cls, valor_para_calcular: float) -> float: - return valor_para_calcular ** (1 / 2) - - @classmethod - def raizCubica(cls, valor_para_calcular: float) -> float: - return valor_para_calcular ** (1 / 3) - - @classmethod - def fatorar(cls, valor_para_calcular: int) -> int: - # Se o valor não é um número, retorna uma mensagem de erro - if not isinstance(valor_para_calcular, (int, float)): - return print('Isso não é um número inteiro') - - A = [] - - # Encontra os fatores do número - for y in range(2, int(valor_para_calcular)): - while valor_para_calcular % y == 0: - valor_para_calcular /= y - A.append(y) - - # Se o array está vazio, significa que o número é primo e ele é adicionado ao array - if len(A) == 0: - A.append(int(valor_para_calcular)) - - # Retorna o array com os fatores - return A - - @classmethod - def seno(cls, valor_para_calcular: float) -> float: - # Valor da variável X se tiver - if Calculadora.modulo(valor_para_calcular) > 5 and Calculadora.modulo(valor_para_calcular) <= 30: - n = 100 # Valor An para soma parcial - elif Calculadora.modulo(valor_para_calcular) > 30: - n = 40 # Valor An para soma parcial - else: - n = 200 # Valor An para soma parcial - - inicio_somatorio = 0 # Valor inicial do somatório - valor_vazio = 0 - - for k in range(inicio_somatorio, n + 1): - serie = (((-1) ** k) * (valor_para_calcular ** (2 * k + 1))) / Calculadora.fatorial(2 * k + 1) - valor_vazio += serie # Soma a série de acordo com o valor de n - - if Calculadora.modulo(valor_vazio) < 0.00000001: - return 0 - else: - return valor_vazio # Retorna a soma parcial da série - - @classmethod - def cosseno(cls, valor_para_calcular: float) -> float: - if Calculadora.modulo(valor_para_calcular) > 5.0 and Calculadora.modulo(valor_para_calcular) <= 30.0: - n = 100 # Valor An para soma parcial - elif Calculadora.modulo(valor_para_calcular) > 30: - n = 40 # Valor An para soma parcial - else: - n = 200 # Valor An para soma parcial - - inicioSomatorio = 0 # Valor inicial do somatorio - valorVasio = 0 - for k in range(inicioSomatorio, n+1): - serie = ((-1)**k)*(valor_para_calcular**(2*k))/((Calculadora.fatorial(2*k))) - valorVasio += serie # Soma a serie de acordo com o valor de n - - if Calculadora.modulo(valorVasio) < 0.00000001: - return 0 - else: - return valorVasio # Retorna a soma parcial da serie - - @classmethod - def numero_aleatorio_entre(cls, minimo: float, maximo: float) -> float: - #Obter a data e hora atual em segundos - tempo_em_segundos = int(time.time()) - - # Usar o tempo atual como semente do gerador de números aleatórios - # (o número 2147483647 é o maior número inteiro que pode ser representado com 32 bits) - semente = (tempo_em_segundos * 16807) % 2147483647 - - # Calcular o número aleatório a partir da semente - numero_aleatorio = minimo + (semente % (maximo - minimo + 1)) - - return numero_aleatorio - - - @classmethod - def raiz_de_primeiro_grau(cls, a, b): - numero_a = float(a) - numero_b = float(b) - - if numero_a == 0: - return f"Esta equação é uma constante de valor = {numero_b}" - else: - raiz = -numero_b / numero_a - return raiz - - - @classmethod - def raizDeSegundoGrau(cls, a, b, c): - numeroA = float(a) - numeroB = float(b) - numeroC = float(c) - - if numeroA == 0 and numeroB == 0: - return f"Esta equação é uma constante de valor = {numeroC}" - else: - delta = numeroB**2 - 4*numeroA*numeroC - if delta < 0: - return "Não possui raízes reais" - elif delta == 0: - raiz1 = -numeroB/(2*numeroA) - return [raiz1, "Possui apenas 1 raiz real"] - else: - raiz1 = (-numeroB + Calculadora.raizQuadrada(delta))/(2*numeroA) - raiz2 = (-numeroB - Calculadora.raizQuadrada(delta))/(2*numeroA) - return [raiz1, raiz2] - - - - - -# Cria uma instância da classe Calculadora -start_calculadora: Calculadora = Calculadora() diff --git a/packages/python/pyproject.toml b/packages/python/pyproject.toml new file mode 100644 index 0000000..b831ec6 --- /dev/null +++ b/packages/python/pyproject.toml @@ -0,0 +1,24 @@ +[build-system] +requires = [ + "setuptools>=61" +] +build-backend = "setuptools.build_meta" + +[project] +name = "loganmatic" +version = "0.0.16" +authors = [ + { name="Gabriel Logan" }, +] +description = "Loganmatic package" +readme = "README.md" +requires-python = ">=3.7" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] + +[project.urls] +"Homepage" = "https://github.com/gabriel-logan/Math_Lib/tree/main/packages/python" +"Bug Tracker" = "https://github.com/gabriel-logan/Math_Lib/tree/main/packages/python" diff --git a/packages/python/src/loganmatic.egg-info/PKG-INFO b/packages/python/src/loganmatic.egg-info/PKG-INFO new file mode 100644 index 0000000..6a54796 --- /dev/null +++ b/packages/python/src/loganmatic.egg-info/PKG-INFO @@ -0,0 +1,59 @@ +Metadata-Version: 2.1 +Name: loganmatic +Version: 0.0.16 +Summary: Loganmatic package +Author: Gabriel Logan +Project-URL: Homepage, https://github.com/gabriel-logan/Math_Lib/tree/main/packages/python +Project-URL: Bug Tracker, https://github.com/gabriel-logan/Math_Lib/tree/main/packages/python +Classifier: Programming Language :: Python :: 3 +Classifier: License :: OSI Approved :: MIT License +Classifier: Operating System :: OS Independent +Requires-Python: >=3.7 +Description-Content-Type: text/markdown +License-File: LICENSE + +# Loganmatic + +[![PyPI version](https://badge.fury.io/py/loganmatic.svg)](https://badge.fury.io/py/loganmatic) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![PyPI downloads](https://img.shields.io/pypi/dm/loganmatic.svg?style=flat-square)](https://pypistats.org/packages/loganmatic) + +## Example usage of the Calculator class + +!! PYTHON !! + +## Docs +https://gabriel-logan.github.io/Math_Lib/python + +To use as a PIP package, simply use + +```bash +pip install loganmatic +``` + +Then, you can use it as follows: + +```py +from loganmatic import loganmatic +``` + +## Example usage of the Calculator class + +```py +# Import the Calculator class from the loganmatic module +from loganmatic import loganmatic + +print("Pi value", loganmatic.Pi) +print("Euler value", loganmatic.EulerNumber) +print("Absolute value", loganmatic.absoluteValue(-5)) +print("Factorial", loganmatic.factorial(5)) +print("Square root", loganmatic.squareRoot(25)) +print("Cubic root", loganmatic.cubicRoot(27)) +print("Factors", loganmatic.factor(12)) +print("Sine", loganmatic.sine(0.5)) +print("Cosine", loganmatic.cosine(0.5)) +print("Random number", loganmatic.random_number_between(1, 10)) +print("Root of linear equation", loganmatic.root_of_first_degree(2, 4)) +print("Roots of quadratic equation", loganmatic.root_of_second_degree(1, -3, 2)) + +``` diff --git a/packages/python/src/loganmatic.egg-info/SOURCES.txt b/packages/python/src/loganmatic.egg-info/SOURCES.txt new file mode 100644 index 0000000..814573d --- /dev/null +++ b/packages/python/src/loganmatic.egg-info/SOURCES.txt @@ -0,0 +1,9 @@ +LICENSE +README.md +pyproject.toml +src/loganmatic/__init__.py +src/loganmatic.egg-info/PKG-INFO +src/loganmatic.egg-info/SOURCES.txt +src/loganmatic.egg-info/dependency_links.txt +src/loganmatic.egg-info/top_level.txt +tests/testarlib.py \ No newline at end of file diff --git a/packages/python/src/loganmatic.egg-info/dependency_links.txt b/packages/python/src/loganmatic.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/packages/python/src/loganmatic.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/packages/python/src/loganmatic.egg-info/top_level.txt b/packages/python/src/loganmatic.egg-info/top_level.txt new file mode 100644 index 0000000..4ae9625 --- /dev/null +++ b/packages/python/src/loganmatic.egg-info/top_level.txt @@ -0,0 +1 @@ +loganmatic diff --git a/packages/python/src/loganmatic/__init__.py b/packages/python/src/loganmatic/__init__.py new file mode 100644 index 0000000..8d442bc --- /dev/null +++ b/packages/python/src/loganmatic/__init__.py @@ -0,0 +1,264 @@ +import time +from decimal import Decimal, getcontext + +class Calculator: + """ + A class that provides various mathematical calculations and constants. + """ + def __init__(self): + """ + Initializes an instance of the Calculator class. + """ + def create_euler_number(): + """ + Helper function to calculate the Euler's number. + """ + n: int = 99 + start_summation: int = 0 + empty_value = 0 + + for k in range(start_summation, n + 1): + series = ((1 ** k)) / (self.factorial(k)) + empty_value += series + return empty_value + + self.EulerNumber = create_euler_number() + + self.Pi = 3.1415926535897932384626433832795 + + @classmethod + def absoluteValue(cls, number): + """ + Returns the absolute value of a number. + + Args: + number (int or float): The number to calculate the absolute value of. + + Returns: + int or float: The absolute value of the number. + """ + if number < 0: + return -number # Returns the negative value as positive + else: + return number # Returns the positive value as is + + + @classmethod + def factorial(cls, value_to_calculate): + """ + Calculates the factorial of a given number. + + Args: + value_to_calculate (int): The number to calculate the factorial of. + + Returns: + int: The factorial of the given number. + """ + # If the value is zero, the factorial is 1 + if value_to_calculate == 0: + return 1 + + result: int = 1 + # Iterates over the numbers less than or equal to the value to calculate the factorial + for i in range(1, value_to_calculate + 1): + result *= i + + # Returns the result of the factorial + return result + + @classmethod + def squareRoot(cls, value_to_calculate): + """ + Calculates the square root of a given number. + + Args: + value_to_calculate (int or float): The number to calculate the square root of. + + Returns: + float: The square root of the given number. + """ + return value_to_calculate ** (1 / 2) + + @classmethod + def cubicRoot(cls, value_to_calculate): + """ + Calculates the cubic root of a given number. + + Args: + value_to_calculate (int or float): The number to calculate the cubic root of. + + Returns: + float: The cubic root of the given number. + """ + return value_to_calculate ** (1 / 3) + + @classmethod + def factor(cls, value_to_calculate: int) -> int: + """ + Finds the factors of a given number. + + Args: + value_to_calculate (int): The number to find the factors of. + + Returns: + list: A list of factors of the given number. + """ + # If the value is not a number, returns an error message + if not isinstance(value_to_calculate, (int, float)): + return print('This is not an integer') + + A = [] + + # Finds the factors of the number + for y in range(2, int(value_to_calculate)): + while value_to_calculate % y == 0: + A.append(y) + value_to_calculate = value_to_calculate / y + if value_to_calculate > 1: + A.append(value_to_calculate) + return A + + @classmethod + def sine(cls, value_to_calculate): + """ + Calculates the sine of a given angle. + + Args: + value_to_calculate (int or float): The angle in radians to calculate the sine of. + + Returns: + float: The sine of the given angle. + """ + getcontext().prec = 100 # Set the precision of Decimal + + if Calculator.absoluteValue(value_to_calculate) > 5 and Calculator.absoluteValue(value_to_calculate) <= 30: + n = 100 # Value An for partial sum + elif Calculator.absoluteValue(value_to_calculate) > 30: + n = 40 # Value An for partial sum + else: + n = 200 # Value An for partial sum + + start_summation = 0 # Initial value of the summation + empty_value = Decimal(0) + + for k in range(start_summation, n + 1): + series = (((-1) ** k) * (Decimal(value_to_calculate) ** (2 * k + 1))) / Calculator.factorial(2 * k + 1) + empty_value += Decimal(series) # Adds the series according to the value of n + + if Calculator.absoluteValue(empty_value) < Decimal(0.00000001): + return 0 + else: + return float(empty_value) # Returns the partial sum of the series + + @classmethod + def cosine(cls, value_to_calculate): + """ + Calculates the cosine of a given angle. + + Args: + value_to_calculate (int or float): The angle in radians to calculate the cosine of. + + Returns: + float: The cosine of the given angle. + """ + getcontext().prec = 100 # Set the precision of Decimal + + if Calculator.absoluteValue(value_to_calculate) > 5.0 and Calculator.absoluteValue(value_to_calculate) <= 30.0: + n = 100 # Value An for partial sum + elif Calculator.absoluteValue(value_to_calculate) > 30: + n = 40 # Value An for partial sum + else: + n = 200 # Value An for partial sum + + start_summation = 0 # Initial value of the summation + empty_value = Decimal(0) + for k in range(start_summation, n+1): + series = ((-1)**k)*(Decimal(value_to_calculate)**(2*k))/((Calculator.factorial(2*k))) + empty_value += Decimal(series) # Adds the series according to the value of n + + if Calculator.absoluteValue(empty_value) < Decimal(0.00000001): + return 0 + else: + return float(empty_value) # Returns the partial sum of the series + + @classmethod + def random_number_between(cls, minimum, maximum): + """ + Generates a random number between the given minimum and maximum values. + + Args: + minimum (int or float): The minimum value of the random number range. + maximum (int or float): The maximum value of the random number range. + + Returns: + int or float: A random number between the given minimum and maximum values. + """ + # Get the current date and time in seconds + current_time_in_seconds = int(time.time()) + + # Use the current time as the seed for the random number generator + # (the number 2147483647 is the largest integer that can be represented with 32 bits) + seed = (current_time_in_seconds * 16807) % 2147483647 + + # Calculate the random number from the seed + random_number = minimum + (seed % (maximum - minimum + 1)) + + return random_number + + + @classmethod + def root_of_first_degree(cls, a, b): + """ + Calculates the root of a linear equation of the form ax + b = 0. + + Args: + a (int or float): The coefficient of x. + b (int or float): The constant term. + + Returns: + tuple: A tuple containing the root of the equation and an error message if applicable. + """ + number_a = float(a) + number_b = float(b) + + if number_a == 0: + return None, "The value of 'a' cannot be zero." + else: + root = -number_b / number_a + return root + + + @classmethod + def root_of_second_degree(cls, a, b, c): + """ + Calculates the roots of a quadratic equation of the form ax^2 + bx + c = 0. + + Args: + a (int or float): The coefficient of x^2. + b (int or float): The coefficient of x. + c (int or float): The constant term. + + Returns: + list: A list containing the roots of the equation and an error message if applicable. + """ + numberA = float(a) + numberB = float(b) + numberC = float(c) + + if numberA == 0 and numberB == 0: + return None, "The values of 'a' and 'b' cannot be zero at the same time." + else: + delta = numberB**2 - 4*numberA*numberC + if delta < 0: + return None, "Has no real roots" + elif delta == 0: + root1 = -numberB/(2*numberA) + return [root1] + else: + root1 = (-numberB + Calculator.squareRoot(delta))/(2*numberA) + root2 = (-numberB - Calculator.squareRoot(delta))/(2*numberA) + return [root1, root2] + + +# Creates an instance of the Calculator class +loganmatic = Calculator() \ No newline at end of file diff --git a/packages/python/testarlib.py b/packages/python/testarlib.py deleted file mode 100644 index 31b056b..0000000 --- a/packages/python/testarlib.py +++ /dev/null @@ -1,17 +0,0 @@ -from loganmatic import Calculadora - -minha_calculadora = Calculadora() -print(minha_calculadora.NumeroEuler) -print(minha_calculadora.fatorar(100)) -print(minha_calculadora.Pi) -print(minha_calculadora.modulo(-4)) -print(minha_calculadora.fatorial(4)) -print(minha_calculadora.raiz_de_primeiro_grau(2, 1)) -print(minha_calculadora.raizDeSegundoGrau(1,2,-3)) -print(minha_calculadora.raizCubica(8)) -print(minha_calculadora.raizQuadrada(9)) -print(minha_calculadora.numero_aleatorio_entre(10, 20)) - -# Essas duas ultimas estão com problema para valores float... -print(minha_calculadora.cosseno(0)) -print(minha_calculadora.seno(0)) diff --git a/packages/python/tests/testarlib.py b/packages/python/tests/testarlib.py new file mode 100644 index 0000000..228a69e --- /dev/null +++ b/packages/python/tests/testarlib.py @@ -0,0 +1,16 @@ +from loganmatic import Calculator + +minha_calculadora = Calculator() +# Execute all methods +print("Absolute Value:", Calculator.absoluteValue(-5)) +print("Factorial:", Calculator.factorial(5)) +print("Square Root:", Calculator.squareRoot(16)) +print("Cubic Root:", Calculator.cubicRoot(27)) +print("Factor:", Calculator.factor(100)) +print("Sine:", Calculator.sine(0.5)) +print("Cosine:", Calculator.cosine(0.5)) +print("Random Number:", Calculator.random_number_between(1, 10)) +print("Root of First Degree:", Calculator.root_of_first_degree(2, 4)) +print("Root of Second Degree:", Calculator.root_of_second_degree(1, -3, 2)) +print("Euler Number:", start_calculator.EulerNumber) +print("Pi:", start_calculator.Pi)