00001 #include "MusimatTutorial.h" 00002 MusimatTutorialSection(B0127) { 00003 Print("*** B.1.27 Other Built-in Functions ***"); 00004 /***************************************************************************** 00005 00006 B.1.27 Other Built-in Functions 00007 00008 Musimat includes standard mathematical functions such as Sqrt(x). There are trigono- 00009 metric functions such as Sin(x), Cos(x), and Tan(x). Arguments to trigonometric functions 00010 are in real radian values. Speaking of radian measure, here's an interesting way to compute Pi to 00011 the machine precision of your computer: 00012 *****************************************************************************/ 00013 00014 Const Real Pi = Atan(1.0) * 4.0; // arctangent of 1 times 4 equals Pi 00015 Print("Pi=", Pi); 00016 00017 /***************************************************************************** 00018 The function Abs(x) returns the absolute value of its argument. It works for either Real or 00019 Integer expressions. For instance, both of the following statements will print True: 00020 *****************************************************************************/ 00021 00022 If (Abs(-5) == Abs(5)) // Integer Abs( ) 00023 Print(True); 00024 Else 00025 Print(False); 00026 00027 If (Abs(-5.0) == Abs(5.0)) // Real Abs( ) 00028 Print(True); 00029 Else 00030 Print(False); 00031 00032 /***************************************************************************** 00033 With no arguments, the built-in function Random() returns a real random value between 0.0 and 00034 1.0, but if Random() is given arguments specifying Real lower and upper bounds, it returns a 00035 Real random value between those boundaries. For example, 00036 *****************************************************************************/ 00037 00038 Real x = Random(0.0, 11.0); 00039 Print(x); 00040 00041 /***************************************************************************** 00042 returns a random Real value in the range 0.0 <= x < 11.0. Note the range is from 0.0 to almost 11.0. 00043 00044 If Random() is given arguments specifying Integer lower and upper bounds, it returns an 00045 Integer random value between those boundaries. For example, 00046 *****************************************************************************/ 00047 00048 Integer y = Random(0, 11); 00049 Print(y); 00050 00051 /***************************************************************************** 00052 returns a random Integer value in the range [0..11]. Note the range is inclusive from 0 to 11. 00053 *****************************************************************************/ 00054 } 00055 00057 /* $Revision: 1.3 $ $Date: 2006/09/05 08:03:08 $ $Author: dgl $ $Name: $ $Id: B0127.cpp,v 1.3 2006/09/05 08:03:08 dgl Exp $ */ 00058 // The Musimat Tutorial © 2006 Gareth Loy 00059 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy 00060 // and published exclusively by The MIT Press. 00061 // This program is released WITHOUT ANY WARRANTY; without even the implied 00062 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00063 // For information on usage and redistribution, and for a DISCLAIMER OF ALL 00064 // WARRANTIES, see the file, "LICENSE.txt," in this distribution. 00065 // "Musimathics" is available here: http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916 00066 // Gareth Loy's Musimathics website: http://www.musimathics.com/ 00067 // The Musimat website: http://www.musimat.com/ 00068 // This program is released under the terms of the GNU General Public License 00069 // available here: http://www.gnu.org/licenses/gpl.txt 00070