• Main Page
  • Files
  • File List
  • File Members

/Users/garethloy/Musimathics/Musimat1.2/MusimatTutorial/B0116.cpp

Go to the documentation of this file.
00001 #include "MusimatTutorial.h"
00002 MusimatTutorialSection(B0116) {
00003         Print("*** B.1.16 Conditional Statements ***");
00004         /*****************************************************************************
00005          
00006          B.1.16 Conditional Statements
00007          
00008          A mathematical notation for determining the sign of a number is
00009          
00010                  | x < 0, a
00011          y = |
00012                  | x >= 0, b
00013          
00014          
00015          which sets y to a if x is negative; otherwise it sets y to b. Such relational expressions are called 
00016          predicates. Musimat accomplishes the same thing like this:
00017          *****************************************************************************/
00018         
00019         Real a = 1;
00020         Real b = 2;
00021         Real y = 5;
00022         
00023         If (y < 0) 
00024                 y = a;
00025         Else 
00026                 y = b;
00027         
00028         /*****************************************************************************
00029          In this example, y receives the value of a if y is less than 0; otherwise y receives the value of b. 
00030          The Else part of this construction is optional. So for example,
00031          *****************************************************************************/
00032         
00033         If (a < b)
00034                 Print(a);
00035         
00036         /*****************************************************************************
00037          prints a only if it is less than b. If and Else can be combined to allow chains of predicates:
00038          *****************************************************************************/
00039         Real r = -1.0;
00040         
00041         If (a < 0)         // is x negative?
00042                 y = a;
00043         Else If (a == 0)   // it's not negative, but is it zero?
00044                 y = b;
00045         Else               // neither negative nor zero, x must be positive
00046                 y = r;
00047         
00048 }
00049 
00051 /* $Revision: 1.2 $ $Date: 2006/09/05 06:32:25 $ $Author: dgl $ $Name:  $ $Id: B0116.cpp,v 1.2 2006/09/05 06:32:25 dgl Exp $ */
00052 // The Musimat Tutorial © 2006 Gareth Loy
00053 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy 
00054 // and published exclusively by The MIT Press.
00055 // This program is released WITHOUT ANY WARRANTY; without even the implied 
00056 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00057 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
00058 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
00059 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
00060 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
00061 // The Musimat website:                 http://www.musimat.com/
00062 // This program is released under the terms of the GNU General Public License
00063 // available here:                      http://www.gnu.org/licenses/gpl.txt
00064 

Generated on Fri Nov 26 2010 16:18:25 for Musimat Tutorial by  doxygen 1.7.2