Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00019
00020 #include <string.h>
00021 #include "Musimat.h"
00022
00023 Integer Length( String s ) { Return( Integer( strlen(s)+1 ) ); }
00024
00034 Integer RealToRational( Real f, Integer Reference a, Integer Reference b ) {
00035 If (f == 0.0) {
00036 a = 0;
00037 b = 1;
00038 Return( 0 );
00039 } Else If (f == 1.0) {
00040 a = b = 1;
00041 Return( 0 );
00042 }
00043
00044 Const Integer count = 3000000;
00045 Const Real limit = 0.0000001 ;
00046
00047 If (f < limit) {
00048 a = 1;
00049 b = count;
00050 Return( 0 );
00051 }
00052
00053 a = b = 1;
00054 Integer i;
00055 For (i = 0; i < count; i++) {
00056 If ( Abs(Real(a)/Real(b) - f) < limit )
00057 Return i;
00058 Else {
00059 Real x = Abs( Real(a+1)/Real(b) - f );
00060 Real y = Abs( Real(a)/Real(b+1) - f );
00061 If (x < y)
00062 a++;
00063 Else
00064 b++;
00065 }
00066 }
00067 Return i;
00068 }
00069
00070 Void About()
00071 {
00072 Print("The Musimat Tutorial (©) 2006 Gareth Loy");
00073 Print("Derived from Chapter 9 and Appendix B of \"Musimathics Vol. 1\" © 2006 Gareth Loy");
00074 Print("and published exclusively by The MIT Press.");
00075 Print("This program is released WITHOUT ANY WARRANTY; without even the implied");
00076 Print("warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
00077 Print("For information on usage and redistribution, and for a DISCLAIMER OF ALL");
00078 Print("WARRANTIES, see the file, LICENSE.txt, in this distribution.");
00079 Print("\"Musimathics\" is available here: http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916");
00080 Print("Gareth Loy's Musimathics website: http://www.musimathics.com/");
00081 Print("The Musimat website: http://www.musimat.com/");
00082 Print("This program is released under the terms of the GNU General Public License");
00083 Print("available here: http://www.gnu.org/licenses/gpl.txt");
00084 }
00085