Module calculator_classic

Module calculator_classic 

Source
Expand description

Mathematical utilities translated faithfully from the legacy calculator application suite (old/calculator), including Calculator 4.0, assistance/ error solvers, the 6r2 unique random number generator, and the R.P.S. sidecar game.

Re-exports§

pub use crate::constant::CONST_E;
pub use crate::constant::CONST_PI;

Structs§

PrimeVerificationResult
Structure holding the result of a prime number and factor verification test.

Enums§

RpsChoice
Choice options in Rock-Paper-Scissors.
RpsOutcome
Outcome of a Rock-Paper-Scissors game round.
SquareRootResult
Result of a square root evaluation, representing real or imaginary output.

Constants§

RANDOM_SCALES
Standard scale multipliers for random table generation.

Functions§

add
Performs addition of two floating-point numbers.
celsius_to_fahrenheit
Converts temperature from Celsius to Fahrenheit.
circle_area
Calculates the area of a circle given its radius ($\pi \cdot r^2$).
divide
Performs floating-point division of two numbers. Returns an error if the divisor is zero.
evaluate_basic_op
Evaluates a basic arithmetic operation given an operator string.
evaluate_expression
Evaluates a math expression string with standard operator precedence.
fahrenheit_to_celsius
Converts temperature from Fahrenheit to Celsius.
format_modulo_result
Formats modulo quotient and remainder into legacy output string ("Q r R"). FIXME: In original version, if n2 is 0 it looks like it returns “{ }” as output string. I guess that would need to be implemented in the UI code.
format_square_root
Formats square root result into a human-readable display string.
generate_scaled_random_table
Generates a table of 8 scaled random numbers from a given base raw random value ($0 \dots 1$).
generate_unique_random_triplet
Generates a triplet of non-repeating random integers within $[min, max]$. Faithfully reproduces the loop validation in sidecar 6r2.
integer_divide
Performs integer division (quotient without remainder). Returns an error if dividing by zero or overflowing.
modulo
Computes integer remainder (modulo). Returns an error if dividing by zero or overflowing.
multiply
Performs multiplication of two floating-point numbers.
play_rps
Evaluates a Rock-Paper-Scissors turn outcome.
power
Performs exponentiation ($base^{exp}$).
quotient_and_remainder
Computes both quotient and remainder for integer division. Faithfully models legacy Visual Basic modulo formatting logic.
rectangle_area
Calculates the area of a rectangle given base and height ($base \cdot height$).
rectangle_perimeter
Calculates the perimeter of a rectangle ($2 \cdot (base + height)$).
rps_choice_from_int
Converts integer code ($1 \dots 3$) to RpsChoice.
scaled_random
Computes a scaled random number value based on a base $[0.0, 1.0)$ input.
square_root
Computes the square root of a number. Supports negative inputs by returning an imaginary component representation.
subtract
Performs subtraction of two floating-point numbers.
verify_prime_and_factors
Checks prime status and calculates factors, matching legacy calculator interface.