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.validate_zero_divisionBinaryArithmeticExpression.operationBinaryArithmeticExpression.resultBinaryArithmeticExpression.model_computed_fields
BinaryArithmeticOperationBinaryArithmeticOperatorcalculate_results
Module contents#
Expose binary operations.
- pydantic model BinaryArithmeticExpression[source]#
Bases:
CustomPydanticBaseModelDefine binary arithmetic expression.
- binary_operator#
arithmetic operator of binary arithmetic expression
- Type:
- operation#
function to perform arithmetic operation corresponding to binary_operator
Show JSON schema
{ "title": "BinaryArithmeticExpression", "description": "Define binary arithmetic expression.\n\nAttributes\n----------\nleft_operand : float\n first number of binary arithmetic expression\nbinary_operator : BinaryArithmeticOperator\n arithmetic operator of binary arithmetic expression\nright_operand : float\n second number of binary arithmetic expression\noperation : BinaryArithmeticOperation\n function to perform arithmetic operation corresponding to `binary_operator`\nresult : float\n result of binary arithmetic expression", "type": "object", "properties": { "left_operand": { "description": "first number of binary arithmetic expression", "title": "Left Operand", "type": "number" }, "binary_operator": { "allOf": [ { "$ref": "#/$defs/BinaryArithmeticOperator" } ], "description": "arithmetic operator of binary arithmetic expression" }, "right_operand": { "description": "second number of binary arithmetic expression", "title": "Right Operand", "type": "number" } }, "$defs": { "BinaryArithmeticOperator": { "description": "Define supported arithmetic operators.", "enum": [ "+", "-", "*", "/" ], "title": "BinaryArithmeticOperator", "type": "string" } }, "additionalProperties": false, "required": [ "left_operand", "binary_operator", "right_operand" ] }
- Config:
extra: str = forbid
- Fields:
- Validators:
validate_zero_division»all fields
- field binary_operator: BinaryArithmeticOperator [Required]#
arithmetic operator of binary arithmetic expression
- Validated by:
- validator validate_zero_division » all fields[source]#
Validate that division by zero is not attempted.
- Returns:
unchanged instance if validation passes
- Return type:
- Raises:
ValueError -- if division by zero is attempted
- Validates:
all fields
- property operation: Callable[[float, float], float]#
Store implementation of binary arithmetic operation.
- Returns:
implementation of binary arithmetic operation corresponding to 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]] = {'operation': ComputedFieldInfo(wrapped_property=<property object>, return_type=collections.abc.Callable[[float, float], float], alias=None, alias_priority=None, title=None, description='Store implementation of binary arithmetic operation.\n\nReturns\n-------\nBinaryArithmeticOperation\n implementation of binary arithmetic operation corresponding to `binary_operator`', examples=None, json_schema_extra=None, repr=True), 'result': ComputedFieldInfo(wrapped_property=<functools.cached_property object>, return_type=<class 'float'>, alias=None, alias_priority=None, title=None, description='Store result of binary arithmetic expression.\n\nReturns\n-------\nfloat\n result of binary arithmetic expression', examples=None, json_schema_extra=None, repr=True)}#
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- class BinaryArithmeticOperator(value)[source]#
Bases:
CustomStrEnumDefine supported arithmetic operators.
- ADDITION = '+'#
- SUBTRACTION = '-'#
- MULTIPLICATION = '*'#
- DIVISION = '/'#
- class IdentityElements(value)[source]#
Bases:
CustomFloatEnumDefine assumed identity elements.
- ADDITIVE_IDENTITY = 0.0#
- MULTIPLICATIVE_IDENTITY = 1.0#
- class InverseElements(value)[source]#
Bases:
CustomFloatEnumDefine supported inverse elements.
- ADDITIVE_INVERSE = -1.0#
- MULTIPLICATIVE_INVERSE = 1.0#
- add_numbers(left_addend: float, right_addend: float) float[source]#
Perform addition of two real numbers.
- Parameters:
- Returns:
sum of left_addend and right_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: float, operator: BinaryArithmeticOperator, second_input: float) float[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: float, divisor: float) float[source]#
Perform division of two real numbers.
- Parameters:
- Returns:
quotient of dividend by divisor
- 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: float) float[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: float) float[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_number is 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: float, right_multiplicand: float) float[source]#
Perform multiplication of two real numbers.
- Parameters:
- Returns:
product of two left_multiplicand and right_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: float, subtrahend: float) float[source]#
Perform subtraction of two real numbers.
- Parameters:
- Returns:
difference of minuend from subtrahend
- 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