Jump to content
  • Advertisement
Sign in to follow this  
SirLuthor

Fractions for everyone!

This topic is 4815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, once again folks, I come bearing... something! Anyway, I've been working recently on a fraction class, with multiplication, devision, all that junk.. So, here you have the fruit of my labours.. Anyway, you all can feel free to use this, and if someone could, I'd appreciate it if someone would have a gander through and point out to me the obvious things that I've missed and subsquently screwed up horribly [smile] Readme is included in the header file. Any and all feedback welcome [EDIT] Oh yes, one question.. I was trying to overload the << operator so as to be able to use std::cout with it, and this is what I had my function declaration as: std::ostream & operator<< (std::ostream & os, const Fraction & ref); And of course the obligatory friend declaration inside the Fraction class. However, this yielded a fine crop of errors, err, well, 2 actually. Both of which were syntax errors, one about a missing comma, and one about a misplaced '&' symbol, if I recall correectly. if someone could point out what the heck I was doing wrong, I'd appreciate it!

Share this post


Link to post
Share on other sites
Advertisement
You didn't do any research on existing fraction implementations, did you?

a) Your code breaks when unsigned long isn't 32 bit.
b) Im quite sure that a good least common multiple algorithm is way faster than your primetable.
c) ++ and -- have weird semantics and break comparison operators.
d) Clamping the numerator and denominator to 16-bit values is extremely unintuitive.
e) I'm fairly certain your != is broken.
f) Your binary +,-,*,/ return references and modify one of the operands which again is against intuition
g) Using throw() declarations is considered bad style by most C++ programmers

Share this post


Link to post
Share on other sites
Well, it looks like I got quite a bit wrong then... Anyway, I wasn't doing this for lack of fractions, just to make my own.

Good stuff there, I'll have a look at my code again.. Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!