Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


i


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 aeleneski   Banned   -  Reputation: 100

Like
Likes
Like

Posted 17 December 2001 - 01:09 PM

i [Edited by - aeleneski on April 24, 2006 11:23:05 PM]

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 17 December 2001 - 02:30 PM

This function would probably be extremely slow but heres one solution I think

int numerator, denomenator; // set these to something
int smallest; // holds the smaller of the two variables
int gcf; // greatest common factor

// determine which number is smallest, doesn''t matter if equal
if ( numerator >= denomenator )
{ smallest = numerator; }
else
{ smallest = denomenator; }

for ( int i = smallest; i > 0; i++ )
{
// if both numbers divide evenly, then it is divisible by i
if ( ( numerator % i == 0 ) && ( denomenator % i == 0 ))
{ gcf = i; }
}

I''m still learning C++ so if there are any more complex functions to do this I am unaware of them.


#3 Floppy   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 December 2001 - 02:54 PM

Here''s some source code I made a while ago:
  
// Utilities

void rational::simplify() // Simplify rational

{
double x=gcd(num, denom);
num/=x;
denom/=x;
}

long rational::gcd(long x, long y) // Find greatest common divisor

{
x=labs(x); // long absolute value

y=labs(y);
while(x != y)
{
if(x<y)
y-=x;
if(y<x)
x-=y;
}
return(x);
}





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS