docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
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.
5 and a string "3" returns 8 as a number @test10.5 and a standard number 2 returns 12.5 as an arbitrary precision decimal @test1/2 and a standard number 0.25 returns a rational number equivalent to 3/4 @test4 and an arbitrary precision decimal 2.5 returns 10 as an arbitrary precision decimal @test2/3 and a standard number 3 returns a rational number equivalent to 2 @test10 by an arbitrary precision decimal 4 returns 2.5 as an arbitrary precision decimal @test1/2 by a standard number 2 returns a rational number equivalent to 1/4 @test5 and a complex number with value 3 + 2i returns a complex number 8 + 2i @test5 and a rational number 1/4 returns an arbitrary precision decimal 5.25 @test/**
* 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
};Provides mathematical functions and multi-type numeric support with automatic type conversions.