#!/usr/bin/env node; /****************************************************************************** * This program demonstrates the math library. * * Copyright © 2016 Richard Lesh. All rights reserved. *****************************************************************************/ const Utils = require('./Utils'); const main = async () => { const a = Math.PI / 6; const b = Math.PI / 4; const c = -a * 2; const d = -b * 2; const e = Math.E; console.log(Utils.format("pi = {0:f}", Math.PI)); console.log(Utils.format("e = {0:f}", Math.E)); // abs, floor, ceil, round, trunc, min, max console.log(Utils.format("abs({0:f}) = {1:f}", a, Math.abs(a))); console.log(Utils.format("abs({0:f}) = {1:f}", c, Math.abs(c))); console.log(Utils.format("floor({0:f}) = {1:f}", a, Math.floor(a))); console.log(Utils.format("floor({0:f}) = {1:f}", c, Math.floor(c))); console.log(Utils.format("ceil({0:f}) = {1:f}", a, Math.ceil(a))); console.log(Utils.format("ceil({0:f}) = {1:f}", c, Math.ceil(c))); console.log(Utils.format("round({0:f}) = {1:f}", a, Math.round(a))); console.log(Utils.format("round({0:f}) = {1:f}", c, Math.round(c))); console.log(Utils.format("trunc({0:f}) = {1:f}", a, Math.trunc(a))); console.log(Utils.format("trunc({0:f}) = {1:f}", c, Math.trunc(c))); console.log(Utils.format("min({0:f}, {1:f}) = {2:f}", a, c, Math.min(a, c))); console.log(Utils.format("max({0:f}, {1:f}) = {2:f}", a, c, Math.max(a, c))); // sin, cos, tan, atan, atan2, acos, asin console.log(Utils.format("sin({0:f}) = {1:f}", a, Math.sin(a))); console.log(Utils.format("sin({0:f}) = {1:f}", b, Math.sin(b))); console.log(Utils.format("sin({0:f}) = {1:f}", c, Math.sin(c))); console.log(Utils.format("sin({0:f}) = {1:f}", d, Math.sin(d))); console.log(Utils.format("cos({0:f}) = {1:f}", a, Math.cos(a))); console.log(Utils.format("cos({0:f}) = {1:f}", b, Math.cos(b))); console.log(Utils.format("cos({0:f}) = {1:f}", c, Math.cos(c))); console.log(Utils.format("cos({0:f}) = {1:f}", d, Math.cos(d))); console.log(Utils.format("tan({0:f}) = {1:f}", a, Math.tan(a))); console.log(Utils.format("tan({0:f}) = {1:f}", b, Math.tan(b))); console.log(Utils.format("tan({0:f}) = {1:f}", c, Math.tan(c))); console.log(Utils.format("asin({0:f}) = {1:f}", Math.sin(a), Math.asin(Math.sin(a)))); console.log(Utils.format("asin({0:f}) = {1:f}", Math.sin(b), Math.asin(Math.sin(b)))); console.log(Utils.format("asin({0:f}) = {1:f}", Math.sin(c), Math.asin(Math.sin(c)))); console.log(Utils.format("asin({0:f}) = {1:f}", Math.sin(d), Math.asin(Math.sin(d)))); console.log(Utils.format("acos({0:f}) = {1:f}", Math.cos(a), Math.acos(Math.cos(a)))); console.log(Utils.format("acos({0:f}) = {1:f}", Math.cos(b), Math.acos(Math.cos(b)))); console.log(Utils.format("acos({0:f}) = {1:f}", Math.cos(c), Math.acos(Math.cos(c)))); console.log(Utils.format("acos({0:f}) = {1:f}", Math.cos(d), Math.acos(Math.cos(d)))); console.log(Utils.format("atan({0:f}) = {1:f}", Math.tan(a), Math.atan(Math.tan(a)))); console.log(Utils.format("atan({0:f}) = {1:f}", Math.tan(b), Math.atan(Math.tan(b)))); console.log(Utils.format("atan({0:f}) = {1:f}", Math.tan(c), Math.atan(Math.tan(c)))); // 45 degrees console.log(Utils.format("atan2({0:f}, {1:f}) = {2:f}", 1.0, 1.0, Math.atan2(1.0, 1.0))); // 30 degrees console.log(Utils.format("atan2({0:f}, {1:f}) = {2:f}", 1.0, Math.sqrt(3.0), Math.atan2(1.0, Math.sqrt(3.0)))); // sinh, cosh, tanh, atanh, acosh, asinh console.log(Utils.format("sinh({0:f}) = {1:f}", a, Math.sinh(a))); console.log(Utils.format("sinh({0:f}) = {1:f}", b, Math.sinh(b))); console.log(Utils.format("sinh({0:f}) = {1:f}", c, Math.sinh(c))); console.log(Utils.format("sinh({0:f}) = {1:f}", d, Math.sinh(d))); console.log(Utils.format("cosh({0:f}) = {1:f}", a, Math.cosh(a))); console.log(Utils.format("cosh({0:f}) = {1:f}", b, Math.cosh(b))); console.log(Utils.format("cosh({0:f}) = {1:f}", c, Math.cosh(c))); console.log(Utils.format("cosh({0:f}) = {1:f}", d, Math.cosh(d))); console.log(Utils.format("tanh({0:f}) = {1:f}", a, Math.tanh(a))); console.log(Utils.format("tanh({0:f}) = {1:f}", b, Math.tanh(b))); console.log(Utils.format("tanh({0:f}) = {1:f}", c, Math.tanh(c))); console.log(Utils.format("tanh({0:f}) = {1:f}", d, Math.tanh(d))); console.log(Utils.format("asinh({0:f}) = {1:f}", Math.sinh(a), Math.asinh(Math.sinh(a)))); console.log(Utils.format("asinh({0:f}) = {1:f}", Math.sinh(b), Math.asinh(Math.sinh(b)))); console.log(Utils.format("asinh({0:f}) = {1:f}", Math.sinh(c), Math.asinh(Math.sinh(c)))); console.log(Utils.format("asinh({0:f}) = {1:f}", Math.sinh(d), Math.asinh(Math.sinh(d)))); console.log(Utils.format("acosh({0:f}) = {1:f}", Math.cosh(a), Math.acosh(Math.cosh(a)))); console.log(Utils.format("acosh({0:f}) = {1:f}", Math.cosh(b), Math.acosh(Math.cosh(b)))); console.log(Utils.format("acosh({0:f}) = {1:f}", Math.cosh(c), Math.acosh(Math.cosh(c)))); console.log(Utils.format("acosh({0:f}) = {1:f}", Math.cosh(d), Math.acosh(Math.cosh(d)))); console.log(Utils.format("atanh({0:f}) = {1:f}", Math.tanh(a), Math.atanh(Math.tanh(a)))); console.log(Utils.format("atanh({0:f}) = {1:f}", Math.tanh(b), Math.atanh(Math.tanh(b)))); console.log(Utils.format("atanh({0:f}) = {1:f}", Math.tanh(c), Math.atanh(Math.tanh(c)))); console.log(Utils.format("atanh({0:f}) = {1:f}", Math.tanh(d), Math.atanh(Math.tanh(d)))); // log, log10, exp, pow, sqrt console.log(Utils.format("log({0:f}) = {1:f}", a, Math.log(a))); console.log(Utils.format("log({0:f}) = {1:f}", b, Math.log(b))); console.log(Utils.format("log({0:f}) = {1:f}", -c, Math.log(-c))); console.log(Utils.format("log({0:f}) = {1:f}", -d, Math.log(-d))); console.log(Utils.format("log({0:f}) = {1:f}", e, Math.log(e))); console.log(Utils.format("log10({0:f}) = {1:f}", a, Math.log10(a))); console.log(Utils.format("log10({0:f}) = {1:f}", b, Math.log10(b))); console.log(Utils.format("log10({0:f}) = {1:f}", -c, Math.log10(-c))); console.log(Utils.format("log10({0:f}) = {1:f}", -d, Math.log10(-d))); console.log(Utils.format("log10({0:f}) = {1:f}", e, Math.log10(e))); console.log(Utils.format("exp({0:f}) = {1:f}", 0.5, Math.exp(0.5))); console.log(Utils.format("exp({0:f}) = {1:f}", 1.0, Math.exp(1.0))); console.log(Utils.format("exp({0:f}) = {1:f}", 2.0, Math.exp(2.0))); console.log(Utils.format("pow({0:f}, {1:f}) = {2:f}", 10.0, 0.5, Math.pow(10.0, 0.5))); console.log(Utils.format("pow({0:f}, {1:f}) = {2:f}", 10.0, 1.0, Math.pow(10.0, 1.0))); console.log(Utils.format("pow({0:f}, {1:f}) = {2:f}", 10.0, 2.0, Math.pow(10.0, 2.0))); console.log(Utils.format("sqrt({0:f}) = {1:f}", 0.5, Math.sqrt(0.5))); console.log(Utils.format("sqrt({0:f}) = {1:f}", 2.0, Math.sqrt(2.0))); console.log(Utils.format("sqrt({0:f}) = {1:f}", 10.0, Math.sqrt(10.0))); // random numbers console.log(Utils.format("random() = {0:f}", Math.random())); console.log(Utils.format("random() = {0:f}", Math.random())); console.log(Utils.format("random() = {0:f}", Math.random())); } main().catch( e => { console.error(e) } );