Special ! 
Mobile version of the aldweb Site m.aldweb.com Neither French, nor English? Try one of these flags then:


Weather / Spam / www 
Lyon Weather
aldweb against spam







 Forum  Pocket Computer
Warning: A nonnumeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 257
Topic # 19 
convert decimal to fraction 
09/12/2002 @ 20:45 by ERNESTO

HI I LOOKING FOR FOR A PROGRAM IN BASIC TO CONVERT DECIMAL TO FRACTION. EXEMPLE : RATIO =.301886 FRACTION = 16/53 I HAVE SEVERAL POCKET COMPUTER LIKE SHARP 1500 ALSO SHARP EL9600c AND CASIO FX880P. I HOPE YOU CAN GIMME A HAND ALSO I NEED THE MORE LOWER FACTOR BECAUSE THIS APPLICATION IS FOR FIGURING SET OF GEARS FOR MACHINES TO CUT GEARS THANK YOU ERNESTO HERNANDEZ ; 


Warning: A nonnumeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 1  09/12/2002 @ 21:56 by aldweb
visitor 
Hello Ernesto and welcome on this forum :) Your request for a program being able to find a fraction from a real number is a wonderful thing. I wish I would be able to find the algorithm to do it, but it by far outpasses my programming knowledge. Anybody else has got an idea? We could think about running a friendly competition among us on this topic. What do you think of it? 


Warning: A nonnumeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 2  16/12/2002 @ 15:37 by Madis K.
visitor 
Lets open our eyes and try some simpe things. I think you have already tried that, but I would go and multiply X with Y & INC(Y) every cycle, till X*Y becomes a integer value. Then I would make the fraction simpler by dividing a number of times both A and Y in formula A/Y. Another thing is to start increasing Value of Y in formula 1/Y. IF 1/Y<X THEN X=X+1 ELSEIF 1/Y>X then do one of the following: 1)Take the integer part away from the X or 2)Subsitute 1 with variable and increase it IF 1/Y=X THEN just print the value on the screen or keep it in secret:) About the first one:You take the INT away!!! this means you have to add it later and you get a value like a_b/c In the second you get a value like a/b <=a is sometimes bigger than b. Hope it helps;D You know what to do when it won't 


Warning: A nonnumeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 3  16/12/2002 @ 21:48 by Sébastien
visitor 
Sorry for multiple replies, I had some problem with the answer window... I give here the basic idea of a method that yields series of fractions approximating more and more accurately a given floating point number. First, start with a positive number r0. The trivial approximating fraction of r0 at rank zero is... surprise: u0/1 where u0 = [r0] is the integer part of r0! Then subtract [r0] from r0, giving a positive number r1 in range [0, 1). r1 is the inverse of this new number. Now take the integer part of r1: u1 = [r1]. A new approximating fraction of r0 is now: 1 u0 +  u1 The idea is to recursively apply the method over the ri terms, yielding: 1 u0 +  1 u1 +  u2 + etc. Now the problem is to compute *incrementally* the fraction. I give a method (without demonstration!): Let N(1) = 1 and D(1) = 0 and N(0) = [r0] and D(0) = 1 and U(0) = r0  N(0) and R(0) = r0 then at rank i we have: N(i) = N(i1) * U(i) + N(i2) D(i) = D(i1) * U(i) + D(i2) where U(i) = [1 / R(i1)] and R(i) = 1 / R(i1)  U(i) Programmed in Objective Caml and applied to acos(1) (~pi) it yields: 22./7. (Archimede's approximation) 333./106. 355./113. (A wellknown pi approximation) 103993./33102. 104348./33215. etc. Writing the BASIC program that computes the series of approximating fractions is let as an exercice to the reader! Note: The halt condition may be something like: abs (r0  N(i) / D(i)) / r0 < epsilon (relative convergence) I hope I've not made too many mistakes... Cheers, Sébastien 


Warning: A nonnumeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 4  17/12/2002 @ 10:03 by Sébastien
visitor 
After one night full of mathematical dreams, I would suggest to work only on the mantissa of r0 (by multiplying it by its base 10logarithm). It should avoid bad results when r0 is too small. After running the algorithm, just add trailing zeroes to the numerator in case of positive logarithm or to the denominator otherwise. Cheers, Sébastien. 


Warning: A nonnumeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 5  17/12/2002 @ 10:22 by Sébastien
visitor 
Aldweb, Just a little suggestion about this forum: Is it possible to *keep* spaces at the beginning of a line to avoid bad formatting like this: 1 u0 +  1 u1 +  u2 + etc. when I wrote that: ...........1 u0 +  ...............1 ......u1 +  ............u2 + etc. Thank you! Sébastien. 


Warning: A nonnumeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 6  17/12/2002 @ 22:14 by aldweb
visitor 
Sébastien,
It's done :) It's done :) It's done :) It's done ;:) It's done :) It's done :) It's done :) 


Warning: A nonnumeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 7  17/12/2002 @ 23:02 by aldweb
visitor 
Oups, I forgot to say that you have to leave at least 2 SPACES at the beginning of a line for this to be effective. 


Warning: A nonnumeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 8  18/12/2002 @ 19:18 by Sébastien
visitor 
Thank you! PS: Just a little test, to see...
Sébastien. 


topic active
topic closed
Sticky
New message 
Correct message
Close topic
Make sticky





