- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# C:/Musimathics_local/Musimat/MusimatLib/Rational.cpp

Go to the documentation of this file.

    00001 /* $Revision: 1.2 $ $Date: 2006/09/09 06:22:54 $ $Author: dgl $ $Name:  $ $Id: _rational_8cpp-source.html,v 1.2 2006/09/09 06:22:54 dgl Exp $ */
    00002 // The Musimat Tutorial © 2006 Gareth Loy
    00003 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy
    00004 // and published exclusively by The MIT Press.
    00005 // This program is released WITHOUT ANY WARRANTY; without even the implied
    00006 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
    00008 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
    00009 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
    00010 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
    00011 // The Musimat website:                 http://www.musimat.com/
    00012 // This program is released under the terms of the GNU General Public License
    00013 // available here:                      http://www.gnu.org/licenses/gpl.txt
    00014
    00015 #include "Musimat.h"
    00016 #include "float.h"
    00017
    00018 // Private buffer to format strings in
    00019 Character Rational::s_buf[128];
    00020
    00021 ostream& operator<<( ostream& os, Rational& r )
    00022 {
    00023         os << r.print();
    00024         Return os;
    00025 }
    00026
    00027 istream& operator>>( istream& is, Rational& p )
    00028 {
    00029         char ch;
    00030         is >> ch && (ch == '{' || ch == '(')
    00031                 && is >> p.m_num >> ch && ch == ','
    00032                 && is >> p.m_den >> ch && (ch == '}' || ch == '(');
    00033         Return is;
    00034 }
    00035
    00036 RationalList RealListToRationalList( RealList R )
    00037 {
    00038         RationalList L;
    00039         For (Integer i = 0; i < Length( R ); i++ ) {
    00040                 Rational x(R[i]);
    00041                 L[i] = x;
    00042         }
    00043         Return( L );
    00044 }