3.0 Numeric Processing Unit (NPU)
The npu_compute() and. npu_math() functions are implemented within the codemelted.rs and codemelted.js modules. They hold all computations executable by this project. The CMathFormula enumeration is what you utilize for the codemelted.rs rust module. The MATH_FORMULA enumeration is what is utilized for the codemelted.js module.
Table of Contents
3.1 Compute Functionality
The following sub-sections breakdown the npu_compute() function usage within the project’s primary modules.
3.1.1 Syntax
codemelted.js Module:
// Specify an Object literal request, receive a CResult object with a
// CObject held in the result() function.
let response = npu_compute(request);
codemelted.rs Module:
#![allow(unused)]
fn main() {
// Specify an CObject (a.k.a JsonValue) request,
// receive a Result object back with a CObject response if
// successful
let response: Result<CObject, std::io::Error> = codemelted::npu_compute(
request: &CObject
);
}
3.1.2 Request Objects
TO BE DETERMINED
3.2 Math
3.2.1 Syntax
codemelted.js Module:
// Specify the MATH_FORMULA to execute and pass the arguments to
// the chosen formula to receive the answer.
let answer = npu_math({
formula: MATH_FORMULA.TemperatureCelsiusToFahrenheit,
args: [0.0]
});
NOTE: A SyntaxError is thrown if the arguments don’t match the necessary formula requirements.
codemelted.rs Module:
#![allow(unused)]
fn main() {
// Specify the CMathFormula to execute and pass the arguments to
// the chosen formula to receive the answer.
let answer: f64 = codemelted::npu_math(
CMathFormula.TemperatureCelsiusToFahrenheit,
&[0.0]
);
}
NOTE: A panic! occurs if the arguments don’t match the necessary formula requirements.
3.2.2 Formulas
The following CamelCase Formula entries correspond to the enumerations identified in 3.2.1 Syntax above. They also correspond to the formula one would specify for the codemelted CLI program.
| Formula | Description |
|---|---|
| TemperatureCelsiusToFahrenheit | °F = (°C x 9/5) + 32 |
| TemperatureCelsiusToKelvin | °K = °C + 273.15 |
| TemperatureFahrenheitToCelsius | °K = (°F − 32) × 5/9 + 273.15 |
| TemperatureFahrenheitToKelvin | °K = (°F − 32) × 5/9 + 273.15 |
| TemperatureKelvinToCelsius | °C = °K − 273.15 |
| TemperatureKelvinToFahrenheit | °F = (°K − 273.15) × 9/5 + 32 |