aldweb

Close I. aldweb

Close II. PC Freeware

Close III. Palm Freeware

Close IV. Palm Shareware

Close V. iziBasic Palm

Close VI. Palm Knowledge

Close VII. Pocket Computer

Close VIII. miniPortail

Special !



Mobile version of
the aldweb Site

m.aldweb.com


Neither French, nor English?

Try one of these flags then:
[de] [es] [it] [pt]
Search




Weather / Spam / www

Lyon Weather


aldweb against spam


Newsletter
To receive news about this website, consider subscribing to our Newsletter.
Subscribe
Unsubscribe
298 Subscribers
Family's web sites

Webmaster - Infos
Friends News
Visits

   visitors

   visitors online

Poll
What do you think of the new design of the aldweb Site?
 
Great !
Beautiful
Average
So ugly...
Results
forum.gifForum - Pocket Computer - Topic #19

Forum - Forum
Pocket Computer - Pocket Computer


Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 257

active  Topic # 19  convert decimal to fraction

09/12/2002 @ 20:45
by ERNESTO

Anonymous



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 EL-9600c
AND CASIO FX-880P.
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








;
Write to ERNESTO   Post an answer  Top

[]   


Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 1
--------
09/12/2002 @ 21:56
by aldweb

Anonymous

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?
Write to aldweb   Post an answer  Top

Warning: A non-numeric 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.

Anonymous

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
Write to Madis K.   Post an answer  Top

Warning: A non-numeric 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

Anonymous

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(i-1) * U(i) + N(i-2)
D(i) = D(i-1) * U(i) + D(i-2)
where U(i) = [1 / R(i-1)]
and R(i) = 1 / R(i-1) - U(i)

Programmed in Objective Caml and applied to acos(-1) (~pi) it yields:

22./7. (Archimede's approximation)
333./106.
355./113. (A well-known 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
Write to Sébastien   Post an answer  Top

Warning: A non-numeric 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

Anonymous

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 10-logarithm). 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.
Write to Sébastien   Post an answer  Top

Warning: A non-numeric 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

Anonymous

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.
Write to Sébastien   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 6
--------
17/12/2002 @ 22:14
by aldweb

Anonymous

visitor
Sébastien,

It's done :-)
  It's done :-)
    It's done :-)
      It's done ;:-)
    It's done :-)
  It's done :-)
It's done :-)
Write to aldweb   Post an answer  Top

Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n 7
--------
17/12/2002 @ 23:02
by aldweb

Anonymous

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.
Write to aldweb   Post an answer  Top

Warning: A non-numeric 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

Anonymous

visitor
  Thank you!
    P-S: Just a little test,
      to see...

         Sébastien.
Write to Sébastien   Post an answer  Top
active topic active   closed topic closed   Sticky Sticky   New New message   -   Correct Correct message   Close Close topic   Make sticky Make sticky
[]
Forum Topic  Forum 



 
^ Top ^