or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-4/

Multi-Type Calculator

Build a calculator module that performs arithmetic operations on values of different numeric types, automatically handling type conversions between standard numbers, arbitrary precision decimals, rational numbers (fractions), and complex numbers.

Capabilities

Addition with Mixed Types

  • Adding a standard number 5 and a string "3" returns 8 as a number @test
  • Adding an arbitrary precision decimal representing 10.5 and a standard number 2 returns 12.5 as an arbitrary precision decimal @test
  • Adding a rational number 1/2 and a standard number 0.25 returns a rational number equivalent to 3/4 @test

Multiplication with Mixed Types

  • Multiplying a standard number 4 and an arbitrary precision decimal 2.5 returns 10 as an arbitrary precision decimal @test
  • Multiplying a rational number 2/3 and a standard number 3 returns a rational number equivalent to 2 @test

Division with Mixed Types

  • Dividing a standard number 10 by an arbitrary precision decimal 4 returns 2.5 as an arbitrary precision decimal @test
  • Dividing a rational number 1/2 by a standard number 2 returns a rational number equivalent to 1/4 @test

Complex Number Operations

  • Adding a standard number 5 and a complex number with value 3 + 2i returns a complex number 8 + 2i @test
  • Adding an arbitrary precision decimal 5 and a rational number 1/4 returns an arbitrary precision decimal 5.25 @test

Implementation

@generates

API

/**
 * Adds two values of potentially different numeric types.
 * Automatically converts types as needed to return the appropriate result type.
 *
 * @param {*} a - First value (any numeric type)
 * @param {*} b - Second value (any numeric type)
 * @returns {*} Sum with appropriate type based on inputs
 */
function add(a, b) {
  // IMPLEMENTATION HERE
}

/**
 * Multiplies two values of potentially different numeric types.
 * Automatically converts types as needed to return the appropriate result type.
 *
 * @param {*} a - First value (any numeric type)
 * @param {*} b - Second value (any numeric type)
 * @returns {*} Product with appropriate type based on inputs
 */
function multiply(a, b) {
  // IMPLEMENTATION HERE
}

/**
 * Divides two values of potentially different numeric types.
 * Automatically converts types as needed to return the appropriate result type.
 *
 * @param {*} a - Dividend (any numeric type)
 * @param {*} b - Divisor (any numeric type)
 * @returns {*} Quotient with appropriate type based on inputs
 */
function divide(a, b) {
  // IMPLEMENTATION HERE
}

module.exports = {
  add,
  multiply,
  divide
};

Dependencies { .dependencies }

mathjs { .dependency }

Provides mathematical functions and multi-type numeric support with automatic type conversions.