package_name_to_import_with.calculator_sub_package package#
Subpackages#
Submodules#
- package_name_to_import_with.calculator_sub_package.wrapper_module module
BinaryArithmeticExpressionBinaryArithmeticExpression.left_operandBinaryArithmeticExpression.binary_operatorBinaryArithmeticExpression.right_operandBinaryArithmeticExpression.operationBinaryArithmeticExpression.resultBinaryArithmeticExpression.left_operandBinaryArithmeticExpression.binary_operatorBinaryArithmeticExpression.right_operandBinaryArithmeticExpression.operationBinaryArithmeticExpression.resultBinaryArithmeticExpression.model_computed_fieldsBinaryArithmeticExpression.model_configBinaryArithmeticExpression.model_fields
BinaryArithmeticOperationBinaryArithmeticOperatorcalculate_results
Module contents#
Expose binary operations.
- class BinaryArithmeticExpression(*, left_operand, binary_operator, right_operand)[source]#
Bases:
pydantic.main.BaseModelDefine binary arithmetic expression.
- binary_operator#
arithmetic operator of binary arithmetic expression
- Type:
- operation#
function to perform arithmetic operation corresponding to
self.binary_operator
- binary_operator: package_name_to_import_with.calculator_sub_package.wrapper_module.BinaryArithmeticOperator#
- property operation: collections.abc.Callable[[float, float], float]#
Store implementation of binary arithmetic operation.
- Returns:
implementation of binary arithmetic operation corresponding to
self.binary_operator- Return type:
- property result: float#
Store result of binary arithmetic expression.
- Returns:
result of binary arithmetic expression
- Return type:
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}#
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'binary_operator': FieldInfo(annotation=BinaryArithmeticOperator, required=True), 'left_operand': FieldInfo(annotation=float, required=True), 'right_operand': FieldInfo(annotation=float, required=True)}#
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- BinaryArithmeticOperation#
alias of
collections.abc.Callable[float,float,float]
- class BinaryArithmeticOperator(value)[source]#
-
Define supported arithmetic operators.
- ADDITION = '+'#
- SUBTRACTION = '-'#
- MULTIPLICATION = '*'#
- DIVISION = '/'#
- class IdentityElements(value)[source]#
-
Define assumed identity elements.
- ADDITIVE_IDENTITY = 0.0#
- MULTIPLICATIVE_IDENTITY = 1.0#
- class InverseElements(value)[source]#
-
Define supported inverse elements.
- ADDITIVE_INVERSE = -1.0#
- MULTIPLICATIVE_INVERSE = 1.0#
- add_numbers(left_addend, right_addend)[source]#
Perform addition of two real numbers.
- Parameters:
- Returns:
sum of
left_addendandright_addend- Return type:
Examples
>>> from package_name_to_import_with.calculator_sub_package import add_numbers >>> add_numbers(1, 2) 3.0 >>> add_numbers(1, -2) -1.0 >>> add_numbers(-1, 2) 1.0 >>> add_numbers(-1, -2) -3.0
- calculate_results(first_input, operator, second_input)[source]#
Perform basic binary arithmetic expressions.
- Parameters:
first_input (
float) -- left operand of binary arithmetic expressionoperator (
BinaryArithmeticOperator) -- kind of binary arithmetic expressionsecond_input (
float) -- right operand of binary arithmetic expression
- Returns:
result of binary arithmetic expression
- Return type:
Examples
>>> from package_name_to_import_with import calculate_results >>> calculate_results(1, "+", 2) 3.0 >>> calculate_results(1, "-", 2) -1.0 >>> calculate_results(1, "*", 2) 2.0 >>> calculate_results(1, "/", 2) 0.5
- divide_numbers(dividend, divisor)[source]#
Perform division of two real numbers.
- Parameters:
- Returns:
quotient of
dividendbydivisor- Return type:
Examples
>>> from package_name_to_import_with.calculator_sub_package import divide_numbers >>> divide_numbers(1, 2) 0.5 >>> divide_numbers(1, -2) -0.5 >>> divide_numbers(-1, 2) -0.5 >>> divide_numbers(-1, -2) 0.5
- get_negative(input_number)[source]#
Get additive inverse of a real number.
- Parameters:
input_number (
float) -- number for which additive inverse is required- Returns:
negative of
input_number- Return type:
Examples
>>> from package_name_to_import_with.calculator_sub_package import get_negative >>> get_negative(1) -1.0 >>> get_negative(-1) 1.0
- get_reciprocal(input_number)[source]#
Get multiplicative inverse of a real number.
- Parameters:
input_number (
float) -- number for which multiplicative inverse is required- Returns:
reciprocal of
input_number- Return type:
- Raises:
ValueError -- if
input_numberis additive identity, viz. zero
Examples
>>> from package_name_to_import_with.calculator_sub_package import get_reciprocal >>> get_reciprocal(2) 0.5 >>> get_reciprocal(0.5) 2.0
- multiply_numbers(left_multiplicand, right_multiplicand)[source]#
Perform multiplication of two real numbers.
- Parameters:
- Returns:
product of two
left_multiplicandandright_multiplicand- Return type:
Examples
>>> from package_name_to_import_with.calculator_sub_package import multiply_numbers >>> multiply_numbers(1, 2) 2.0 >>> multiply_numbers(1, -2) -2.0 >>> multiply_numbers(-1, 2) -2.0 >>> multiply_numbers(-1, -2) 2.0
- subtract_numbers(minuend, subtrahend)[source]#
Perform subtraction of two real numbers.
- Parameters:
- Returns:
difference of
minuendfromsubtrahend- Return type:
Examples
>>> from package_name_to_import_with.calculator_sub_package import subtract_numbers >>> subtract_numbers(1, 2) -1.0 >>> subtract_numbers(1, -2) 3.0 >>> subtract_numbers(-1, 2) -3.0 >>> subtract_numbers(-1, -2) 1.0