# 4.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**

- [4.0 Numeric Processing Unit (NPU)](#40-numeric-processing-unit-npu)
  - [4.1 Compute Functionality](#41-compute-functionality)
    - [4.1.1 Syntax](#411-syntax)
    - [4.1.2 Request Objects](#412-request-objects)
  - [4.2 Math](#42-math)
    - [4.2.1 Syntax](#421-syntax)
    - [4.2.2 Formulas](#422-formulas)

## 4.1 Compute Functionality

The following sub-sections breakdown the `npu_compute()` function usage within the project's primary modules.

### 4.1.1 Syntax

**codemelted.js Module:**

```javascript
// 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:**

```rust
// 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
);
```

### 4.1.2 Request Objects

<mark>TO BE DETERMINED</mark>

## 4.2 Math

### 4.2.1 Syntax

**codemelted.js Module:**

```javascript
// 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:**

```rust
// 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.*

### 4.2.2 Formulas

The following CamelCase Formula entries correspond to the enumerations identified in [4.2.1 Syntax](#621-syntax) above. They also correspond to the formula one would specify for the `codemelted` CLI program. See Section "3.0 Native Command Line Interface (CLI)" for details.

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` |
