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